feat: Add level command

master
Luther Wen Xu 2020-05-30 20:47:10 +07:00
parent 35115fd0d1
commit 46aad07121
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 57 additions and 2 deletions

@ -19,16 +19,23 @@ type command struct {
var commands = []command{
command{"autorole", "<message link> <emoji> <role to assign>", handleAutorole, 3, true},
command{"recalclevel", "", handleRecalculateLevel, 0, false},
command{"level", "", handleLevel, 0, false},
}
func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot {
return
}
if !strings.HasPrefix(m.Content, "milen ") {
split := strings.Split(m.Content, " ")
prefix := strings.ToLower(split[0])
if prefix != "milen," && prefix != "milen" {
return
}
if len(split) == 1 {
util.SendFailEmbed(dg, m.ChannelID, ":(", "Did you just call me out for no reason? Please specify what you want me to do.")
return
}
split := strings.Split(m.Content, " ")
for _, v := range commands {
if split[1] != v.Name {
continue

@ -0,0 +1,48 @@
package commands
import (
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/db"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
func handleLevel(dg *discordgo.Session, m *discordgo.MessageCreate, arguments []string) {
target := m.Author.ID
switch len(m.Mentions) {
case 0:
case 1:
target = m.Mentions[0].ID
default:
util.SendFailEmbed(dg, m.ChannelID, "Invalid Arguments", "You can only check the level of one person at a time.")
return
}
xp := db.GetXP(target)
member, err := util.GetMember(dg, m.GuildID, target)
if err != nil {
util.ReportError(dg, err)
util.SendFailEmbed(dg, m.ChannelID, "Error", "Cannot find requested member.")
return
}
embed := &discordgo.MessageEmbed{
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "Active Time",
Value: util.FormatPlural(xp, "second", "seconds") + " (or " + util.FormatTime(xp) + ")",
},
&discordgo.MessageEmbedField{
Name: "Internal User ID",
Value: target,
},
},
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: util.GetAvatar(dg, member.User),
},
}
if member.Nick != "" {
embed.Title = "Level for " + member.Nick + " (" + member.User.Username + "#" + member.User.Discriminator + ")"
} else {
embed.Title = "Level for " + member.User.Username + "#" + member.User.Discriminator
}
util.SendEmbed(dg, m.ChannelID, embed)
}