diff --git a/commands/commands.go b/commands/commands.go index 5bfcaea..618980c 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -19,16 +19,23 @@ type command struct { var commands = []command{ command{"autorole", " ", 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 diff --git a/commands/level.go b/commands/level.go new file mode 100644 index 0000000..895abfe --- /dev/null +++ b/commands/level.go @@ -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) +}