From 3bcef5b48aa2261895445ac88eaeb154f2f0fcb0 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Wed, 20 Oct 2021 23:03:20 +0200 Subject: [PATCH] cleanup --- cmd/bot/banphrase.go | 15 ++++++++------- cmd/bot/bot.go | 2 ++ cmd/main.go | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/bot/banphrase.go b/cmd/bot/banphrase.go index 73a541c..9fda7f4 100644 --- a/cmd/bot/banphrase.go +++ b/cmd/bot/banphrase.go @@ -28,12 +28,13 @@ type banphraseData struct { Permanent bool `json:"permanent"` } -// CheckMessage checks if a message contains -// banphrased content. -// If a message is allowed it returns -// false, "okay" -// If a message is not allowed it returns: -// true, "[banphrased] monkaS" +var ( + banPhraseUrl = "https://pajlada.pajbot.com/api/v1/banphrases/test" +) + +// CheckMessage checks a message against a banphrase api.. +// returns false, "okay" if a message was allowed +// returns true, "[banphrased] monkaS" and the reason if not. // More information: // https://gist.github.com/pajlada/57464e519ba8d195a97ddcd0755f9715 func CheckMessage(text string) (bool, string) { @@ -47,7 +48,7 @@ func CheckMessage(text string) (bool, string) { log.Error(err) } - resp, err := http.Post("https://pajlada.pajbot.com/api/v1/banphrases/test", "application/json", bytes.NewBuffer(reqBody)) + resp, err := http.Post(banPhraseUrl, "application/json", bytes.NewBuffer(reqBody)) if err != nil { log.Error(err) } diff --git a/cmd/bot/bot.go b/cmd/bot/bot.go index b5bd95c..25ce095 100644 --- a/cmd/bot/bot.go +++ b/cmd/bot/bot.go @@ -45,8 +45,10 @@ func (b *Bot) Send(target, text string) { if len(text) > 500 { firstMessage := text[0:499] secondMessage := text[499:] + b.TwitchClient.Say(target, firstMessage) b.TwitchClient.Say(target, secondMessage) + return } diff --git a/cmd/main.go b/cmd/main.go index b9d4ddb..bd90231 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -21,6 +21,7 @@ func main() { } nb.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { + // If channelID is missing something must have gone wrong. channelID := message.Tags["room-id"] if channelID == "" { @@ -28,7 +29,7 @@ func main() { return } - // So that the bot doesn't repeat itself. + // Don't act on bots own messages. if message.Tags["user-id"] == "596581605" { return }