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 local s, e = command.param:find(" "); |
6 if command.room then |
7 local nick = command.param:sub(0, s - 1); |
7 local s, e = command.param:find(" "); |
8 local msg = command.param:sub(s + 1); |
8 local nick = command.param:sub(0, s - 1); |
9 local found = false; |
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 |
10 |
18 |
11 for tmp,_ in pairs(command.room.occupants) do |
19 if not found then |
12 if tmp == nick then |
20 if(tellings[nick] == nil) then |
13 found = true; |
21 tellings[nick] = {}; |
14 break; |
22 end |
|
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
|
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 .. "!"; |
|
28 else |
|
29 return "Aehm?! ... " .. nick .. " is currently online!"; |
|
30 end |
15 end |
31 end |
16 end |
|
17 |
|
18 if not found then |
|
19 if(tellings[nick] == nil) then |
|
20 tellings[nick] = {}; |
|
21 end |
|
22 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
|
23 return "Ok! Will tell " .. nick .. " what you have said!"; |
|
24 else |
32 else |
25 if nick == command.sender.nick then |
33 return "Sorry, but this command only makes sense if you execute it in a groupchat."; |
26 return "Are you going crazy!? You are " .. nick .. "!"; |
|
27 else |
|
28 return "Aehm?! ... " .. nick .. " is currently online!"; |
|
29 end |
|
30 end |
34 end |
31 end); |
35 end); |
32 |
36 |
33 bot:hook("groupchat/joined", function (room) |
37 bot:hook("groupchat/joined", function (room) |
34 room:hook("occupant-joined", function (occupant) |
38 room:hook("occupant-joined", function (occupant) |