# HG changeset patch # User Thomas Mangin # Date 1277398296 -3600 # Node ID 7bfe0d739b1c8beaec0ff05caa0e7cfb6e70b07c # Parent 11154ba6cbf682d9933f3e3f4952cb7ec6f49389 plugins.tell: Add !untell and !untell to remove tells diff -r 11154ba6cbf6 -r 7bfe0d739b1c plugins/tell.lua --- a/plugins/tell.lua Thu Jun 24 17:49:08 2010 +0100 +++ b/plugins/tell.lua Thu Jun 24 17:51:36 2010 +0100 @@ -36,6 +36,63 @@ return "Ok!"; end); + bot:hook("commands/untell", function (command) + if not command.room then + return "This command is only available in groupchats."; + end + if not command.param then + return "If you changed your mind tell me for who"; + end + + local s, e = command.param:find(" "); + local nick; + local id; + + -- parameter parsing + if not s then + nick = command.param; + id = nil; + else + nick = command.param:sub(0, s - 1); + id = command.param:sub(s + 1); + end + + -- no message for that user + if not tellings[nick] then + return "I have no messages for "..nick; + end + + -- no message id and message for that user + if id == nil then + local response = "I am supposed to relay the following message to "..nick.." :"; + for index,msg in ipairs(tellings[nick]) do + response = response .. "\n#"..index.." : "..msg.msg; + end + return response; + end + + -- check the message id is valid + local number = #tellings[nick]; + id = tonumber(id) + if id == nil or id < 1 or id > number then + return "I need a valid message #id .. sigh !!\n"..nick.." has "..number.." message(s)"; + end + + if tellings[nick][id].from ~= command.sender.nick then + return "you never said that, "..tellings[nick][id].from.." did !"; + end + + -- remove the message + if number > 1 then + tellings[nick][id] = tellings[nick][number]; + tellings[nick][number] = nil; + return "what was I supposed to tell "..nick.." again ?"; + else + tellings[nick] = nil; + return "who is "..nick.." anyway ?"; + end + end); + bot:hook("groupchat/joined", function (room) room:hook("occupant-joined", function (occupant) if(tellings[occupant.nick] ~= nil) then @@ -47,4 +104,3 @@ end); end); end -