50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
const generalChannelID = "645550570001924098"
|
|
|
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
if m.Author.Bot {
|
|
return
|
|
}
|
|
go incrementXP(s, m.Author.ID, m.ChannelID == generalChannelID)
|
|
|
|
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,
|
|
),
|
|
)
|
|
}
|