From 3bc10bfe4f3d91b44098066344e06f208a0ac18c Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 27 Aug 2022 17:29:00 +0300 Subject: [PATCH] Honor allowed users list --- bot/command.go | 4 ++-- bot/settings.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bot/command.go b/bot/command.go index ea19740..9a67a97 100644 --- a/bot/command.go +++ b/bot/command.go @@ -175,7 +175,7 @@ func (b *Bot) runStop(ctx context.Context, checkAllowed bool) { return } - if checkAllowed && !cfg.Allowed(b.noowner, evt.Sender) { + if checkAllowed && !cfg.Allowed(b.noowner, evt.Sender, b.allowedUsers) { b.Notice(ctx, evt.RoomID, "you don't have permission to do that") return } @@ -251,7 +251,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { return } - if !cfg.Allowed(b.noowner, evt.Sender) { + if !cfg.Allowed(b.noowner, evt.Sender, b.allowedUsers) { b.Notice(ctx, evt.RoomID, "you don't have permission to do that, kupo") return } diff --git a/bot/settings.go b/bot/settings.go index ad37899..a7a103c 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -1,6 +1,7 @@ package bot import ( + "regexp" "strconv" "strings" @@ -20,7 +21,11 @@ type settingsOld struct { } // Allowed checks if change is allowed -func (s settings) Allowed(noowner bool, userID id.UserID) bool { +func (s settings) Allowed(noowner bool, userID id.UserID, allowedUsers []*regexp.Regexp) bool { + if !utils.Match(userID.String(), allowedUsers) { + return false + } + if noowner { return true }