34 end |
34 end |
35 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
35 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; |
36 return "Ok!"; |
36 return "Ok!"; |
37 end); |
37 end); |
38 |
38 |
|
39 bot:hook("commands/untell", function (command) |
|
40 if not command.room then |
|
41 return "This command is only available in groupchats."; |
|
42 end |
|
43 if not command.param then |
|
44 return "If you changed your mind tell me for who"; |
|
45 end |
|
46 |
|
47 local s, e = command.param:find(" "); |
|
48 local nick; |
|
49 local id; |
|
50 |
|
51 -- parameter parsing |
|
52 if not s then |
|
53 nick = command.param; |
|
54 id = nil; |
|
55 else |
|
56 nick = command.param:sub(0, s - 1); |
|
57 id = command.param:sub(s + 1); |
|
58 end |
|
59 |
|
60 -- no message for that user |
|
61 if not tellings[nick] then |
|
62 return "I have no messages for "..nick; |
|
63 end |
|
64 |
|
65 -- no message id and message for that user |
|
66 if id == nil then |
|
67 local response = "I am supposed to relay the following message to "..nick.." :"; |
|
68 for index,msg in ipairs(tellings[nick]) do |
|
69 response = response .. "\n#"..index.." : "..msg.msg; |
|
70 end |
|
71 return response; |
|
72 end |
|
73 |
|
74 -- check the message id is valid |
|
75 local number = #tellings[nick]; |
|
76 id = tonumber(id) |
|
77 if id == nil or id < 1 or id > number then |
|
78 return "I need a valid message #id .. sigh !!\n"..nick.." has "..number.." message(s)"; |
|
79 end |
|
80 |
|
81 if tellings[nick][id].from ~= command.sender.nick then |
|
82 return "you never said that, "..tellings[nick][id].from.." did !"; |
|
83 end |
|
84 |
|
85 -- remove the message |
|
86 if number > 1 then |
|
87 tellings[nick][id] = tellings[nick][number]; |
|
88 tellings[nick][number] = nil; |
|
89 return "what was I supposed to tell "..nick.." again ?"; |
|
90 else |
|
91 tellings[nick] = nil; |
|
92 return "who is "..nick.." anyway ?"; |
|
93 end |
|
94 end); |
|
95 |
39 bot:hook("groupchat/joined", function (room) |
96 bot:hook("groupchat/joined", function (room) |
40 room:hook("occupant-joined", function (occupant) |
97 room:hook("occupant-joined", function (occupant) |
41 if(tellings[occupant.nick] ~= nil) then |
98 if(tellings[occupant.nick] ~= nil) then |
42 for _,msg in ipairs(tellings[occupant.nick]) do |
99 for _,msg in ipairs(tellings[occupant.nick]) do |
43 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |
100 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\"."); |