Thu, 14 Oct 2010 13:21:55 +0100
plugins.version, plugins.command: Remove obsolete require 'util.xstanza'
0 | 1 | function riddim.plugins.commands(bot) |
2 | local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$"; | |
3 | ||
4 | local function process_command(event) | |
14
3df63aaba9e3
Decouple plugins from base implementation (in particular no plugins are now loaded by default)
Chris <jugg@hotmail.com>
parents:
0
diff
changeset
|
5 | local body = event.body; |
0 | 6 | if not body then return; end |
14
3df63aaba9e3
Decouple plugins from base implementation (in particular no plugins are now loaded by default)
Chris <jugg@hotmail.com>
parents:
0
diff
changeset
|
7 | if event.delay then return; end -- Don't process old messages from groupchat |
0 | 8 | |
9 | local command, hasparam, param = body:match(command_pattern); | |
10 | ||
11 | if not command then | |
12 | command, hasparam, param = body:match("%[([%a%-%_%d]+)(%s?)(.*)%]"); | |
13 | end | |
14 | ||
15 | if hasparam ~= " " then param = nil; end | |
16 | ||
17 | if command then | |
18 | local command_event = { | |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
19 | command = command, |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
20 | param = param, |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
21 | sender = event.sender, |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
22 | stanza = event.stanza, |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
23 | reply = event.reply, |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
24 | room = event.room, -- groupchat support |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
14
diff
changeset
|
25 | }; |
0 | 26 | local ret = bot:event("commands/"..command, command_event); |
27 | if type(ret) == "string" then | |
28 | event:reply(ret); | |
29 | end | |
30 | return ret; | |
31 | end | |
32 | end | |
33 | ||
14
3df63aaba9e3
Decouple plugins from base implementation (in particular no plugins are now loaded by default)
Chris <jugg@hotmail.com>
parents:
0
diff
changeset
|
34 | -- Hook messages sent to bot, fire a command event on the bot |
0 | 35 | bot:hook("message", process_command); |
36 | ||
14
3df63aaba9e3
Decouple plugins from base implementation (in particular no plugins are now loaded by default)
Chris <jugg@hotmail.com>
parents:
0
diff
changeset
|
37 | -- Support groupchat plugin: Hook messages from rooms that the bot joins |
0 | 38 | bot:hook("groupchat/joining", function (room) |
39 | room:hook("message", process_command); | |
40 | end); | |
41 | end |