style(files): reorganize everything
This commit is contained in:
parent
0a445aa1c7
commit
c408afc879
13 changed files with 422 additions and 389 deletions
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/anhgelus/gokord"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
"github.com/anhgelus/les-copaings-bot/config"
|
||||
"github.com/anhgelus/les-copaings-bot/xp"
|
||||
"github.com/anhgelus/les-copaings-bot/exp"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"strings"
|
||||
)
|
||||
|
@ -17,9 +17,9 @@ func ConfigShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
l := len(cfg.XpRoles) - 1
|
||||
for i, r := range cfg.XpRoles {
|
||||
if i == l {
|
||||
roles += fmt.Sprintf("> Niveau %d - <@&%s>", xp.Level(r.XP), r.RoleID)
|
||||
roles += fmt.Sprintf("> Niveau %d - <@&%s>", exp.Level(r.XP), r.RoleID)
|
||||
} else {
|
||||
roles += fmt.Sprintf("> Niveau %d - <@&%s>\n", xp.Level(r.XP), r.RoleID)
|
||||
roles += fmt.Sprintf("> Niveau %d - <@&%s>\n", exp.Level(r.XP), r.RoleID)
|
||||
}
|
||||
}
|
||||
if len(roles) == 0 {
|
||||
|
@ -98,7 +98,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
}
|
||||
return
|
||||
}
|
||||
exp := xp.XPForLevel(uint(level))
|
||||
exp := exp.LevelXP(uint(level))
|
||||
r, ok := optMap["role"]
|
||||
if !ok {
|
||||
err := resp.Message("Le rôle n'a pas été renseigné.").Send()
|
||||
|
|
|
@ -3,19 +3,20 @@ package commands
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
"github.com/anhgelus/les-copaings-bot/xp"
|
||||
"github.com/anhgelus/les-copaings-bot/exp"
|
||||
"github.com/anhgelus/les-copaings-bot/user"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func Rank(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
optMap := utils.GenerateOptionMap(i)
|
||||
c := xp.GetCopaing(i.Member.User.ID, i.GuildID) // current copaing = member who used /rank
|
||||
xp.LastEventUpdate(s, c) // update xp and reset last event
|
||||
c := user.GetCopaing(i.Member.User.ID, i.GuildID) // current user = member who used /rank
|
||||
user.LastEventUpdate(s, c) // update exp and reset last event
|
||||
msg := "Votre niveau"
|
||||
m := i.Member
|
||||
var err error
|
||||
resp := utils.ResponseBuilder{C: s, I: i}
|
||||
if v, ok := optMap["copaing"]; ok {
|
||||
if v, ok := optMap["user"]; ok {
|
||||
u := v.UserValue(s)
|
||||
if u.Bot {
|
||||
err = resp.Message("Imagine si les bots avaient un niveau :rolling_eyes:").IsEphemeral().Send()
|
||||
|
@ -39,12 +40,12 @@ func Rank(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
}
|
||||
return
|
||||
}
|
||||
c = xp.GetCopaing(u.ID, i.GuildID) // current copaing = member targeted by member who wrote /rank
|
||||
xp.XPUpdate(s, c) // update xp without resetting event
|
||||
c = user.GetCopaing(u.ID, i.GuildID) // current user = member targeted by member who wrote /rank
|
||||
user.UpdateXP(s, c) // update exp without resetting event
|
||||
msg = fmt.Sprintf("Le niveau de %s", m.DisplayName())
|
||||
}
|
||||
lvl := xp.Level(c.XP)
|
||||
nxtLvlXP := xp.XPForLevel(lvl + 1)
|
||||
lvl := exp.Level(c.XP)
|
||||
nxtLvlXP := exp.LevelXP(lvl + 1)
|
||||
err = resp.Message(fmt.Sprintf(
|
||||
"%s : **%d**\n> XP : %d\n> Prochain niveau dans %d XP",
|
||||
msg,
|
||||
|
|
|
@ -3,12 +3,12 @@ package commands
|
|||
import (
|
||||
"github.com/anhgelus/gokord"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
"github.com/anhgelus/les-copaings-bot/xp"
|
||||
"github.com/anhgelus/les-copaings-bot/user"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func Reset(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
var copaings []*xp.Copaing
|
||||
var copaings []*user.Copaing
|
||||
gokord.DB.Where("guild_id = ?", i.GuildID).Delete(&copaings)
|
||||
resp := utils.ResponseBuilder{C: s, I: i}
|
||||
if err := resp.IsEphemeral().Message("L'XP a été reset.").Send(); err != nil {
|
||||
|
@ -20,9 +20,9 @@ func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
resp := utils.ResponseBuilder{C: s, I: i}
|
||||
resp.IsEphemeral()
|
||||
optMap := utils.GenerateOptionMap(i)
|
||||
v, ok := optMap["copaing"]
|
||||
v, ok := optMap["user"]
|
||||
if !ok {
|
||||
if err := resp.Message("Le copaing 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())
|
||||
}
|
||||
return
|
||||
|
@ -34,8 +34,8 @@ func ResetUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
}
|
||||
return
|
||||
}
|
||||
xp.GetCopaing(m.ID, i.GuildID).Reset()
|
||||
if err := resp.Message("Le copaing bien été reset.").Send(); err != nil {
|
||||
utils.SendAlert("commands/reset.go - Sending success (copaing)", err.Error())
|
||||
user.GetCopaing(m.ID, i.GuildID).Reset()
|
||||
if err := resp.Message("Le user bien été reset.").Send(); err != nil {
|
||||
utils.SendAlert("commands/reset.go - Sending success (user)", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import (
|
|||
"fmt"
|
||||
"github.com/anhgelus/gokord"
|
||||
"github.com/anhgelus/gokord/utils"
|
||||
"github.com/anhgelus/les-copaings-bot/xp"
|
||||
"github.com/anhgelus/les-copaings-bot/exp"
|
||||
"github.com/anhgelus/les-copaings-bot/user"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func Top(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
xp.LastEventUpdate(s, xp.GetCopaing(i.Member.User.ID, i.GuildID))
|
||||
user.LastEventUpdate(s, user.GetCopaing(i.Member.User.ID, i.GuildID))
|
||||
resp := utils.ResponseBuilder{C: s, I: i}
|
||||
err := resp.IsDeferred().Send()
|
||||
if err != nil {
|
||||
|
@ -18,14 +19,14 @@ func Top(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
}
|
||||
resp.NotDeferred().IsEdit()
|
||||
go func() {
|
||||
var tops []xp.Copaing
|
||||
gokord.DB.Where("guild_id = ?", i.GuildID).Limit(10).Order("xp desc").Find(&tops)
|
||||
var tops []user.Copaing
|
||||
gokord.DB.Where("guild_id = ?", i.GuildID).Limit(10).Order("exp desc").Find(&tops)
|
||||
msg := ""
|
||||
for i, c := range tops {
|
||||
if i == 9 {
|
||||
msg += fmt.Sprintf("%d. **<@%s>** - niveau %d", i+1, c.DiscordID, xp.Level(c.XP))
|
||||
msg += fmt.Sprintf("%d. **<@%s>** - niveau %d", i+1, c.DiscordID, exp.Level(c.XP))
|
||||
} else {
|
||||
msg += fmt.Sprintf("%d. **<@%s>** - niveau %d\n", i+1, c.DiscordID, xp.Level(c.XP))
|
||||
msg += fmt.Sprintf("%d. **<@%s>** - niveau %d\n", i+1, c.DiscordID, exp.Level(c.XP))
|
||||
}
|
||||
}
|
||||
err = resp.Embeds([]*discordgo.MessageEmbed{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue