plugins/version.lua

changeset 125
2c570064f582
parent 113
5f2418fb8b19
child 126
99781a97f582
equal deleted inserted replaced
124:4530954f545a 125:2c570064f582
1 local st = require "util.stanza"; 1 local st = require "util.stanza";
2 2
3 local xmlns_version = "jabber:iq:version"; 3 local xmlns_version = "jabber:iq:version";
4
5 local friendly_errors = {
6 ["service-unavailable"] = " doesn't reply to version requests";
7 ["feature-not-implemented"] = " doesn't support version requests";
8 ["remote-server-not-found"] = " can't be reached via XMPP";
9 }
4 10
5 function riddim.plugins.version(bot) 11 function riddim.plugins.version(bot)
6 bot.stream:add_plugin("version"); 12 bot.stream:add_plugin("version");
7 bot.stream.version:set{ 13 bot.stream.version:set{
8 name = bot.config.bot_name or "Riddim"; 14 name = bot.config.bot_name or "Riddim";
24 .." version "..(reply.version or "unknown") 30 .." version "..(reply.version or "unknown")
25 .." on "..(reply.platform or "an unknown platform")); 31 .." on "..(reply.platform or "an unknown platform"));
26 else 32 else
27 local type, condition, text = reply.type, reply.condition, reply.text; 33 local type, condition, text = reply.type, reply.condition, reply.text;
28 local r = "There was an error requesting "..param.."'s version"; 34 local r = "There was an error requesting "..param.."'s version";
29 if condition == "service-unavailable" then 35 local friendly_error = friendly_errors[condition];
30 r = param.." doesn't reply to version requests"; 36 if friendly_error then
31 elseif condition == "feature-not-implemented" then 37 r = r .. friendly_error;
32 r = param.." doesn't support version requests";
33 elseif condition == "remote-server-not-found" then
34 r = param.." can't be reached via XMPP";
35 elseif condition and not text then 38 elseif condition and not text then
36 r = r..": "..condition; 39 r = r..": "..(condition):gsub("%-", " ");
37 end 40 end
38 if text then 41 if text then
39 r = r .. " ("..text..")"; 42 r = r .. " ("..text..")";
40 end 43 end
41 command:reply(r); 44 command:reply(r);

mercurial