plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells

Thu, 24 Jun 2010 17:51:36 +0100

author
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
date
Thu, 24 Jun 2010 17:51:36 +0100
changeset 30
7bfe0d739b1c
parent 29
11154ba6cbf6
child 31
0cafbe17c0aa

plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells

plugins/tell.lua file | annotate | diff | comparison | revisions
--- 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
-

mercurial