add basic command tell support

Thu, 18 Mar 2010 12:51:48 +0100

author
Thilo Cestonaro <thilo@cestona.ro>
date
Thu, 18 Mar 2010 12:51:48 +0100
changeset 8
9663866ca475
parent 7
59129c1e4e07
child 9
8c3bec93087b

add basic command tell support

init.lua file | annotate | diff | comparison | revisions
plugins/tell.lua file | annotate | diff | comparison | revisions
squishy file | annotate | diff | comparison | revisions
--- a/init.lua	Thu Apr 29 22:11:35 2010 +0100
+++ b/init.lua	Thu Mar 18 12:51:48 2010 +0100
@@ -19,6 +19,7 @@
 	self:add_plugin("groupchat");
 	self:add_plugin("commands");
 	self:add_plugin("ping");
+	self:add_plugin("tell");
 	self:event("started");
 	self.stream:hook("stanza", function (stanza)
 			local body = stanza:get_child("body");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/tell.lua	Thu Mar 18 12:51:48 2010 +0100
@@ -0,0 +1,43 @@
+local st = require "util.stanza";
+local tellings = {};
+
+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;
+				end
+			end
+
+			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
+		end);
+
+	bot:hook("groupchat/joined", function (room)	
+		room:hook("occupant-joined", function (occupant)
+				if(tellings[occupant.nick] ~= nil) then
+					for _,msg in ipairs(tellings[occupant.nick]) do
+						room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\".");
+					end
+				end
+			end);
+		end);
+end
+
--- a/squishy	Thu Apr 29 22:11:35 2010 +0100
+++ b/squishy	Thu Mar 18 12:51:48 2010 +0100
@@ -2,6 +2,7 @@
 Module "riddim.plugins.commands"  "plugins/commands.lua"
 Module "riddim.plugins.version"   "plugins/version.lua"
 Module "riddim.plugins.ping"      "plugins/ping.lua"
+Module "riddim.plugins.tell"      "plugins/tell.lua"
 
 Main "init.lua"
 

mercurial