2016-04-11 06:04:47 +02:00
|
|
|
local nick = {}
|
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-04-11 06:04:47 +02:00
|
|
|
|
|
|
|
nick.command = 'nick <nickname>'
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function nick:init(config)
|
|
|
|
nick.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('nick', true).table
|
|
|
|
nick.doc = [[```
|
|
|
|
]]..config.cmd_pat..[[nick <nickname>
|
|
|
|
Set your nickname. Use "]]..config.cmd_pat..[[nick --" to delete it.
|
|
|
|
```]]
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
function nick:action(msg, config)
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-03-08 10:17:55 +01:00
|
|
|
local target = msg.from
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
if msg.from.id == config.admin and msg.reply_to_message then
|
2016-03-08 10:17:55 +01:00
|
|
|
target = msg.reply_to_message.from
|
|
|
|
target.id_str = tostring(target.id)
|
|
|
|
target.name = target.first_name
|
|
|
|
if target.last_name then
|
|
|
|
target.name = target.first_name .. ' ' .. target.last_name
|
|
|
|
end
|
2015-08-29 08:15:01 +02:00
|
|
|
end
|
|
|
|
|
2016-03-08 10:17:55 +01:00
|
|
|
local output
|
2016-04-08 23:12:02 +02:00
|
|
|
local input = utilities.input(msg.text)
|
2016-03-08 10:17:55 +01:00
|
|
|
if not input then
|
2016-04-11 06:04:47 +02:00
|
|
|
if self.database.users[target.id_str].nickname then
|
|
|
|
output = target.name .. '\'s nickname is "' .. self.database.users[target.id_str].nickname .. '".'
|
2016-03-08 10:17:55 +01:00
|
|
|
else
|
|
|
|
output = target.name .. ' currently has no nickname.'
|
|
|
|
end
|
2016-05-27 17:49:58 +02:00
|
|
|
elseif utilities.utf8_len(input) > 32 then
|
2016-03-08 10:17:55 +01:00
|
|
|
output = 'The character limit for nicknames is 32.'
|
2016-05-25 15:01:54 +02:00
|
|
|
elseif input == '--' or input == utilities.char.em_dash then
|
2016-04-11 06:04:47 +02:00
|
|
|
self.database.users[target.id_str].nickname = nil
|
2016-03-08 10:17:55 +01:00
|
|
|
output = target.name .. '\'s nickname has been deleted.'
|
2015-11-25 03:22:04 +01:00
|
|
|
else
|
2016-05-10 21:49:05 +02:00
|
|
|
input = input:gsub('\n', ' ')
|
2016-04-11 06:04:47 +02:00
|
|
|
self.database.users[target.id_str].nickname = input
|
2016-03-08 10:17:55 +01:00
|
|
|
output = target.name .. '\'s nickname has been set to "' .. input .. '".'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_reply(self, msg, output)
|
2015-08-18 11:55:25 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return nick
|