Compare commits
No commits in common. "026abcc07a57eeda8a08a746ad2b664e956360f3" and "b59da2cca7eab152ac51bcb1de00af7c7cf9fdfb" have entirely different histories.
026abcc07a
...
b59da2cca7
13 changed files with 157 additions and 174 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,4 +26,3 @@ go.work
|
||||||
tmp
|
tmp
|
||||||
config/**.toml
|
config/**.toml
|
||||||
data
|
data
|
||||||
docker-compose.yml
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
cfg := config.GetGuildConfig(i.GuildID)
|
cfg := config.GetGuildConfig(i.GuildID)
|
||||||
|
resp := utils.NewResponseBuilder(s, i)
|
||||||
roles := ""
|
roles := ""
|
||||||
l := len(cfg.XpRoles) - 1
|
l := len(cfg.XpRoles) - 1
|
||||||
for i, r := range cfg.XpRoles {
|
for i, r := range cfg.XpRoles {
|
||||||
|
@ -43,30 +44,32 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap uti
|
||||||
} else {
|
} else {
|
||||||
defaultChan = fmt.Sprintf("<#%s>", cfg.FallbackChannel)
|
defaultChan = fmt.Sprintf("<#%s>", cfg.FallbackChannel)
|
||||||
}
|
}
|
||||||
err := resp.AddEmbed(&discordgo.MessageEmbed{
|
err := resp.Embeds([]*discordgo.MessageEmbed{
|
||||||
Type: discordgo.EmbedTypeRich,
|
{
|
||||||
Title: "Config",
|
Type: discordgo.EmbedTypeRich,
|
||||||
Color: utils.Success,
|
Title: "Config",
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Color: utils.Success,
|
||||||
{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
Name: "Salon par défaut",
|
{
|
||||||
Value: defaultChan,
|
Name: "Salon par défaut",
|
||||||
Inline: false,
|
Value: defaultChan,
|
||||||
},
|
Inline: false,
|
||||||
{
|
},
|
||||||
Name: "Rôles liés aux niveaux",
|
{
|
||||||
Value: roles,
|
Name: "Rôles liés aux niveaux",
|
||||||
Inline: false,
|
Value: roles,
|
||||||
},
|
Inline: false,
|
||||||
{
|
},
|
||||||
Name: "Salons désactivés",
|
{
|
||||||
Value: chans,
|
Name: "Salons désactivés",
|
||||||
Inline: false,
|
Value: chans,
|
||||||
},
|
Inline: false,
|
||||||
{
|
},
|
||||||
Name: "Jours avant la réduction",
|
{
|
||||||
Value: fmt.Sprintf("%d", cfg.DaysXPRemains),
|
Name: "Jours avant la réduction",
|
||||||
Inline: false,
|
Value: fmt.Sprintf("%d", cfg.DaysXPRemains),
|
||||||
|
Inline: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).Send()
|
}).Send()
|
||||||
|
@ -75,12 +78,13 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate, optMap uti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
resp.IsEphemeral()
|
optMap := utils.GenerateOptionMapForSubcommand(i)
|
||||||
|
resp := utils.NewResponseBuilder(s, i).IsEphemeral()
|
||||||
// verify every args
|
// verify every args
|
||||||
t, ok := optMap["type"]
|
t, ok := optMap["type"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le type d'action n'a pas été renseigné.").Send()
|
err := resp.Message("Le type d'action n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Action type not set", err.Error())
|
utils.SendAlert("commands/config.go - Action type not set", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
ts := t.StringValue()
|
ts := t.StringValue()
|
||||||
lvl, ok := optMap["level"]
|
lvl, ok := optMap["level"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le niveau n'a pas été renseigné.").Send()
|
err := resp.Message("Le niveau n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Level not set", err.Error())
|
utils.SendAlert("commands/config.go - Level not set", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -97,7 +101,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
}
|
}
|
||||||
level := lvl.IntValue()
|
level := lvl.IntValue()
|
||||||
if level < 1 {
|
if level < 1 {
|
||||||
err := resp.SetMessage("Le niveau doit forcément être supérieur à 0.").Send()
|
err := resp.Message("Le niveau doit forcément être supérieur à 0.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Invalid level", err.Error())
|
utils.SendAlert("commands/config.go - Invalid level", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -106,7 +110,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
xp := exp.LevelXP(uint(level))
|
xp := exp.LevelXP(uint(level))
|
||||||
r, ok := optMap["role"]
|
r, ok := optMap["role"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le rôle n'a pas été renseigné.").Send()
|
err := resp.Message("Le rôle n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Role not set", err.Error())
|
utils.SendAlert("commands/config.go - Role not set", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
case "add":
|
case "add":
|
||||||
for _, r := range cfg.XpRoles {
|
for _, r := range cfg.XpRoles {
|
||||||
if r.RoleID == role.ID {
|
if r.RoleID == role.ID {
|
||||||
err = resp.SetMessage("Le rôle est déjà présent dans la config").Send()
|
err = resp.Message("Le rôle est déjà présent dans la config").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Role already in config", err.Error())
|
utils.SendAlert("commands/config.go - Role already in config", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -148,7 +152,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
case "del":
|
case "del":
|
||||||
_, r := cfg.FindXpRole(role.ID)
|
_, r := cfg.FindXpRole(role.ID)
|
||||||
if r == nil {
|
if r == nil {
|
||||||
err = resp.SetMessage("Le rôle n'a pas été trouvé dans la config.").Send()
|
err = resp.Message("Le rôle n'a pas été trouvé dans la config.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Role not found (del)", err.Error())
|
utils.SendAlert("commands/config.go - Role not found (del)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -170,7 +174,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
case "edit":
|
case "edit":
|
||||||
_, r := cfg.FindXpRole(role.ID)
|
_, r := cfg.FindXpRole(role.ID)
|
||||||
if r == nil {
|
if r == nil {
|
||||||
err = resp.SetMessage("Le rôle n'a pas été trouvé dans la config.").Send()
|
err = resp.Message("Le rôle n'a pas été trouvé dans la config.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Role not found (edit)", err.Error())
|
utils.SendAlert("commands/config.go - Role not found (edit)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -191,28 +195,29 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err = resp.SetMessage("Le type d'action n'est pas valide.").Send()
|
err = resp.Message("Le type d'action n'est pas valide.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Invalid action type", err.Error())
|
utils.SendAlert("commands/config.go - Invalid action type", err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = resp.SetMessage("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
err = resp.Message("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
||||||
} else {
|
} else {
|
||||||
err = resp.SetMessage("La configuration a bien été mise à jour.").Send()
|
err = resp.Message("La configuration a bien été mise à jour.").Send()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Config updated message", err.Error())
|
utils.SendAlert("commands/config.go - Config updated message", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
resp.IsEphemeral()
|
optMap := utils.GenerateOptionMapForSubcommand(i)
|
||||||
|
resp := utils.NewResponseBuilder(s, i).IsEphemeral()
|
||||||
// verify every args
|
// verify every args
|
||||||
t, ok := optMap["type"]
|
t, ok := optMap["type"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le type d'action n'a pas été renseigné.").Send()
|
err := resp.Message("Le type d'action n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Action type not set", err.Error())
|
utils.SendAlert("commands/config.go - Action type not set", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -221,7 +226,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
|
||||||
ts := t.StringValue()
|
ts := t.StringValue()
|
||||||
salon, ok := optMap["channel"]
|
salon, ok := optMap["channel"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le salon n'a pas été renseigné.").Send()
|
err := resp.Message("Le salon n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Channel not set (disabled)", err.Error())
|
utils.SendAlert("commands/config.go - Channel not set (disabled)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -232,7 +237,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
|
||||||
switch ts {
|
switch ts {
|
||||||
case "add":
|
case "add":
|
||||||
if strings.Contains(cfg.DisabledChannels, channel.ID) {
|
if strings.Contains(cfg.DisabledChannels, channel.ID) {
|
||||||
err := resp.SetMessage("Le salon est déjà dans la liste des salons désactivés").Send()
|
err := resp.Message("Le salon est déjà dans la liste des salons désactivés").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Channel already disabled", err.Error())
|
utils.SendAlert("commands/config.go - Channel already disabled", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -241,7 +246,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
|
||||||
cfg.DisabledChannels += channel.ID + ";"
|
cfg.DisabledChannels += channel.ID + ";"
|
||||||
case "del":
|
case "del":
|
||||||
if !strings.Contains(cfg.DisabledChannels, channel.ID) {
|
if !strings.Contains(cfg.DisabledChannels, channel.ID) {
|
||||||
err := resp.SetMessage("Le salon n'est pas désactivé").Send()
|
err := resp.Message("Le salon n'est pas désactivé").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Channel not disabled", err.Error())
|
utils.SendAlert("commands/config.go - Channel not disabled", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -249,7 +254,7 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
|
||||||
}
|
}
|
||||||
cfg.DisabledChannels = strings.ReplaceAll(cfg.DisabledChannels, channel.ID+";", "")
|
cfg.DisabledChannels = strings.ReplaceAll(cfg.DisabledChannels, channel.ID+";", "")
|
||||||
default:
|
default:
|
||||||
err := resp.SetMessage("Le type d'action n'est pas valide.").Send()
|
err := resp.Message("Le type d'action n'est pas valide.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Invalid action type", err.Error())
|
utils.SendAlert("commands/config.go - Invalid action type", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -268,21 +273,22 @@ func ConfigChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap
|
||||||
"channel_id",
|
"channel_id",
|
||||||
channel.ID,
|
channel.ID,
|
||||||
)
|
)
|
||||||
err = resp.SetMessage("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
err = resp.Message("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
||||||
} else {
|
} else {
|
||||||
err = resp.SetMessage("Modification sauvegardé.").Send()
|
err = resp.Message("Modification sauvegardé.").Send()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Modification saved message", err.Error())
|
utils.SendAlert("commands/config.go - Modification saved message", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
resp.IsEphemeral()
|
optMap := utils.GenerateOptionMapForSubcommand(i)
|
||||||
|
resp := utils.NewResponseBuilder(s, i).IsEphemeral()
|
||||||
// verify every args
|
// verify every args
|
||||||
salon, ok := optMap["channel"]
|
salon, ok := optMap["channel"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le salon n'a pas été renseigné.").Send()
|
err := resp.Message("Le salon n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Channel not set (fallback)", err.Error())
|
utils.SendAlert("commands/config.go - Channel not set (fallback)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -290,7 +296,7 @@ func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate,
|
||||||
}
|
}
|
||||||
channel := salon.ChannelValue(s)
|
channel := salon.ChannelValue(s)
|
||||||
if channel.Type != discordgo.ChannelTypeGuildText {
|
if channel.Type != discordgo.ChannelTypeGuildText {
|
||||||
err := resp.SetMessage("Le salon n'est pas un salon textuel.").Send()
|
err := resp.Message("Le salon n'est pas un salon textuel.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Invalid channel type", err.Error())
|
utils.SendAlert("commands/config.go - Invalid channel type", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -309,21 +315,22 @@ func ConfigFallbackChannel(s *discordgo.Session, i *discordgo.InteractionCreate,
|
||||||
"channel_id",
|
"channel_id",
|
||||||
channel.ID,
|
channel.ID,
|
||||||
)
|
)
|
||||||
err = resp.SetMessage("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
err = resp.Message("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
||||||
} else {
|
} else {
|
||||||
err = resp.SetMessage("Salon enregistré.").Send()
|
err = resp.Message("Salon enregistré.").Send()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Channel saved message", err.Error())
|
utils.SendAlert("commands/config.go - Channel saved message", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
resp.IsEphemeral()
|
optMap := utils.GenerateOptionMapForSubcommand(i)
|
||||||
|
resp := utils.NewResponseBuilder(s, i).IsEphemeral()
|
||||||
// verify every args
|
// verify every args
|
||||||
days, ok := optMap["days"]
|
days, ok := optMap["days"]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := resp.SetMessage("Le nombre de jours n'a pas été renseigné.").Send()
|
err := resp.Message("Le nombre de jours n'a pas été renseigné.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Days not set (fallback)", err.Error())
|
utils.SendAlert("commands/config.go - Days not set (fallback)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -331,7 +338,7 @@ func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCrea
|
||||||
}
|
}
|
||||||
d := days.IntValue()
|
d := days.IntValue()
|
||||||
if d < 30 {
|
if d < 30 {
|
||||||
err := resp.SetMessage("Le nombre de jours est inférieur à 30.").Send()
|
err := resp.Message("Le nombre de jours est inférieur à 30.").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Days < 30 (fallback)", err.Error())
|
utils.SendAlert("commands/config.go - Days < 30 (fallback)", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -350,9 +357,9 @@ func ConfigPeriodBeforeReduce(s *discordgo.Session, i *discordgo.InteractionCrea
|
||||||
"days",
|
"days",
|
||||||
d,
|
d,
|
||||||
)
|
)
|
||||||
err = resp.SetMessage("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
err = resp.Message("Il y a eu une erreur lors de la modification de de la base de données.").Send()
|
||||||
} else {
|
} else {
|
||||||
err = resp.SetMessage("Nombre de jours enregistré.").Send()
|
err = resp.Message("Nombre de jours enregistré.").Send()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/config.go - Days saved message", err.Error())
|
utils.SendAlert("commands/config.go - Days saved message", err.Error())
|
||||||
|
|
|
@ -5,28 +5,30 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Credits(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func Credits(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
err := resp.AddEmbed(&discordgo.MessageEmbed{
|
resp := utils.NewResponseBuilder(s, i)
|
||||||
|
err := resp.Embeds([]*discordgo.MessageEmbed{
|
||||||
Type: discordgo.EmbedTypeRich,
|
{
|
||||||
Title: "Crédits",
|
Type: discordgo.EmbedTypeRich,
|
||||||
Description: "Auteur du bot : @anhgelus (https://github.com/anhgelus)\nLangage : Go 1.24\nLicence : AGPLv3",
|
Title: "Crédits",
|
||||||
Color: utils.Success,
|
Description: "Auteur du bot : @anhgelus (https://github.com/anhgelus)\nLangage : Go 1.24\nLicence : AGPLv3",
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Color: utils.Success,
|
||||||
{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
Name: "anhgelus/gokord",
|
{
|
||||||
Value: "v0.10.0 - MPL 2.0",
|
Name: "anhgelus/gokord",
|
||||||
Inline: true,
|
Value: "v0.6.3 - MPL 2.0",
|
||||||
},
|
Inline: true,
|
||||||
{
|
},
|
||||||
Name: "bwmarrin/discordgo",
|
{
|
||||||
Value: "v0.29.0 - BSD-3-Clause",
|
Name: "bwmarrin/discordgo",
|
||||||
Inline: true,
|
Value: "v0.28.1 - BSD-3-Clause",
|
||||||
},
|
Inline: true,
|
||||||
{
|
},
|
||||||
Name: "gorm",
|
{
|
||||||
Value: "v1.30.0 - MIT",
|
Name: "redis/go-redis/v9",
|
||||||
Inline: true,
|
Value: "v9.8.0 - BSD-2-Clause",
|
||||||
|
Inline: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).Send()
|
}).Send()
|
||||||
|
|
|
@ -8,15 +8,17 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Rank(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func Rank(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
optMap := utils.GenerateOptionMap(i)
|
||||||
c := user.GetCopaing(i.Member.User.ID, i.GuildID) // current user = member who used /rank
|
c := user.GetCopaing(i.Member.User.ID, i.GuildID) // current user = member who used /rank
|
||||||
msg := "Votre niveau"
|
msg := "Votre niveau"
|
||||||
m := i.Member
|
m := i.Member
|
||||||
var err error
|
var err error
|
||||||
|
resp := utils.NewResponseBuilder(s, i)
|
||||||
if v, ok := optMap["copaing"]; ok {
|
if v, ok := optMap["copaing"]; ok {
|
||||||
u := v.UserValue(s)
|
u := v.UserValue(s)
|
||||||
if u.Bot {
|
if u.Bot {
|
||||||
err = resp.SetMessage("Imagine si les bots avaient un niveau :rolling_eyes:").IsEphemeral().Send()
|
err = resp.Message("Imagine si les bots avaient un niveau :rolling_eyes:").IsEphemeral().Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/rank.go - Reply error user is a bot", err.Error())
|
utils.SendAlert("commands/rank.go - Reply error user is a bot", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -31,7 +33,7 @@ func Rank(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.Opt
|
||||||
"guild_id",
|
"guild_id",
|
||||||
i.GuildID,
|
i.GuildID,
|
||||||
)
|
)
|
||||||
err = resp.SetMessage("Erreur : impossible de récupérer le membre").IsEphemeral().Send()
|
err = resp.Message("Erreur : impossible de récupérer le membre").IsEphemeral().Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/rank.go - Reply error fetching guild member", err.Error())
|
utils.SendAlert("commands/rank.go - Reply error fetching guild member", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,7 @@ func Rank(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.Opt
|
||||||
"guild_id",
|
"guild_id",
|
||||||
i.GuildID,
|
i.GuildID,
|
||||||
)
|
)
|
||||||
err = resp.SetMessage("Erreur : impossible de récupérer l'XP").IsEphemeral().Send()
|
err = resp.Message("Erreur : impossible de récupérer l'XP").IsEphemeral().Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/rank.go - Reply error fetching xp", err.Error())
|
utils.SendAlert("commands/rank.go - Reply error fetching xp", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -58,7 +60,7 @@ func Rank(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.Opt
|
||||||
}
|
}
|
||||||
lvl := exp.Level(xp)
|
lvl := exp.Level(xp)
|
||||||
nxtLvlXP := exp.LevelXP(lvl + 1)
|
nxtLvlXP := exp.LevelXP(lvl + 1)
|
||||||
err = resp.SetMessage(fmt.Sprintf(
|
err = resp.Message(fmt.Sprintf(
|
||||||
"%s : **%d**\n> XP : %d\n> Prochain niveau dans %d XP",
|
"%s : **%d**\n> XP : %d\n> Prochain niveau dans %d XP",
|
||||||
msg,
|
msg,
|
||||||
lvl,
|
lvl,
|
||||||
|
|
|
@ -7,26 +7,27 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Reset(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func Reset(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
var copaings []*user.Copaing
|
var copaings []*user.Copaing
|
||||||
gokord.DB.Where("guild_id = ?", i.GuildID).Delete(&copaings)
|
gokord.DB.Where("guild_id = ?", i.GuildID).Delete(&copaings)
|
||||||
if err := resp.IsEphemeral().SetMessage("L'XP a été reset.").Send(); err != nil {
|
if err := utils.NewResponseBuilder(s, i).IsEphemeral().Message("L'XP a été reset.").Send(); err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Sending success (all)", err.Error())
|
utils.SendAlert("commands/reset.go - Sending success (all)", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
resp.IsEphemeral()
|
resp := utils.NewResponseBuilder(s, i).IsEphemeral()
|
||||||
|
optMap := utils.GenerateOptionMap(i)
|
||||||
v, ok := optMap["user"]
|
v, ok := optMap["user"]
|
||||||
if !ok {
|
if !ok {
|
||||||
if err := resp.SetMessage("Le user n'a pas été renseigné.").Send(); err != nil {
|
if err := resp.Message("Le user n'a pas été renseigné.").Send(); err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Copaing not set", err.Error())
|
utils.SendAlert("commands/reset.go - Copaing not set", err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m := v.UserValue(s)
|
m := v.UserValue(s)
|
||||||
if m.Bot {
|
if m.Bot {
|
||||||
if err := resp.SetMessage("Les bots n'ont pas de niveau :upside_down:").Send(); err != nil {
|
if err := resp.Message("Les bots n'ont pas de niveau :upside_down:").Send(); err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Copaing not set", err.Error())
|
utils.SendAlert("commands/reset.go - Copaing not set", err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -34,12 +35,12 @@ func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate, optMap util
|
||||||
err := user.GetCopaing(m.ID, i.GuildID).Delete()
|
err := user.GetCopaing(m.ID, i.GuildID).Delete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Copaing not deleted", err.Error(), "discord_id", m.ID, "guild_id", i.GuildID)
|
utils.SendAlert("commands/reset.go - Copaing not deleted", err.Error(), "discord_id", m.ID, "guild_id", i.GuildID)
|
||||||
err = resp.SetMessage("Erreur : impossible de reset l'utilisateur").Send()
|
err = resp.Message("Erreur : impossible de reset l'utilisateur").Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Error deleting", err.Error())
|
utils.SendAlert("commands/reset.go - Error deleting", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = resp.SetMessage("Le user bien été reset.").Send(); err != nil {
|
if err = resp.Message("Le user bien été reset.").Send(); err != nil {
|
||||||
utils.SendAlert("commands/reset.go - Sending success (user)", err.Error())
|
utils.SendAlert("commands/reset.go - Sending success (user)", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Top(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.OptionMap, resp *utils.ResponseBuilder) {
|
func Top(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
err := resp.IsDeferred().Send()
|
resp := utils.NewResponseBuilder(s, i).IsDeferred()
|
||||||
|
err := resp.Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.SendAlert("commands/top.go - Sending deferred", err.Error())
|
utils.SendAlert("commands/top.go - Sending deferred", err.Error())
|
||||||
return
|
return
|
||||||
|
@ -48,12 +49,9 @@ func Top(s *discordgo.Session, i *discordgo.InteractionCreate, optMap utils.Opti
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if cfg.DaysXPRemains > 30 {
|
if cfg.DaysXPRemains > 30 {
|
||||||
resp.AddEmbed(embeds[0]).
|
resp.Embeds(embeds)
|
||||||
AddEmbed(embeds[1]).
|
|
||||||
AddEmbed(embeds[2])
|
|
||||||
} else {
|
} else {
|
||||||
resp.AddEmbed(embeds[1]).
|
resp.Embeds(embeds[1:])
|
||||||
AddEmbed(embeds[2])
|
|
||||||
}
|
}
|
||||||
err = resp.Send()
|
err = resp.Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
22
docker-compose.yml
Normal file
22
docker-compose.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./config:/app/config
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
postgres:
|
||||||
|
image: postgres:alpine
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./data:/var/lib/postgresql/data
|
||||||
|
adminer:
|
||||||
|
image: docker.io/adminer
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
18
events.go
18
events.go
|
@ -31,7 +31,7 @@ func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
}
|
}
|
||||||
c := user.GetCopaing(m.Author.ID, m.GuildID)
|
c := user.GetCopaing(m.Author.ID, m.GuildID)
|
||||||
// add exp
|
// add exp
|
||||||
trimmed := exp.TrimMessage(strings.ToLower(m.Content))
|
trimmed := utils.TrimMessage(strings.ToLower(m.Content))
|
||||||
m.Member.User = m.Author
|
m.Member.User = m.Author
|
||||||
m.Member.GuildID = m.GuildID
|
m.Member.GuildID = m.GuildID
|
||||||
xp := min(exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed)), MaxXpPerMessage)
|
xp := min(exp.MessageXP(uint(len(trimmed)), exp.CalcDiversity(trimmed)), MaxXpPerMessage)
|
||||||
|
@ -51,12 +51,12 @@ func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cfg := config.GetGuildConfig(e.GuildID)
|
cfg := config.GetGuildConfig(e.GuildID)
|
||||||
if (e.BeforeUpdate == nil || cfg.IsDisabled(e.BeforeUpdate.ChannelID)) && e.ChannelID != "" {
|
if e.BeforeUpdate == nil && e.ChannelID != "" {
|
||||||
if cfg.IsDisabled(e.ChannelID) {
|
if cfg.IsDisabled(e.ChannelID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onConnection(s, e)
|
onConnection(s, e)
|
||||||
} else if e.BeforeUpdate != nil && (e.ChannelID == "" || cfg.IsDisabled(e.ChannelID)) {
|
} else if e.BeforeUpdate != nil && e.ChannelID == "" {
|
||||||
if cfg.IsDisabled(e.BeforeUpdate.ChannelID) {
|
if cfg.IsDisabled(e.BeforeUpdate.ChannelID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -64,21 +64,17 @@ func OnVoiceUpdate(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func genMapKey(guildID string, userID string) string {
|
|
||||||
return fmt.Sprintf("%s:%s", guildID, userID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func onConnection(_ *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
func onConnection(_ *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
utils.SendDebug("User connected", "username", e.Member.DisplayName())
|
utils.SendDebug("User connected", "username", e.Member.DisplayName())
|
||||||
connectedSince[genMapKey(e.GuildID, e.UserID)] = time.Now().Unix()
|
connectedSince[e.UserID] = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDisconnect(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
func onDisconnect(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
c := user.GetCopaing(e.UserID, e.GuildID)
|
c := user.GetCopaing(e.UserID, e.GuildID)
|
||||||
// check the validity of user
|
// check the validity of user
|
||||||
con, ok := connectedSince[genMapKey(e.GuildID, e.UserID)]
|
con := connectedSince[e.UserID]
|
||||||
if !ok || con == NotConnected {
|
if con == NotConnected {
|
||||||
utils.SendWarn(fmt.Sprintf(
|
utils.SendWarn(fmt.Sprintf(
|
||||||
"User %s diconnect from a vocal but was registered as not connected", e.Member.DisplayName(),
|
"User %s diconnect from a vocal but was registered as not connected", e.Member.DisplayName(),
|
||||||
))
|
))
|
||||||
|
@ -86,7 +82,7 @@ func onDisconnect(s *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
||||||
}
|
}
|
||||||
timeInVocal := now - con
|
timeInVocal := now - con
|
||||||
utils.SendDebug("User disconnected", "username", e.Member.DisplayName(), "time in vocal", timeInVocal)
|
utils.SendDebug("User disconnected", "username", e.Member.DisplayName(), "time in vocal", timeInVocal)
|
||||||
connectedSince[genMapKey(e.GuildID, e.UserID)] = NotConnected
|
connectedSince[e.UserID] = NotConnected
|
||||||
// add exp
|
// add exp
|
||||||
if timeInVocal < 0 {
|
if timeInVocal < 0 {
|
||||||
utils.SendAlert(
|
utils.SendAlert(
|
||||||
|
|
|
@ -4,9 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,24 +48,12 @@ func LevelXP(level uint) uint {
|
||||||
|
|
||||||
// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
|
// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
|
||||||
func TimeStampNDaysBefore(n uint) string {
|
func TimeStampNDaysBefore(n uint) string {
|
||||||
var unix time.Time
|
var y, d int
|
||||||
|
var m time.Month
|
||||||
if gokord.Debug {
|
if gokord.Debug {
|
||||||
unix = time.Unix(time.Now().Unix()-int64(n), 0) // reduce time for debug
|
y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
|
||||||
} else {
|
} else {
|
||||||
unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0)
|
y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
|
||||||
}
|
}
|
||||||
unix = unix.UTC()
|
return fmt.Sprintf("%d-%d-%d", y, m, d)
|
||||||
return fmt.Sprintf("%d-%d-%d %d:%d:%d UTC", unix.Year(), unix.Month(), unix.Day(), unix.Hour(), unix.Minute(), unix.Second())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TrimMessage(s string) string {
|
|
||||||
not := regexp.MustCompile("[^a-zA-Z0-9éèêàùûç,;:!.?]")
|
|
||||||
ping := regexp.MustCompile("<(@&?|#)[0-9]{18}>")
|
|
||||||
link := regexp.MustCompile("https?://[a-zA-Z0-9.]+[.][a-z]+.*")
|
|
||||||
|
|
||||||
s = ping.ReplaceAllLiteralString(s, "")
|
|
||||||
s = link.ReplaceAllLiteralString(s, "")
|
|
||||||
s = not.ReplaceAllLiteralString(s, "")
|
|
||||||
|
|
||||||
return strings.Trim(s, " ")
|
|
||||||
}
|
}
|
||||||
|
|
9
go.mod
9
go.mod
|
@ -3,11 +3,11 @@ module github.com/anhgelus/les-copaings-bot
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/anhgelus/gokord v0.10.0
|
github.com/anhgelus/gokord v0.7.0
|
||||||
github.com/bwmarrin/discordgo v0.29.0
|
github.com/bwmarrin/discordgo v0.28.1
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4
|
github.com/pelletier/go-toml/v2 v2.2.4
|
||||||
gorm.io/driver/postgres v1.5.11
|
gorm.io/driver/postgres v1.5.11
|
||||||
gorm.io/gorm v1.30.0
|
gorm.io/gorm v1.26.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -20,8 +20,7 @@ require (
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/joho/godotenv v1.5.1 // indirect
|
github.com/redis/go-redis/v9 v9.8.0 // indirect
|
||||||
github.com/redis/go-redis/v9 v9.9.0 // indirect
|
|
||||||
golang.org/x/crypto v0.38.0 // indirect
|
golang.org/x/crypto v0.38.0 // indirect
|
||||||
golang.org/x/sync v0.14.0 // indirect
|
golang.org/x/sync v0.14.0 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
golang.org/x/sys v0.33.0 // indirect
|
||||||
|
|
12
go.sum
12
go.sum
|
@ -1,17 +1,11 @@
|
||||||
github.com/anhgelus/gokord v0.7.0 h1:G9GrxD3/xEreXsiz3etKxbeHsNHrwT5I/VEKSWpyrj4=
|
github.com/anhgelus/gokord v0.7.0 h1:G9GrxD3/xEreXsiz3etKxbeHsNHrwT5I/VEKSWpyrj4=
|
||||||
github.com/anhgelus/gokord v0.7.0/go.mod h1:SfGKyMMGjNS9F9ehiEb5Cc58P+uoDdLDGGYqXSiMCus=
|
github.com/anhgelus/gokord v0.7.0/go.mod h1:SfGKyMMGjNS9F9ehiEb5Cc58P+uoDdLDGGYqXSiMCus=
|
||||||
github.com/anhgelus/gokord v0.9.0 h1:vz7jHZ6papdt/xehe+nx4DxOLquPO6QukW8UzH81bGY=
|
|
||||||
github.com/anhgelus/gokord v0.9.0/go.mod h1:NSepHjTV61LUnuyGgHxEhZNMnWREErGFyOtRYPgdx/E=
|
|
||||||
github.com/anhgelus/gokord v0.10.0 h1:FaaMWntaezmSCvarcSMjfWr5OXVVwwzlDMnNX8gXaWE=
|
|
||||||
github.com/anhgelus/gokord v0.10.0/go.mod h1:NSepHjTV61LUnuyGgHxEhZNMnWREErGFyOtRYPgdx/E=
|
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
|
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
|
||||||
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||||
github.com/bwmarrin/discordgo v0.29.0 h1:FmWeXFaKUwrcL3Cx65c20bTRW+vOb6k8AnaP+EgjDno=
|
|
||||||
github.com/bwmarrin/discordgo v0.29.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -34,16 +28,12 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
|
||||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI=
|
github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI=
|
||||||
github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||||
github.com/redis/go-redis/v9 v9.9.0 h1:URbPQ4xVQSQhZ27WMQVmZSo3uT3pL+4IdHVcYq2nVfM=
|
|
||||||
github.com/redis/go-redis/v9 v9.9.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
@ -71,5 +61,3 @@ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
|
||||||
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
||||||
gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw=
|
gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw=
|
||||||
gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
||||||
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
|
|
||||||
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
|
||||||
|
|
25
main.go
25
main.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"github.com/anhgelus/gokord/utils"
|
"github.com/anhgelus/gokord/utils"
|
||||||
|
@ -10,8 +9,6 @@ import (
|
||||||
"github.com/anhgelus/les-copaings-bot/config"
|
"github.com/anhgelus/les-copaings-bot/config"
|
||||||
"github.com/anhgelus/les-copaings-bot/user"
|
"github.com/anhgelus/les-copaings-bot/user"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,18 +19,14 @@ var (
|
||||||
Version = gokord.Version{
|
Version = gokord.Version{
|
||||||
Major: 3,
|
Major: 3,
|
||||||
Minor: 1,
|
Minor: 1,
|
||||||
Patch: 3,
|
Patch: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
stopPeriodicReducer chan<- interface{}
|
stopPeriodicReducer chan<- interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := godotenv.Load()
|
flag.StringVar(&token, "token", "", "token of the bot")
|
||||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
||||||
utils.SendWarn("Error while loading .env file", "error", err.Error())
|
|
||||||
}
|
|
||||||
flag.StringVar(&token, "token", os.Getenv("TOKEN"), "token of the bot")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -178,9 +171,7 @@ func main() {
|
||||||
AfterInit: afterInit,
|
AfterInit: afterInit,
|
||||||
Innovations: innovations,
|
Innovations: innovations,
|
||||||
Version: &Version,
|
Version: &Version,
|
||||||
Intents: discordgo.IntentsAllWithoutPrivileged |
|
Intents: discordgo.IntentsAllWithoutPrivileged | discordgo.IntentsGuildMessages | discordgo.IntentGuildMembers,
|
||||||
discordgo.IntentsMessageContent |
|
|
||||||
discordgo.IntentGuildMembers,
|
|
||||||
}
|
}
|
||||||
bot.Start()
|
bot.Start()
|
||||||
|
|
||||||
|
@ -195,15 +186,7 @@ func afterInit(dg *discordgo.Session) {
|
||||||
dg.AddHandler(OnVoiceUpdate)
|
dg.AddHandler(OnVoiceUpdate)
|
||||||
dg.AddHandler(OnLeave)
|
dg.AddHandler(OnLeave)
|
||||||
|
|
||||||
d := 24 * time.Hour
|
stopPeriodicReducer = utils.NewTimer(24*time.Hour, func(stop chan<- interface{}) {
|
||||||
if gokord.Debug {
|
|
||||||
d = 24 * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
user.PeriodicReducer(dg)
|
|
||||||
|
|
||||||
stopPeriodicReducer = utils.NewTimer(d, func(stop chan<- interface{}) {
|
|
||||||
utils.SendDebug("Periodic reducer")
|
|
||||||
user.PeriodicReducer(dg)
|
user.PeriodicReducer(dg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,14 +86,14 @@ func PeriodicReducer(dg *discordgo.Session) {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
cfg := config.GetGuildConfig(g.ID)
|
cfg := config.GetGuildConfig(g.ID)
|
||||||
res := gokord.DB.
|
err := gokord.DB.
|
||||||
Model(&CopaingXP{}).
|
Model(&CopaingXP{}).
|
||||||
Where("guild_id = ? and created_at < ?", g.ID, exp.TimeStampNDaysBefore(cfg.DaysXPRemains)).
|
Where("guild_id = ? and created_at < ?", g.ID, exp.TimeStampNDaysBefore(cfg.DaysXPRemains)).
|
||||||
Delete(&CopaingXP{})
|
Delete(&CopaingXP{}).
|
||||||
if res.Error != nil {
|
Error
|
||||||
utils.SendAlert("user/level.go - Removing old XP", res.Error.Error(), "guild_id", g.ID)
|
if err != nil {
|
||||||
|
utils.SendAlert("user/level.go - Removing old XP", err.Error(), "guild_id", g.ID)
|
||||||
}
|
}
|
||||||
utils.SendDebug("Guild cleaned", "guild", g.Name, "rows affected", res.RowsAffected)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue