From 4e1d2a4c5611e8badaf1bdc4a196600eed252677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 6 Oct 2022 12:37:38 +0200 Subject: [PATCH] bot: Check badges to see if a user is authorized --- bot.go | 7 +++++++ settings.go | 4 +--- static_commands.go | 5 +---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bot.go b/bot.go index ed97af5..3be5805 100644 --- a/bot.go +++ b/bot.go @@ -1,6 +1,7 @@ package main import ( + "errors" "log" "os" @@ -8,12 +9,18 @@ import ( "github.com/gempir/go-twitch-irc/v3" ) +var errNotAuthorized = errors.New("not authorized") + type bot struct { client *twitch.Client cfg *config db *database.DB } +func (b *bot) isAuthorized(user *twitch.User) bool { + return user.Badges["broadcaster"] == 1 +} + func (b *bot) say(msg *twitch.PrivateMessage, text string) { useReply := b.cfg.Channels[msg.Channel].UseReply if useReply { diff --git a/settings.go b/settings.go index abb32cb..643811c 100644 --- a/settings.go +++ b/settings.go @@ -7,9 +7,7 @@ import ( ) func (b *bot) handleSet(parsed []string, msg *twitch.PrivateMessage) error { - // NOTE: Only allow mods or owner to use this - // Wait for https://github.com/gempir/go-twitch-irc/pull/188 to get merged - if msg.User.Name != msg.Channel { + if !b.isAuthorized(&msg.User) { return errNotAuthorized } diff --git a/static_commands.go b/static_commands.go index 511a153..36bb8ec 100644 --- a/static_commands.go +++ b/static_commands.go @@ -9,13 +9,10 @@ import ( "github.com/gempir/go-twitch-irc/v3" ) -var errNotAuthorized = errors.New("not authorized") var errTooShort = errors.New("input too short") func (b *bot) handleCommands(parsed []string, msg *twitch.PrivateMessage) error { - // NOTE: Only allow mods or owner to use this - // Wait for https://github.com/gempir/go-twitch-irc/pull/188 to get merged - if msg.User.Name != msg.Channel { + if !b.isAuthorized(&msg.User) { return errNotAuthorized } -- 2.44.0