plugins/version.lua

Thu, 14 Oct 2010 13:21:55 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 14 Oct 2010 13:21:55 +0100
changeset 33
37caf7bd2021
parent 16
ae69cea97598
child 37
85b3f2a96edb
permissions
-rw-r--r--

plugins.version, plugins.command: Remove obsolete require 'util.xstanza'

local st = require "util.stanza";

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 == "feature-not-implemented" then
					r = param.." doesn't support feature 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