|
1 local st = require "util.stanza"; |
|
2 local tellings = {}; |
|
3 |
|
4 function riddim.plugins.tell(bot) |
|
5 bot:hook("commands/tell", function (command) |
|
6 local s, e = command.param:find(" "); |
|
7 local nick = command.param:sub(0, s - 1); |
|
8 local msg = command.param:sub(s + 1); |
|
9 local found = false; |
|
10 |
|
11 for tmp,_ in pairs(command.room.occupants) do |
|
12 if tmp == nick then |
|
13 found = true; |
|
14 break; |
|
15 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 |
|
25 if nick == command.sender.nick then |
|
26 return "Are you going crazy!? You are " .. nick .. "!"; |
|
27 else |
|
28 return "Aehm?! ... " .. nick .. " is currently online!"; |
|
29 end |
|
30 end |
|
31 end); |
|
32 |
|
33 bot:hook("groupchat/joined", function (room) |
|
34 room:hook("occupant-joined", function (occupant) |
|
35 if(tellings[occupant.nick] ~= nil) then |
|
36 for _,msg in ipairs(tellings[occupant.nick]) do |
|
37 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
|
38 end |
|
39 end |
|
40 end); |
|
41 end); |
|
42 end |
|
43 |