feat(xp): disable xp in disabled channels

This commit is contained in:
Anhgelus Morhtuuzh 2024-04-15 16:48:16 +02:00
parent f97df035c3
commit a8c0a395ac
No known key found for this signature in database
GPG key ID: CF4550297832A29F
2 changed files with 10 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package config
import ( import (
"github.com/anhgelus/gokord" "github.com/anhgelus/gokord"
"gorm.io/gorm" "gorm.io/gorm"
"strings"
) )
type GuildConfig struct { type GuildConfig struct {
@ -33,6 +34,10 @@ func (cfg *GuildConfig) Save() {
gokord.DB.Save(cfg) gokord.DB.Save(cfg)
} }
func (cfg *GuildConfig) IsDisabled(channelID string) bool {
return strings.Contains(cfg.DisabledChannels, channelID)
}
func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) { func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) {
for i, r := range cfg.XpRoles { for i, r := range cfg.XpRoles {
if r.RoleID == roleID { if r.RoleID == roleID {

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/anhgelus/gokord" "github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils" "github.com/anhgelus/gokord/utils"
"github.com/anhgelus/les-copaings-bot/config"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"slices" "slices"
@ -24,6 +25,10 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot { if m.Author.Bot {
return return
} }
cfg := config.GetGuildConfig(m.GuildID)
if cfg.IsDisabled(m.ChannelID) {
return
}
c := GetCopaing(m.Author.ID, m.GuildID) c := GetCopaing(m.Author.ID, m.GuildID)
// add xp // add xp
trimmed := utils.TrimMessage(strings.ToLower(m.Content)) trimmed := utils.TrimMessage(strings.ToLower(m.Content))