plugins/version.lua

Mon, 21 Dec 2009 19:27:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 21 Dec 2009 19:27:08 +0000
changeset 0
7d84f4403d67
child 7
59129c1e4e07
permissions
-rw-r--r--

Initial commit, hello world!

local st = require "util.stanza";
require "util.xstanza";

local xmlns_version = "jabber:iq:version";

function riddim.plugins.version(bot)
	bot.stream:add_plugin("version");
	bot.stream.version:set{
		name = "Riddim";
		version = "alpha";
	};

	bot:hook("commands/version", function (command)
		local who, param = bot.stream.jid, command.param or (command.room and command.room.nick);
		if param then
			if command.room and command.room.occupants[param] then
				who = command.room.occupants[param].jid;
			elseif command.room and command.room.occupants[param:gsub("%s$", "")] then
				who = command.room.occupants[param:gsub("%s$", "")].jid;
			else
				who = param;
			end
		end
		
		bot.stream:query_version(who,
			function (reply)
				if not reply.error then
					local saywho = (who == command.sender.jid and "You are") or (param.." is");
					command:reply(saywho.." running "..(reply.name or "something")
						.." version "..(reply.version or "unknown")
						.." on "..(reply.platform or "an unknown platform"));
				else
					local type, condition, text = reply.type, reply.condition, reply.text;
					local r = "There was an error requesting "..param.."'s version";
					if condition == "service-unavailable" then
						r = param.." doesn't reply to version requests";
					elseif condition == "remote-server-not-found" then
						r = param.." can't be reached via XMPP"
					elseif condition and not text then
						r = r..": "..condition;
					end
					if text then
						r = r .. " ("..text..")";
					end
					command:reply(r);
				end
			end);
		return true;
	end);	
end

mercurial