plugins/version.lua

Sun, 06 Jul 2014 15:36:18 +0200

author
Kim Alvefur <zash@zash.se>
date
Sun, 06 Jul 2014 15:36:18 +0200
changeset 113
5f2418fb8b19
parent 105
4234c8789cc6
child 125
2c570064f582
permissions
-rw-r--r--

plugins.version: example.com doesn't support *version* requests, not feature requests

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 = bot.config.bot_name or "Riddim";
		version = bot.config.bot_version or "alpha";
		platform = bot.config.bot_platform or _VERSION;
	};

	bot:add_plugin("resolvejid");
	bot:hook("commands/version", function (command)
		local who, param = bot.stream.jid, command.param;
		if param then
			who = bot:resolvejid(param, command.room);
		end
		
		bot.stream:query_version(who, function (reply)
			if not reply.error then
				local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am");
				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 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