From 2304c6278bca1649265e22a080e7b90f42df4693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 6 Oct 2022 12:52:34 +0200 Subject: [PATCH] bot: Moderators are authorized as well Can be disabled in the config file. --- bot.go | 5 +++-- config.go | 17 ++++++++++++++++- settings.go | 2 +- static_commands.go | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index 3be5805..3f13b0a 100644 --- a/bot.go +++ b/bot.go @@ -17,8 +17,9 @@ type bot struct { db *database.DB } -func (b *bot) isAuthorized(user *twitch.User) bool { - return user.Badges["broadcaster"] == 1 +func (b *bot) isAuthorized(user *twitch.User, channel string) bool { + return user.Badges["broadcaster"] == 1 || + (b.cfg.Channels[channel].ModsAreAdmins && user.Badges["moderator"] == 1) } func (b *bot) say(msg *twitch.PrivateMessage, text string) { diff --git a/config.go b/config.go index 79b15c6..9191733 100644 --- a/config.go +++ b/config.go @@ -16,7 +16,8 @@ type config struct { } type channel struct { - UseReply bool + UseReply bool + ModsAreAdmins bool } func readConfig(path string) (*config, error) { @@ -81,6 +82,20 @@ func readConfig(path string) (*config, error) { } } + // By default mods should be allowed to edit commands + channel.ModsAreAdmins = true + d = channelDir.Children.Get("mods-are-admins") + if d != nil { + var modsAreAdmins string + if err := d.ParseParams(&modsAreAdmins); err != nil { + return nil, err + } + + if modsAreAdmins == "false" { + channel.ModsAreAdmins = false + } + } + channels[name] = *channel } config.Channels = channels diff --git a/settings.go b/settings.go index 643811c..8e6add8 100644 --- a/settings.go +++ b/settings.go @@ -7,7 +7,7 @@ import ( ) func (b *bot) handleSet(parsed []string, msg *twitch.PrivateMessage) error { - if !b.isAuthorized(&msg.User) { + if !b.isAuthorized(&msg.User, msg.Channel) { return errNotAuthorized } diff --git a/static_commands.go b/static_commands.go index 36bb8ec..5f45433 100644 --- a/static_commands.go +++ b/static_commands.go @@ -12,7 +12,7 @@ import ( var errTooShort = errors.New("input too short") func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error { - if !b.isAuthorized(&msg.User) { + if !b.isAuthorized(&msg.User, msg.Channel) { return errNotAuthorized } -- 2.44.0