plugins/commands.lua

changeset 35
0f17e574b6bb
parent 33
37caf7bd2021
child 58
3e5b57d44fa0
equal deleted inserted replaced
34:23e17e64ca25 35:0f17e574b6bb
1 function riddim.plugins.commands(bot) 1 function riddim.plugins.commands(bot)
2 local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$"; 2 local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$";
3
4 local direct_address_pattern = false;
5 if bot.config.nick then
6 direct_address_pattern = "^"..bot.config.nick.."[,: ]+([%a%-%_%d]+)(%s?)(.*)";
7 end
3 8
4 local function process_command(event) 9 local function process_command(event)
5 local body = event.body; 10 local body = event.body;
6 if not body then return; end 11 if not body then return; end
7 if event.delay then return; end -- Don't process old messages from groupchat 12 if event.delay then return; end -- Don't process old messages from groupchat
8 13
9 local command, hasparam, param = body:match(command_pattern); 14 local command, hasparam, param = body:match(command_pattern);
15
16 if not command and direct_address_pattern then
17 command, hasparam, param = body:match(direct_address_pattern);
18 end
10 19
11 if not command then 20 if not command then
12 command, hasparam, param = body:match("%[([%a%-%_%d]+)(%s?)(.*)%]"); 21 command, hasparam, param = body:match("%[([%a%-%_%d]+)(%s?)(.*)%]");
13 end 22 end
14 23

mercurial