48 lines
1003 B
Go
48 lines
1003 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
if m.Author.Bot {
|
|
return
|
|
}
|
|
go incrementXP(s, m.Author.ID)
|
|
|
|
if m.Content == "pgqlevel" {
|
|
handleXPRequest(s, m)
|
|
}
|
|
if m.Content == "pgqshard" {
|
|
handleShardRequest(s, m)
|
|
}
|
|
}
|
|
|
|
func handleXPRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
level, xp := getLevelAndXP(s, m.Author.ID)
|
|
levelUpRequirement := levelUpRequirementCache[level-1]
|
|
if level > 1 {
|
|
levelUpRequirement -= levelUpRequirementCache[level-2]
|
|
}
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
fmt.Sprintf(
|
|
"<@%s> is now level %d. (%d XP/%d XP) [%.1f%%]",
|
|
m.Author.ID, level, xp, levelUpRequirement, float64(xp)/float64(levelUpRequirement)*100,
|
|
),
|
|
)
|
|
}
|
|
|
|
func handleShardRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
shard := getShard(s, m.Author.ID)
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
fmt.Sprintf(
|
|
"<@%s> has %d shards.",
|
|
m.Author.ID, shard,
|
|
),
|
|
)
|
|
}
|