Thu, 18 Mar 2010 12:51:48 +0100
add basic command tell support
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) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
6 | local s, e = command.param:find(" "); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
7 | local nick = command.param:sub(0, s - 1); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
8 | local msg = command.param:sub(s + 1); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
9 | local found = false; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
10 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
11 | for tmp,_ in pairs(command.room.occupants) do |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
12 | if tmp == nick then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
13 | found = true; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
14 | break; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
15 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
16 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
17 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 | if not found then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
19 | if(tellings[nick] == nil) then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
20 | tellings[nick] = {}; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
21 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
22 | tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
23 | return "Ok! Will tell " .. nick .. " what you have said!"; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
24 | else |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
25 | if nick == command.sender.nick then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
26 | return "Are you going crazy!? You are " .. nick .. "!"; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
27 | else |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
28 | return "Aehm?! ... " .. nick .. " is currently online!"; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
29 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
30 | end |
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 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
33 | bot:hook("groupchat/joined", function (room) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
34 | room:hook("occupant-joined", function (occupant) |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
35 | if(tellings[occupant.nick] ~= nil) then |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
36 | for _,msg in ipairs(tellings[occupant.nick]) do |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
37 | 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
|
38 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
39 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
40 | end); |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
41 | end); |
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 |