From 1def85e5d228d20823402b5d82eccd305c6293f2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 4 Jul 2023 12:13:31 +0200 Subject: [PATCH] Config - Now map repository names to channel names App - Now we join all channels in the `repo -> channel` map --- config.json | 6 ++++-- source/app.d | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/config.json b/config.json index 220562d..00fb214 100644 --- a/config.json +++ b/config.json @@ -8,9 +8,11 @@ "irc" : { "host": "worcester.irc.bnet.eu.org", "port": 6667, - "nickname": "tlangbot", + "nickname": "tlangbot1", "realname": "TLang Development Bot", - "channel": "#tlang" + "channels": { + "tlang" : "#tlang" + } }, "ntfy": { "endpoint": "http://ntfy.sh", diff --git a/source/app.d b/source/app.d index 6521088..cfda838 100644 --- a/source/app.d +++ b/source/app.d @@ -70,7 +70,7 @@ void commitHandler(HTTPServerRequest request, HTTPServerResponse response) string repositoryName = json["repository"]["full_name"].str(); /* Extract JUST the repository's name */ - toChannel = json["repository"]["name"].str(); + toChannel = associations[json["repository"]["name"].str()]; string ircMessage = bold("["~repositoryName~"]")~" New commit "~commitMessage~" ("~commitID~") by "~italics(authorName)~" ("~authorEmail~") ["~underline(commitURL)~"]"; ircBot.channelMessage(ircMessage, toChannel); //TODO: Add IRC error handling @@ -112,7 +112,7 @@ void issueHandler(HTTPServerRequest request, HTTPServerResponse response) string repositoryName = issueBlock["repository"]["full_name"].str(); /* Extract JUST the repository's name */ - toChannel = json["repository"]["name"].str(); + toChannel = associations[json["repository"]["name"].str()]; /* Opened a new issue */ if(cmp(issueAction, "opened") == 0) @@ -231,7 +231,7 @@ string serverHost; ushort serverPort; string nickname; string channelName; - +string[string] associations; /** * Sends a message to ntfy.sh (only if it is enabled) @@ -304,7 +304,16 @@ void main(string[] args) serverHost = ircBlock["host"].str(); serverPort = cast(ushort)(ircBlock["port"].integer()); nickname = ircBlock["nickname"].str(); - channelName = ircBlock["channel"].str(); + + /** + * Mapping between `repo -> #channel` + */ + JSONValue[string] channelAssociations = ircBlock["channels"].object(); + foreach(string repoName; channelAssociations.keys()) + { + associations[repoName] = channelAssociations[repoName].str(); + } + /* Attempt to parse ntfy.sh configuration */ @@ -357,9 +366,9 @@ void main(string[] args) //TODO: Clean this string up ircBot.command(new Message("", "USER", "giteabotweb giteabotweb irc.frdeenode.net :Tristan B. Kildaire")); - /* Join the requested channel */ + /* Join the requested channels */ Thread.sleep(dur!("seconds")(4)); - ircBot.joinChannel(channelName); + ircBot.joinChannel(associations.keys()); /* Setup the web server */