Sun, 30 May 2010 02:55:31 +0100
riddim: Hook Verse's new 'ready' event instead of 'binding-success'
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
1 | local st = require "util.stanza"; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
2 | local tellings = {}; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
3 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
4 | function riddim.plugins.tell(bot) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
5 | bot:hook("commands/tell", function (command) |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
6 | if command.room then |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
7 | local s, e = command.param:find(" "); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
8 | local nick = command.param:sub(0, s - 1); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
9 | local msg = command.param:sub(s + 1); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
10 | local found = false; |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
11 | |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
12 | for tmp,_ in pairs(command.room.occupants) do |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
13 | if tmp == nick then |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
14 | found = true; |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
15 | break; |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
16 | end |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
17 | end |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 | |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
19 | if not found then |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
20 | if(tellings[nick] == nil) then |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
21 | tellings[nick] = {}; |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
22 | end |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
23 | tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
20 | 24 | return "Ok!"; |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
25 | else |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
26 | if nick == command.sender.nick then |
21
be3b031b986d
plugins.tell: Remove excess quote (thanks Florob)
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
27 | return "Tell yourself."; |
10
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
28 | else |
20 | 29 | return "" .. nick .. " is currently online!"; |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
30 | end |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
31 | end |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
32 | else |
20 | 33 | return "This command is only available in groupchats."; |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
34 | end |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
35 | end); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
36 | |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
37 | bot:hook("groupchat/joined", function (room) |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
38 | room:hook("occupant-joined", function (occupant) |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
39 | if(tellings[occupant.nick] ~= nil) then |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
40 | for _,msg in ipairs(tellings[occupant.nick]) do |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
41 | room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
42 | end |
20 | 43 | tellings[occupant.nick] = nil; |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
44 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
45 | end); |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
46 | end); |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
47 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
48 |