plugins/tell.lua

Thu, 20 May 2010 17:36:47 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 20 May 2010 17:36:47 +0100
changeset 21
be3b031b986d
parent 20
4f4d98345952
child 29
11154ba6cbf6
permissions
-rw-r--r--

plugins.tell: Remove excess quote (thanks Florob)

local st = require "util.stanza";
local tellings = {};

function riddim.plugins.tell(bot)
	bot:hook("commands/tell", function (command)
		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

			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!";
			else
				if nick == command.sender.nick then
					return "Tell yourself.";
				else
					return "" .. nick .. " is currently online!";
				end
			end
		else
			return "This command is only available in groupchats.";
		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
				tellings[occupant.nick] = nil;
			end
		end);
	end);
end

mercurial