This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/messageCreate.go

50 lines
1.1 KiB
Go

2019-11-17 14:47:34 +07:00
package main
2019-11-18 04:25:34 +07:00
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
2019-11-17 14:47:34 +07:00
const generalChannelID = "645550570001924098"
2019-11-17 14:47:34 +07:00
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot {
return
}
go incrementXP(s, m.Author.ID, m.ChannelID == generalChannelID)
2019-11-17 14:47:34 +07:00
2019-11-18 14:38:03 +07:00
if m.Content == "pgqlevel" {
2019-11-18 04:25:34 +07:00
handleXPRequest(s, m)
}
2019-11-18 14:38:03 +07:00
if m.Content == "pgqshard" {
handleShardRequest(s, m)
}
2019-11-18 04:25:34 +07:00
}
func handleXPRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
level, xp := getLevelAndXP(s, m.Author.ID)
2019-11-18 06:42:20 +07:00
levelUpRequirement := levelUpRequirementCache[level-1]
if level > 1 {
levelUpRequirement -= levelUpRequirementCache[level-2]
}
2019-11-18 04:25:34 +07:00
s.ChannelMessageSend(
m.ChannelID,
2019-11-18 06:42:20 +07:00
fmt.Sprintf(
2019-11-18 06:43:33 +07:00
"<@%s> is now level %d. (%d XP/%d XP) [%.1f%%]",
m.Author.ID, level, xp, levelUpRequirement, float64(xp)/float64(levelUpRequirement)*100,
2019-11-18 06:42:20 +07:00
),
2019-11-18 04:25:34 +07:00
)
2019-11-17 14:47:34 +07:00
}
2019-11-18 14:38:03 +07:00
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,
),
)
}