diff options
Diffstat (limited to 'config/guild.go')
| -rw-r--r-- | config/guild.go | 36 |
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 +} |
