mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
cleanup
This commit is contained in:
parent
dc70232d54
commit
33f61e2f0f
|
@ -37,8 +37,8 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
|
|||
|
||||
sugar.Infow("Command received",
|
||||
// "message", message,
|
||||
"message.Channel", target,
|
||||
"message.Message", message.Message,
|
||||
"target", target,
|
||||
"commandName", commandName,
|
||||
"cmdParams", cmdParams,
|
||||
"msgLen", msgLen,
|
||||
|
|
|
@ -15,11 +15,10 @@ type Application struct {
|
|||
func main() {
|
||||
cfg := config.New()
|
||||
|
||||
tc := twitch.NewClient(cfg.TwitchUsername, cfg.TwitchOauth)
|
||||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
tc := twitch.NewClient(cfg.TwitchUsername, cfg.TwitchOauth)
|
||||
|
||||
app := &Application{
|
||||
TwitchClient: tc,
|
||||
Logger: sugar,
|
||||
|
@ -40,9 +39,10 @@ func main() {
|
|||
// Successfully connected to Twitch so we log a message with the
|
||||
// mode we are currently running in..
|
||||
app.TwitchClient.OnConnect(func() {
|
||||
sugar.Infow("Successfully connected to Twitch Servers",
|
||||
app.Logger.Infow("Successfully connected to Twitch Servers",
|
||||
"Bot username", cfg.TwitchUsername,
|
||||
"Environment", cfg.Environment)
|
||||
"Environment", cfg.Environment,
|
||||
)
|
||||
|
||||
common.Send("nourylul", "xd", app.TwitchClient)
|
||||
})
|
||||
|
|
|
@ -10,17 +10,19 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
|
|||
defer sugar.Sync()
|
||||
|
||||
// roomId is the Twitch UserID of the channel the message originated from.
|
||||
// If there is no roomId something went really wrong.
|
||||
roomId := message.Tags["room-id"]
|
||||
|
||||
// If there is no roomId something went wrong.
|
||||
if roomId == "" {
|
||||
sugar.Errorw("Missing room-id in message tag",
|
||||
"roomId", roomId)
|
||||
app.Logger.Errorw("Missing room-id in message tag",
|
||||
"roomId", roomId,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Message was shorter than our prefix is therefore it's irrelevant for us.
|
||||
if len(message.Message) >= 2 {
|
||||
// Strip the `()` prefix
|
||||
if message.Message[:2] == "()" {
|
||||
handleCommand(message, app.TwitchClient)
|
||||
return
|
||||
|
@ -29,7 +31,7 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
|
|||
|
||||
// Message was no command so we just print it.
|
||||
app.Logger.Infow("Private Message received",
|
||||
"message", message,
|
||||
// "message", message,
|
||||
"message.Channel", message.Channel,
|
||||
"message.User", message.User.DisplayName,
|
||||
"message.Message", message.Message,
|
||||
|
|
|
@ -8,5 +8,6 @@ func (app *Application) handleWhisperMessage(message twitch.WhisperMessage) {
|
|||
app.Logger.Infow("Whisper Message received",
|
||||
"message", message,
|
||||
"message.User.DisplayName", message.User.DisplayName,
|
||||
"message.Message", message.Message)
|
||||
"message.Message", message.Message,
|
||||
)
|
||||
}
|
||||
|
|
2
go.sum
2
go.sum
|
@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.1.0 h1:bUVZ5mADhH7KidJVcl+z79kgLJ7sjdAk4b/ylAvaLy0=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.1.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.2.0 h1:ENhsa7RgBE1GMmDqe0iMkvcSYfgw6ZsXilt+sAg32/U=
|
||||
github.com/gempir/go-twitch-irc/v3 v3.2.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
|
||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
|
|
|
@ -93,7 +93,7 @@ func Send(target, message string, tc *twitch.Client) {
|
|||
}
|
||||
|
||||
// Since messages starting with `.` or `/` are used for special actions
|
||||
// (ban, whisper, timeout) and so on, we place a emote infront of it so
|
||||
// (ban, whisper, timeout) and so on, we place an emote infront of it so
|
||||
// the actions wouldn't execute. `!` and `$` are common bot prefixes so we
|
||||
// don't allow them either.
|
||||
if message[0] == '.' || message[0] == '/' || message[0] == '!' || message[0] == '$' {
|
||||
|
@ -106,13 +106,18 @@ func Send(target, message string, tc *twitch.Client) {
|
|||
// Bad message, replace message and log it.
|
||||
tc.Say(target, "[BANPHRASED] monkaS")
|
||||
sugar.Infow("banned message detected",
|
||||
"banReason", banReason)
|
||||
"target channel", target,
|
||||
"message", message,
|
||||
"ban reason", banReason,
|
||||
)
|
||||
|
||||
return
|
||||
} else {
|
||||
// In case the message we are trying to send is longer than the
|
||||
// maximum allowed message length on twitch. We split the message
|
||||
// in two parts.
|
||||
// maximum allowed message length on twitch we split the message in two parts.
|
||||
// Twitch has a maximum length for messages of 510 characters so to be safe
|
||||
// we split and check at 500 characters.
|
||||
// https://discuss.dev.twitch.tv/t/missing-client-side-message-length-check/21316
|
||||
if len(message) > 500 {
|
||||
firstMessage := message[0:499]
|
||||
secondMessage := message[499:]
|
||||
|
|
Loading…
Reference in a new issue