Thu, 20 May 2010 13:45:53 +0100
plugins.tell: Change responses (thanks Flo)
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) |
10
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
6 | if command.room then |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
7 | local s, e = command.param:find(" "); |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
8 | local nick = command.param:sub(0, s - 1); |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
9 | local msg = command.param:sub(s + 1); |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
10 | local found = false; |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
11 | |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
12 | for tmp,_ in pairs(command.room.occupants) do |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
13 | if tmp == nick then |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
14 | found = true; |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
15 | break; |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
16 | end |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
17 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 | |
10
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
19 | if not found then |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
20 | if(tellings[nick] == nil) then |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
21 | tellings[nick] = {}; |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
22 | end |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
23 | tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
12
d7ce8ba2c462
plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
10
diff
changeset
|
24 | return "Ok!"; |
10
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
25 | else |
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
26 | if nick == command.sender.nick then |
12
d7ce8ba2c462
plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
10
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 |
12
d7ce8ba2c462
plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
10
diff
changeset
|
29 | return "" .. nick .. " is currently online!"; |
10
77753bce939a
tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents:
8
diff
changeset
|
30 | end |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
31 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
32 | else |
12
d7ce8ba2c462
plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
10
diff
changeset
|
33 | return "This command is only available in groupchats."; |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
34 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
35 | end); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
36 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
37 | bot:hook("groupchat/joined", function (room) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
38 | room:hook("occupant-joined", function (occupant) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
39 | if(tellings[occupant.nick] ~= nil) then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
40 | for _,msg in ipairs(tellings[occupant.nick]) do |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
41 | room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
42 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
43 | end |
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); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
46 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
47 |