aboutsummaryrefslogtreecommitdiff
path: root/config/guild.go
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-09-27 18:23:27 +0200
committerWilliam Hergès <william@herges.fr>2025-09-27 18:23:27 +0200
commitb1d3bca64702e66b5ecfe5c9ea5f43aa9dc1d1e6 (patch)
tree67474ed704f529fe4941c179b7697b54099cc326 /config/guild.go
parentc46d1c34a29b10dac2a059b9d78e99a3d5d76f96 (diff)
parentcfdba5f417bb31aac564d13becc09874f17d075d (diff)
Merge branch 'main' into feat/xp-boostfeat/xp-boost
Diffstat (limited to 'config/guild.go')
-rw-r--r--config/guild.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/config/guild.go b/config/guild.go
index 971470d..c2a1636 100644
--- a/config/guild.go
+++ b/config/guild.go
@@ -4,6 +4,7 @@ import (
"strings"
"github.com/anhgelus/gokord"
+ "github.com/nyttikord/gokord/bot"
)
type GuildConfig struct {
@@ -46,8 +47,30 @@ func (cfg *GuildConfig) Save() error {
return gokord.DB.Save(cfg).Error
}
-func (cfg *GuildConfig) IsDisabled(channelID string) bool {
- return strings.Contains(cfg.DisabledChannels, channelID)
+func (cfg *GuildConfig) IsDisabled(s bot.Session, channelID string) bool {
+ ok := true
+ for channelID != "" && ok {
+ ok = !strings.Contains(cfg.DisabledChannels, channelID)
+ c, err := s.ChannelAPI().State.Channel(channelID)
+ if err != nil {
+ s.Logger().Error("unable to find channel %s in state", "error", err, "channel", c)
+ c, err = s.ChannelAPI().Channel(channelID)
+ if err == nil {
+ err = s.ChannelAPI().State.ChannelAdd(c)
+ if err != nil {
+ s.Logger().Error("unable to add channel to state", "error", err, "channel", c)
+ }
+ } else {
+ s.Logger().Error("unable to fetch channel", "error", err, "channel", c)
+ return false
+ }
+ }
+ if err != nil {
+ return false
+ }
+ channelID = c.ParentID
+ }
+ return !ok
}
func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) {
@@ -58,3 +81,12 @@ func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) {
}
return 0, nil
}
+
+func (cfg *GuildConfig) FindXpRoleID(ID uint) (int, *XpRole) {
+ for i, r := range cfg.XpRoles {
+ if r.ID == ID {
+ return i, &r
+ }
+ }
+ return -1, nil
+}