This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/reactions.lua

40 lines
1.7 KiB
Lua
Raw Normal View History

local reactions = {}
2016-06-07 06:31:34 +02:00
local utilities = require('otouto.utilities')
reactions.command = 'reactions'
reactions.doc = 'Returns a list of "reaction" emoticon commands.'
function reactions:init(config)
2016-08-15 07:00:24 +02:00
-- Generate a command list message triggered by "/reactions".
reactions.help = 'Reactions:\n'
2016-08-14 04:46:18 +02:00
reactions.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('reactions').table
local username = self.info.username:lower()
2016-08-15 07:00:24 +02:00
for trigger, reaction in pairs(config.reactions) do
reactions.help = reactions.help .. '' .. config.cmd_pat .. trigger .. ': ' .. reaction .. '\n'
2016-08-14 04:46:18 +02: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
end
function reactions:action(msg, config)
2016-08-14 04:46:18 +02:00
if string.match(msg.text_lower, config.cmd_pat..'reactions') then
utilities.send_message(msg.chat.id, reactions.help, true, nil, 'html')
2016-08-14 04:46:18 +02:00
return
end
for trigger,reaction in pairs(config.reactions) do
if string.match(msg.text_lower, config.cmd_pat..trigger) then
utilities.send_message(msg.chat.id, reaction, true, nil, 'html')
2016-08-14 04:46:18 +02:00
return
end
end
end
return reactions