From 24519b76b48f521f1ef4c7e5e038574eaa66ebcd Mon Sep 17 00:00:00 2001 From: ascpial Date: Sat, 13 Sep 2025 21:40:24 +0200 Subject: feat(config): improve /config look and xp_role usability --- config/guild.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'config/guild.go') diff --git a/config/guild.go b/config/guild.go index 8384d5b..6310fa4 100644 --- a/config/guild.go +++ b/config/guild.go @@ -43,3 +43,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 +} -- cgit v1.2.3 From 8a7189c3835a431b7fc16b189162f6f343e80b84 Mon Sep 17 00:00:00 2001 From: ascpial Date: Sat, 20 Sep 2025 23:33:29 +0200 Subject: feat(config): finish upgrading config --- config/guild.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'config/guild.go') diff --git a/config/guild.go b/config/guild.go index 6310fa4..8096096 100644 --- a/config/guild.go +++ b/config/guild.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/anhgelus/gokord" + discordgo "github.com/nyttikord/gokord" ) type GuildConfig struct { @@ -31,8 +32,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 *discordgo.Session, channelID string) bool { + ok := true + s.LogInfo("Configuration: %s", cfg.DisabledChannels) + s.LogInfo("Channel %s, ok %t", channelID, ok) + for channelID != "" && ok { + s.LogInfo("Channel %s, ok %t", channelID, ok) + ok = !strings.Contains(cfg.DisabledChannels, channelID) + c, err := s.State.Channel(channelID) + if err != nil { + s.LogError(err, "Unable to find channel %s in state", c) + c, err = s.ChannelAPI().Channel(channelID) + if err == nil { + s.State.ChannelAdd(c) + } else { + s.LogError(err, "Unable to fetch channel %s", s) + return false + } + } + if err != nil { + return false + } + channelID = c.ParentID + } + return !ok } func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) { -- cgit v1.2.3 From 30f110d8d49cd1174882c58916147f52e09dd51e Mon Sep 17 00:00:00 2001 From: ascpial Date: Sun, 21 Sep 2025 23:34:31 +0200 Subject: fix(config): forgot some things --- config/guild.go | 3 --- 1 file changed, 3 deletions(-) (limited to 'config/guild.go') diff --git a/config/guild.go b/config/guild.go index 8096096..9cdb7e4 100644 --- a/config/guild.go +++ b/config/guild.go @@ -34,10 +34,7 @@ func (cfg *GuildConfig) Save() error { func (cfg *GuildConfig) IsDisabled(s *discordgo.Session, channelID string) bool { ok := true - s.LogInfo("Configuration: %s", cfg.DisabledChannels) - s.LogInfo("Channel %s, ok %t", channelID, ok) for channelID != "" && ok { - s.LogInfo("Channel %s, ok %t", channelID, ok) ok = !strings.Contains(cfg.DisabledChannels, channelID) c, err := s.State.Channel(channelID) if err != nil { -- cgit v1.2.3 From b61a834b608df3d5e617912eefb28924ef3a46df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Fri, 26 Sep 2025 18:30:57 +0200 Subject: build(gokord): bump to latest nightly --- config/guild.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'config/guild.go') diff --git a/config/guild.go b/config/guild.go index 9cdb7e4..10c64fd 100644 --- a/config/guild.go +++ b/config/guild.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/anhgelus/gokord" - discordgo "github.com/nyttikord/gokord" + "github.com/nyttikord/gokord/bot" ) type GuildConfig struct { @@ -32,18 +32,21 @@ func (cfg *GuildConfig) Save() error { return gokord.DB.Save(cfg).Error } -func (cfg *GuildConfig) IsDisabled(s *discordgo.Session, channelID string) bool { +func (cfg *GuildConfig) IsDisabled(s bot.Session, channelID string) bool { ok := true for channelID != "" && ok { ok = !strings.Contains(cfg.DisabledChannels, channelID) - c, err := s.State.Channel(channelID) + c, err := s.ChannelAPI().State.Channel(channelID) if err != nil { - s.LogError(err, "Unable to find channel %s in state", c) + s.LogError(err, "unable to find channel %s in state", c) c, err = s.ChannelAPI().Channel(channelID) if err == nil { - s.State.ChannelAdd(c) + err = s.ChannelAPI().State.ChannelAdd(c) + if err != nil { + s.LogError(err, "unable to add channel %s to state", c) + } } else { - s.LogError(err, "Unable to fetch channel %s", s) + s.LogError(err, "unable to fetch channel %s", s) return false } } -- cgit v1.2.3 From cfdba5f417bb31aac564d13becc09874f17d075d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 27 Sep 2025 17:34:38 +0200 Subject: build(gokord): bump to latest nightly --- config/guild.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config/guild.go') diff --git a/config/guild.go b/config/guild.go index 10c64fd..e046ca7 100644 --- a/config/guild.go +++ b/config/guild.go @@ -38,15 +38,15 @@ func (cfg *GuildConfig) IsDisabled(s bot.Session, channelID string) bool { ok = !strings.Contains(cfg.DisabledChannels, channelID) c, err := s.ChannelAPI().State.Channel(channelID) if err != nil { - s.LogError(err, "unable to find channel %s in state", c) + 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.LogError(err, "unable to add channel %s to state", c) + s.Logger().Error("unable to add channel to state", "error", err, "channel", c) } } else { - s.LogError(err, "unable to fetch channel %s", s) + s.Logger().Error("unable to fetch channel", "error", err, "channel", c) return false } } -- cgit v1.2.3