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 not command.room then |
7 local s, e = command.param:find(" "); |
|
8 local nick = command.param:sub(0, s - 1); |
|
9 local msg = command.param:sub(s + 1); |
|
10 local found = false; |
|
11 |
|
12 for tmp,_ in pairs(command.room.occupants) do |
|
13 if tmp == nick then |
|
14 found = true; |
|
15 break; |
|
16 end |
|
17 end |
|
18 |
|
19 if not found then |
|
20 if(tellings[nick] == nil) then |
|
21 tellings[nick] = {}; |
|
22 end |
|
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
|
24 return "Ok!"; |
|
25 else |
|
26 if nick == command.sender.nick then |
|
27 return "Tell yourself."; |
|
28 else |
|
29 return "" .. nick .. " is currently online!"; |
|
30 end |
|
31 end |
|
32 else |
|
33 return "This command is only available in groupchats."; |
7 return "This command is only available in groupchats."; |
34 end |
8 end |
|
9 if not command.param then |
|
10 return "If you want me to tell someone something then do so"; |
|
11 end |
|
12 |
|
13 local s, e = command.param:find(" "); |
|
14 |
|
15 if not s then |
|
16 return "if you have nothing to say to "..command.param..", then leave me alone, please"; |
|
17 end |
|
18 |
|
19 local nick = command.param:sub(0, s - 1); |
|
20 local msg = command.param:sub(s + 1); |
|
21 |
|
22 if nick == command.sender.nick then |
|
23 return "Tell yourself."; |
|
24 end |
|
25 |
|
26 for tmp,_ in pairs(command.room.occupants) do |
|
27 if tmp == nick then |
|
28 return "" .. nick .. " is currently online!"; |
|
29 end |
|
30 end |
|
31 |
|
32 if tellings[nick] == nil then |
|
33 tellings[nick] = {}; |
|
34 end |
|
35 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
|
36 return "Ok!"; |
35 end); |
37 end); |
36 |
38 |
37 bot:hook("groupchat/joined", function (room) |
39 bot:hook("groupchat/joined", function (room) |
38 room:hook("occupant-joined", function (occupant) |
40 room:hook("occupant-joined", function (occupant) |
39 if(tellings[occupant.nick] ~= nil) then |
41 if(tellings[occupant.nick] ~= nil) then |