121 lines
3.3 KiB
Go
121 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"time"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
const generalChannelID = "645550570001924098"
|
|
const emojiCheck = "✅"
|
|
const prestigeRequirement = 90000
|
|
|
|
var prestigeList = make(map[string]string)
|
|
|
|
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)
|
|
}
|
|
if m.Content == "pgqprestige" {
|
|
handlePrestigeRequest(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,
|
|
),
|
|
)
|
|
}
|
|
|
|
func handlePrestigeRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
currentPrestigeLevel := getPrestige(s, m.Author.ID)
|
|
xp := getXP(s, m.Author.ID)
|
|
newPrestigeLevel := xp/prestigeRequirement + 1
|
|
|
|
if xp < levelUpRequirementCache[3] && currentPrestigeLevel == 1 {
|
|
s.ChannelMessageSend(m.ChannelID, "**PRESTIGE > **Prestige is only unlocked after level 5!")
|
|
return
|
|
}
|
|
|
|
var lowerLevelWarning string
|
|
if newPrestigeLevel <= currentPrestigeLevel {
|
|
lowerLevelWarning = "**WARNING: Your new prestige multiplier is NOT higher than your current prestige multiplier."
|
|
}
|
|
nearestPowerOfTen := math.Pow10(int(math.Floor(math.Log10(float64(newPrestigeLevel)))))
|
|
nextNearestLogicalPrestige := int((math.Floor(float64(newPrestigeLevel)/nearestPowerOfTen) + 1) * nearestPowerOfTen)
|
|
|
|
msg, err := s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
fmt.Sprintf(
|
|
"<@%s>, here's your prestige multiplier:\n**Now: **__%dx__\n**New: **__%dx__\n**Next: **__%dx__ [%.1f%%]\n%s\n"+
|
|
"React with :white_check_mark: to proceed with prestiging.",
|
|
m.Author.ID,
|
|
currentPrestigeLevel,
|
|
newPrestigeLevel,
|
|
nextNearestLogicalPrestige, float64(xp)/float64(prestigeRequirement*(nextNearestLogicalPrestige-1))*100,
|
|
lowerLevelWarning,
|
|
),
|
|
)
|
|
if err != nil {
|
|
logError(s, "handlePrestigeRequest", "send", err)
|
|
return
|
|
}
|
|
prestigeList[msg.ID] = m.Author.ID
|
|
err = s.MessageReactionAdd(msg.ChannelID, msg.ID, emojiCheck)
|
|
if err != nil {
|
|
logError(s, "handlePrestigeRequest", "addReaction", err)
|
|
return
|
|
}
|
|
go func() {
|
|
time.Sleep(15 * time.Second)
|
|
err = s.MessageReactionsRemoveAll(msg.ChannelID, msg.ID)
|
|
if err != nil {
|
|
logError(s, "handlePrestigeRequest", "removeReaction", err)
|
|
}
|
|
}()
|
|
}
|
|
|
|
func checkPrestigeReact(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
|
|
if prestigeList[m.MessageID] != m.UserID {
|
|
return
|
|
}
|
|
if m.Emoji.Name != emojiCheck {
|
|
return
|
|
}
|
|
xp := getXP(s, m.UserID)
|
|
newPrestigeLevel := xp/prestigeRequirement + 1
|
|
go cleanUpRole(s, m.UserID)
|
|
setPrestige(s, m.UserID, newPrestigeLevel)
|
|
s.ChannelMessageSend(m.ChannelID, "**PRESTIGE > ** <@%s>, you have prestiged!")
|
|
}
|