Thu, 09 Jul 2015 22:48:55 +0200
plugins.version: Put friendly errors in a table
local st = require "util.stanza"; local xmlns_version = "jabber:iq:version"; local friendly_errors = { ["service-unavailable"] = " doesn't reply to version requests"; ["feature-not-implemented"] = " doesn't support version requests"; ["remote-server-not-found"] = " can't be reached via XMPP"; } 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"; local friendly_error = friendly_errors[condition]; if friendly_error then r = r .. friendly_error; elseif condition and not text then r = r..": "..(condition):gsub("%-", " "); end if text then r = r .. " ("..text..")"; end command:reply(r); end end); return true; end); end