plugins.github: Support per-room configuration

Fri, 07 Aug 2015 21:45:02 +0200

author
Kim Alvefur <zash@zash.se>
date
Fri, 07 Aug 2015 21:45:02 +0200
changeset 128
5b03c71d05f0
parent 127
6c977fbf6d0b
child 129
c9da10093c51

plugins.github: Support per-room configuration

plugins/github.lua file | annotate | diff | comparison | revisions
--- a/plugins/github.lua	Fri Aug 07 21:44:21 2015 +0200
+++ b/plugins/github.lua	Fri Aug 07 21:45:02 2015 +0200
@@ -6,7 +6,6 @@
 	local conf = bot.config.github;
 	local base_url = url.parse("https://api.github.com/repos/x/y/issues/123");
 	local base_path = url.parse_path(base_url.path);
-	base_path[2], base_path[3] = conf.user, conf.project;
 
 	local ex = {
 		headers = {
@@ -14,7 +13,9 @@
 		};
 	};
 
-	local function issue_url(number)
+	local function get_issue_url(conf, number)
+		base_path[2] = conf.user;
+		base_path[3] = conf.repo or conf.project;
 		base_path[5] = number;
 		base_url.path = url.build_path(base_path);
 		local url = url.build(base_url);
@@ -24,6 +25,8 @@
 	bot:hook("commands/issue", function (command)
 		local issue_id = tonumber(command.param);
 		if not issue_id then return; end
+		local current_conf = conf[command.room and command.room.jid or "default"];
+		if not current_conf then return end
 		assert(http.request(issue_url(issue_id), ex, function (issue, code)
 			if code > 400 then
 				return command:reply("HTTP Error "..code.." :(");

mercurial