mirror-nourybot/cmd/bot/bot.go

56 lines
1.1 KiB
Go
Raw Normal View History

2021-10-13 21:30:31 +02:00
package bot
import (
2021-10-14 19:02:07 +02:00
"time"
2021-10-13 21:30:31 +02:00
twitch "github.com/gempir/go-twitch-irc/v2"
)
type Bot struct {
2021-10-19 22:25:47 +02:00
TwitchClient *twitch.Client
2021-10-14 19:02:07 +02:00
Uptime time.Time
2021-10-13 21:30:31 +02:00
}
2021-10-19 22:25:47 +02:00
type Channel struct {
Name string
2021-10-13 21:30:31 +02:00
}
2021-10-13 21:39:34 +02:00
2021-10-20 22:59:05 +02:00
// Send checks the message against a banphrase api
// and also splits the message into two if the message
// is too long for a single twitch chat message.
2021-10-19 22:25:47 +02:00
func (b *Bot) Send(target, text string) {
if len(text) == 0 {
return
2021-10-13 21:39:34 +02:00
}
2021-10-20 00:02:53 +02:00
// if text[0] == '.' || text[0] == '/' {
// text = ". " + text
2021-10-19 22:25:47 +02:00
// }
2021-10-20 22:59:05 +02:00
2021-10-21 01:46:25 +02:00
// If a message is too long for a single twitch
// message, split it into two messages.
if len(text) > 500 {
firstMessage := text[0:499]
secondMessage := text[499:]
b.TwitchClient.Say(target, firstMessage)
b.TwitchClient.Say(target, secondMessage)
return
}
2021-10-20 22:59:05 +02:00
// check the message for bad words before we say it
messageBanned, banReason := CheckMessage(text)
if messageBanned {
// Bad message, replace message with a small
// notice on why it's banned.
b.TwitchClient.Say(target, banReason)
2021-10-20 22:35:36 +02:00
return
} else {
2021-10-20 22:59:05 +02:00
// Message was okay.
2021-10-20 22:35:36 +02:00
b.TwitchClient.Say(target, text)
return
}
2021-10-13 21:39:34 +02:00
2021-10-13 23:29:29 +02:00
}