From 5c2591152e5e2b357b715ddb53c5ce881032835a Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sun, 23 Aug 2015 02:10:37 -0400 Subject: [PATCH] Users can now display a list of reactions.lua options using /reactions, a help message dynamically generated at plugin load and streamlined into the reactions system. --- plugins/reaction.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/reaction.lua b/plugins/reaction.lua index 938fb43..2e8907f 100644 --- a/plugins/reaction.lua +++ b/plugins/reaction.lua @@ -1,6 +1,4 @@ -local PLUGIN = {} - -PLUGIN.triggers = { +local triggers = { ['¯\\_(ツ)_/¯'] = '/shrug$', ['( ͡° ͜ʖ ͡°)'] = '/lenny$', ['(╯°□°)╯︵ ┻━┻'] = '/flip$', @@ -8,11 +6,11 @@ PLUGIN.triggers = { ['ಠ_ಠ'] = '/look$' } -function PLUGIN.action(msg) +local action = function(msg) local message = string.lower(msg.text) - for k,v in pairs(PLUGIN.triggers) do + for k,v in pairs(triggers) do if string.match(message, v) then message = k end @@ -26,4 +24,17 @@ function PLUGIN.action(msg) end -return PLUGIN +-- The following block of code will generate a list of reactions add the trigger "/reactions" to display it. +-- Thanks to @Imandaneshi for the idea and early implementation. +local help = '' +for k,v in pairs(triggers) do + if v ~= '^/reactions?' then + help = help .. v:gsub('%$', ': ') .. k .. '\n' + end +end +triggers[help] = '^/reactions' + +return { + triggers = triggers, + action = action +}