tell.lua: prevent executing the command in a non-groupchat environment.

Fri, 14 May 2010 14:18:23 +0100

author
Thilo Cestonaro <thilo@cestona.ro>
date
Fri, 14 May 2010 14:18:23 +0100
changeset 10
77753bce939a
parent 9
8c3bec93087b
child 11
7bb53dcf93d4

tell.lua: prevent executing the command in a non-groupchat environment.

plugins/tell.lua file | annotate | diff | comparison | revisions
--- a/plugins/tell.lua	Thu Mar 18 14:16:05 2010 +0100
+++ b/plugins/tell.lua	Fri May 14 14:18:23 2010 +0100
@@ -3,30 +3,34 @@
 
 function riddim.plugins.tell(bot)
 	bot:hook("commands/tell", function (command)
-			local s, e = command.param:find(" ");
-			local nick = command.param:sub(0, s - 1);
-			local msg = command.param:sub(s + 1);
-			local found = false;
-
-			for tmp,_ in pairs(command.room.occupants) do
-				if tmp == nick then
-					found = true;
-					break;
+			if command.room then
+				local s, e = command.param:find(" ");
+				local nick = command.param:sub(0, s - 1);
+				local msg = command.param:sub(s + 1);
+				local found = false;
+	
+				for tmp,_ in pairs(command.room.occupants) do
+					if tmp == nick then
+						found = true;
+						break;
+					end
 				end
-			end
 
-			if not found then
-				if(tellings[nick] == nil) then
-					tellings[nick] = {};
+				if not found then
+					if(tellings[nick] == nil) then
+						tellings[nick] = {};
+					end
+					tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg};
+					return "Ok! Will tell " .. nick .. " what you have said!";
+				else
+					if nick == command.sender.nick then
+						return "Are you going crazy!? You are " .. nick .. "!";
+					else
+						return "Aehm?! ... " .. nick .. " is currently online!";
+					end
 				end
-				tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg};
-				return "Ok! Will tell " .. nick .. " what you have said!";
 			else
-				if nick == command.sender.nick then
-					return "Are you going crazy!? You are " .. nick .. "!";
-				else
-					return "Aehm?! ... " .. nick .. " is currently online!";
-				end
+				return "Sorry, but this command only makes sense if you execute it in a groupchat.";
 			end
 		end);
 

mercurial