move settings.Allowed() to bot.Allowed()
This commit is contained in:
@@ -175,7 +175,7 @@ func (b *Bot) runStop(ctx context.Context, checkAllowed bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkAllowed && !cfg.Allowed(b.noowner, evt.Sender, b.allowedUsers) {
|
if checkAllowed && !b.Allowed(evt.Sender, cfg) {
|
||||||
b.Notice(ctx, evt.RoomID, "you don't have permission to do that")
|
b.Notice(ctx, evt.RoomID, "you don't have permission to do that")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.Allowed(b.noowner, evt.Sender, b.allowedUsers) {
|
if !b.Allowed(evt.Sender, cfg) {
|
||||||
b.Notice(ctx, evt.RoomID, "you don't have permission to do that, kupo")
|
b.Notice(ctx, evt.RoomID, "you don't have permission to do that, kupo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -20,24 +19,6 @@ type settingsOld struct {
|
|||||||
NoSender bool
|
NoSender bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allowed checks if change is allowed
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
owner := s.Owner()
|
|
||||||
if owner == "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return owner == userID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get option
|
// Get option
|
||||||
func (s settings) Get(key string) string {
|
func (s settings) Get(key string) string {
|
||||||
value := s[strings.ToLower(strings.TrimSpace(key))]
|
value := s[strings.ToLower(strings.TrimSpace(key))]
|
||||||
@@ -123,3 +104,21 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
|
|||||||
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
|
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
|
||||||
return utils.UnwrapError(b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg))
|
return utils.UnwrapError(b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allowed checks if change is allowed
|
||||||
|
func (b *Bot) Allowed(userID id.UserID, cfg settings) bool {
|
||||||
|
if !utils.Match(userID.String(), b.allowedUsers) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.noowner {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
owner := cfg.Owner()
|
||||||
|
if owner == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return owner == userID.String()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user