- Now map repository names to channel names

App

- Now we join all channels in the `repo -> channel` map
This commit is contained in:
Tristan B. Velloza Kildaire 2023-07-04 12:13:31 +02:00
parent 682f52b246
commit 1def85e5d2
2 changed files with 19 additions and 8 deletions

View File

@ -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",

View File

@ -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 */