plugins.version: Put friendly errors in a table

Thu, 09 Jul 2015 22:48:55 +0200

author
Kim Alvefur <zash@zash.se>
date
Thu, 09 Jul 2015 22:48:55 +0200
changeset 125
2c570064f582
parent 124
4530954f545a
child 126
99781a97f582

plugins.version: Put friendly errors in a table

plugins/version.lua file | annotate | diff | comparison | revisions
--- a/plugins/version.lua	Thu Jul 09 14:39:10 2015 +0200
+++ b/plugins/version.lua	Thu Jul 09 22:48:55 2015 +0200
@@ -2,6 +2,12 @@
 
 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{
@@ -26,14 +32,11 @@
 			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";
+				local friendly_error = friendly_errors[condition];
+				if friendly_error then
+					r = r .. friendly_error;
 				elseif condition and not text then
-					r = r..": "..condition;
+					r = r..": "..(condition):gsub("%-", "  ");
 				end
 				if text then
 					r = r .. " ("..text..")";

mercurial