feat(xp): rank command
This commit is contained in:
parent
1078cf3deb
commit
3e06848f72
2 changed files with 56 additions and 12 deletions
|
@ -1,7 +1,50 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import "github.com/bwmarrin/discordgo"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/anhgelus/gokord/utils"
|
||||||
|
"github.com/anhgelus/les-copaings-bot/xp"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
func Rank(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func Rank(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
optMap := utils.GenerateOptionMap(i)
|
||||||
|
c := xp.Copaing{DiscordID: i.Member.User.ID, GuildID: i.GuildID}
|
||||||
|
msg := "Votre niveau"
|
||||||
|
m := i.Member
|
||||||
|
var err error
|
||||||
|
resp := utils.ResponseBuilder{C: s, I: i}
|
||||||
|
if v, ok := optMap["copaing"]; ok {
|
||||||
|
u := v.UserValue(s)
|
||||||
|
if u.Bot {
|
||||||
|
err = resp.Message("Imagine si les bots avaient un niveau :rolling_eyes:").IsEphemeral().Send()
|
||||||
|
if err != nil {
|
||||||
|
utils.SendAlert("rank.go - Reply error user is a bot", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m, err = s.GuildMember(i.GuildID, u.ID)
|
||||||
|
if err != nil {
|
||||||
|
utils.SendAlert("rank.go - Fetching guild member", err.Error())
|
||||||
|
err = resp.Message("Erreur : impossible de récupérer le membre").IsEphemeral().Send()
|
||||||
|
if err != nil {
|
||||||
|
utils.SendAlert("rank.go - Reply error fetching guild member", err.Error())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.DiscordID = u.ID
|
||||||
|
msg = fmt.Sprintf("Le niveau de %s", m.DisplayName())
|
||||||
|
}
|
||||||
|
c.Load()
|
||||||
|
lvl := xp.Level(c.XP)
|
||||||
|
nxtLvl := xp.XPForLevel(lvl + 1)
|
||||||
|
err = resp.Message(fmt.Sprintf(
|
||||||
|
"%s : **%d**\n> XP : %d\n> Prochain niveau dans %d XP",
|
||||||
|
msg,
|
||||||
|
lvl,
|
||||||
|
c.XP,
|
||||||
|
nxtLvl-lvl,
|
||||||
|
)).Send()
|
||||||
|
if err != nil {
|
||||||
|
utils.SendAlert("rank.go - Sending rank", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
21
main.go
21
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
|
"github.com/anhgelus/les-copaings-bot/commands"
|
||||||
"github.com/anhgelus/les-copaings-bot/xp"
|
"github.com/anhgelus/les-copaings-bot/xp"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
@ -25,15 +26,15 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//rankCmd := gokord.NewCommand("rank", "Affiche le niveau d'une personne").
|
rankCmd := gokord.NewCommand("rank", "Affiche le niveau d'une personne").
|
||||||
// HasOption().
|
HasOption().
|
||||||
// AddOption(gokord.NewOption(
|
AddOption(gokord.NewOption(
|
||||||
// discordgo.ApplicationCommandOptionUser,
|
discordgo.ApplicationCommandOptionUser,
|
||||||
// "copaing",
|
"copaing",
|
||||||
// "Le niveau du Copaing que vous souhaitez obtenir",
|
"Le niveau du Copaing que vous souhaitez obtenir",
|
||||||
// )).
|
)).
|
||||||
// SetHandler(commands.Rank).
|
SetHandler(commands.Rank).
|
||||||
// ToCmd()
|
ToCmd()
|
||||||
|
|
||||||
bot := gokord.Bot{
|
bot := gokord.Bot{
|
||||||
Token: token,
|
Token: token,
|
||||||
|
@ -45,7 +46,7 @@ func main() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Commands: []*gokord.Cmd{
|
Commands: []*gokord.Cmd{
|
||||||
//rankCmd,
|
rankCmd,
|
||||||
},
|
},
|
||||||
AfterInit: afterInit,
|
AfterInit: afterInit,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue