From c5863751dea8d2634fa7b808c7fb3c83949edcc8 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 24 Sep 2023 15:46:28 +0200 Subject: [PATCH 1/2] Gitea IRC Bot - Implemented `getRespectiveChannel(string repositoryName)` --- source/app.d | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/app.d b/source/app.d index c735926..ca57a07 100644 --- a/source/app.d +++ b/source/app.d @@ -267,6 +267,30 @@ void notifySH(string message) } } +/** + * Given a repository's name this will look it + * up in the key-value store to find the respective + * channel that should be used to send the message to + * + * Params: + * repositoryName = the repository to lookup by + * Returns: the channel's name + * Throws: + * Exception = if the repository does not exist + * in the map + */ +private string getRespectiveChannel(string repositoryName) +{ + string* channelName = repositoryName in associations; + + if(channelName is null) + { + throw new Exception("No channel exists for repository '"~repositoryName~"'"); + } + + return *channelName; +} + void main() { string configFilePath; From e4ba063a442849df83049d1c26746bbdeef0bafa Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 24 Sep 2023 15:47:32 +0200 Subject: [PATCH 2/2] Gitea IRC Bot - Switched to using `getRespectiveChannel(string)` for `/commit` and /`issue` handling --- source/app.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/app.d b/source/app.d index ca57a07..70f564d 100644 --- a/source/app.d +++ b/source/app.d @@ -81,7 +81,7 @@ void commitHandler(HTTPServerRequest request, HTTPServerResponse response) string repositoryName = json["repository"]["full_name"].str(); /* Extract JUST the repository's name */ - toChannel = associations[json["repository"]["name"].str()]; + toChannel = getRespectiveChannel(json["repository"]["name"].str()); string ircMessage = bold("["~repositoryName~"]")~setForeground(SimpleColor.GREEN)~" New commit "~resetForegroundBackground()~commitMessage~" ("~commitID~") by "~italics(authorName)~" ("~authorEmail~") ["~underline(commitURL)~"]"; ircBot.channelMessage(ircMessage, toChannel); //TODO: Add IRC error handling @@ -128,7 +128,7 @@ void issueHandler(HTTPServerRequest request, HTTPServerResponse response) string repositoryName = issueBlock["repository"]["full_name"].str(); /* Extract JUST the repository's name */ - toChannel = associations[json["repository"]["name"].str()]; + toChannel = getRespectiveChannel(json["repository"]["name"].str()); /* Opened a new issue */ if(cmp(issueAction, "opened") == 0)