1 local st = require "util.stanza"; |
1 local st = require "util.stanza"; |
2 local tellings = {}; |
2 local tellings = {}; |
3 |
3 |
4 function riddim.plugins.tell(bot) |
4 function riddim.plugins.tell(bot) |
5 bot:hook("commands/tell", function (command) |
5 bot:hook("commands/tell", function (command) |
6 if command.room then |
6 if command.room then |
7 local s, e = command.param:find(" "); |
7 local s, e = command.param:find(" "); |
8 local nick = command.param:sub(0, s - 1); |
8 local nick = command.param:sub(0, s - 1); |
9 local msg = command.param:sub(s + 1); |
9 local msg = command.param:sub(s + 1); |
10 local found = false; |
10 local found = false; |
11 |
11 |
12 for tmp,_ in pairs(command.room.occupants) do |
12 for tmp,_ in pairs(command.room.occupants) do |
13 if tmp == nick then |
13 if tmp == nick then |
14 found = true; |
14 found = true; |
15 break; |
15 break; |
16 end |
|
17 end |
16 end |
|
17 end |
18 |
18 |
19 if not found then |
19 if not found then |
20 if(tellings[nick] == nil) then |
20 if(tellings[nick] == nil) then |
21 tellings[nick] = {}; |
21 tellings[nick] = {}; |
22 end |
22 end |
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
24 return "Ok! Will tell " .. nick .. " what you have said!"; |
24 return "Ok! Will tell " .. nick .. " what you have said!"; |
|
25 else |
|
26 if nick == command.sender.nick then |
|
27 return "Are you going crazy!? You are " .. nick .. "!"; |
25 else |
28 else |
26 if nick == command.sender.nick then |
29 return "Aehm?! ... " .. nick .. " is currently online!"; |
27 return "Are you going crazy!? You are " .. nick .. "!"; |
|
28 else |
|
29 return "Aehm?! ... " .. nick .. " is currently online!"; |
|
30 end |
|
31 end |
30 end |
32 else |
31 end |
33 return "Sorry, but this command only makes sense if you execute it in a groupchat."; |
32 else |
|
33 return "Sorry, but this command only makes sense if you execute it in a groupchat."; |
|
34 end |
|
35 end); |
|
36 |
|
37 bot:hook("groupchat/joined", function (room) |
|
38 room:hook("occupant-joined", function (occupant) |
|
39 if(tellings[occupant.nick] ~= nil) then |
|
40 for _,msg in ipairs(tellings[occupant.nick]) do |
|
41 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
|
42 end |
34 end |
43 end |
35 end); |
44 end); |
36 |
45 end); |
37 bot:hook("groupchat/joined", function (room) |
|
38 room:hook("occupant-joined", function (occupant) |
|
39 if(tellings[occupant.nick] ~= nil) then |
|
40 for _,msg in ipairs(tellings[occupant.nick]) do |
|
41 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
|
42 end |
|
43 end |
|
44 end); |
|
45 end); |
|
46 end |
46 end |
47 |
47 |