2016-04-10 21:04:47 -07:00
|
|
|
local reactions = {}
|
|
|
|
|
2016-06-07 00:31:34 -04:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-04-10 21:04:47 -07:00
|
|
|
|
|
|
|
reactions.command = 'reactions'
|
2016-07-25 05:03:35 -04:00
|
|
|
reactions.doc = 'Returns a list of "reaction" emoticon commands.'
|
2016-04-10 21:04:47 -07:00
|
|
|
|
2016-05-26 20:28:44 -07:00
|
|
|
function reactions:init(config)
|
2016-08-15 01:00:24 -04:00
|
|
|
-- Generate a command list message triggered by "/reactions".
|
|
|
|
reactions.help = 'Reactions:\n'
|
2016-08-13 22:46:18 -04:00
|
|
|
reactions.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('reactions').table
|
|
|
|
local username = self.info.username:lower()
|
2016-08-15 01:00:24 -04:00
|
|
|
for trigger, reaction in pairs(config.reactions) do
|
|
|
|
reactions.help = reactions.help .. '• ' .. config.cmd_pat .. trigger .. ': ' .. reaction .. '\n'
|
2016-08-13 22:46:18 -04:00
|
|
|
table.insert(reactions.triggers, '^'..config.cmd_pat..trigger)
|
|
|
|
table.insert(reactions.triggers, '^'..config.cmd_pat..trigger..'@'..username)
|
|
|
|
table.insert(reactions.triggers, config.cmd_pat..trigger..'$')
|
|
|
|
table.insert(reactions.triggers, config.cmd_pat..trigger..'@'..username..'$')
|
|
|
|
table.insert(reactions.triggers, '\n'..config.cmd_pat..trigger)
|
|
|
|
table.insert(reactions.triggers, '\n'..config.cmd_pat..trigger..'@'..username)
|
|
|
|
table.insert(reactions.triggers, config.cmd_pat..trigger..'\n')
|
|
|
|
table.insert(reactions.triggers, config.cmd_pat..trigger..'@'..username..'\n')
|
|
|
|
end
|
2015-11-24 21:22:04 -05:00
|
|
|
end
|
|
|
|
|
2016-05-26 20:28:44 -07:00
|
|
|
function reactions:action(msg, config)
|
2016-08-13 22:46:18 -04:00
|
|
|
if string.match(msg.text_lower, config.cmd_pat..'reactions') then
|
2016-08-23 00:16:32 -04:00
|
|
|
utilities.send_message(msg.chat.id, reactions.help, true, nil, 'html')
|
2016-08-13 22:46:18 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for trigger,reaction in pairs(config.reactions) do
|
|
|
|
if string.match(msg.text_lower, config.cmd_pat..trigger) then
|
2016-08-23 00:16:32 -04:00
|
|
|
utilities.send_message(msg.chat.id, reaction, true, nil, 'html')
|
2016-08-13 22:46:18 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2015-11-24 21:22:04 -05:00
|
|
|
end
|
|
|
|
|
2016-04-10 21:04:47 -07:00
|
|
|
return reactions
|