2019-11-17 14:47:34 +07:00
|
|
|
package main
|
|
|
|
|
2019-11-18 04:25:34 +07:00
|
|
|
import (
|
2019-11-19 12:25:08 +07:00
|
|
|
"crypto/rand"
|
2019-11-18 04:25:34 +07:00
|
|
|
"fmt"
|
2019-11-19 06:59:32 +07:00
|
|
|
"math"
|
2019-11-20 08:34:14 +07:00
|
|
|
"strings"
|
2019-11-19 06:59:32 +07:00
|
|
|
"time"
|
2019-11-18 04:25:34 +07:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
2019-11-17 14:47:34 +07:00
|
|
|
|
2019-11-18 15:23:40 +07:00
|
|
|
const generalChannelID = "645550570001924098"
|
2019-11-19 06:59:32 +07:00
|
|
|
const emojiCheck = "✅"
|
2019-11-19 08:08:47 +07:00
|
|
|
const prestigeRequirement = 90000
|
2019-11-19 06:59:32 +07:00
|
|
|
|
|
|
|
var prestigeList = make(map[string]string)
|
2019-11-18 15:23:40 +07:00
|
|
|
|
2019-11-17 14:47:34 +07:00
|
|
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
if m.Author.Bot {
|
|
|
|
return
|
|
|
|
}
|
2019-11-18 15:23:40 +07:00
|
|
|
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-19 06:59:32 +07:00
|
|
|
if m.Content == "pgqprestige" {
|
|
|
|
handlePrestigeRequest(s, m)
|
|
|
|
}
|
2019-11-20 08:34:14 +07:00
|
|
|
if strings.HasPrefix(m.Content, "pgqstar ") {
|
|
|
|
handleStarRequest(s, m)
|
|
|
|
}
|
2019-11-18 04:25:34 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func handleXPRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
2019-11-19 12:25:08 +07:00
|
|
|
level, rawXP := getLevelAndXP(s, m.Author.ID)
|
|
|
|
randomSource := make([]byte, 1)
|
|
|
|
rand.Read(randomSource)
|
|
|
|
xp := rawXP - (rawXP % 100) + ((int(randomSource[0]) + 128) % 100)
|
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,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2019-11-19 06:59:32 +07:00
|
|
|
|
|
|
|
func handlePrestigeRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
currentPrestigeLevel := getPrestige(s, m.Author.ID)
|
|
|
|
xp := getXP(s, m.Author.ID)
|
2019-11-19 08:08:47 +07:00
|
|
|
newPrestigeLevel := xp/prestigeRequirement + 1
|
2019-11-19 06:59:32 +07:00
|
|
|
|
2019-11-19 08:08:47 +07:00
|
|
|
if xp < levelUpRequirementCache[3] && currentPrestigeLevel == 1 {
|
2019-11-19 06:59:32 +07:00
|
|
|
s.ChannelMessageSend(m.ChannelID, "**PRESTIGE > **Prestige is only unlocked after level 5!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var lowerLevelWarning string
|
|
|
|
if newPrestigeLevel <= currentPrestigeLevel {
|
2019-11-19 08:20:05 +07:00
|
|
|
lowerLevelWarning = "**WARNING:** *Your new prestige multiplier is __NOT__ higher than your current prestige multiplier.*"
|
2019-11-19 06:59:32 +07:00
|
|
|
}
|
|
|
|
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,
|
2019-11-19 08:08:47 +07:00
|
|
|
nextNearestLogicalPrestige, float64(xp)/float64(prestigeRequirement*(nextNearestLogicalPrestige-1))*100,
|
2019-11-19 06:59:32 +07:00
|
|
|
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
|
|
|
|
}
|
2019-11-19 08:12:16 +07:00
|
|
|
if m.Emoji.Name != emojiCheck {
|
|
|
|
return
|
|
|
|
}
|
2019-11-19 06:59:32 +07:00
|
|
|
xp := getXP(s, m.UserID)
|
2019-11-19 08:08:47 +07:00
|
|
|
newPrestigeLevel := xp/prestigeRequirement + 1
|
2019-11-19 07:11:32 +07:00
|
|
|
go cleanUpRole(s, m.UserID)
|
2019-11-19 06:59:32 +07:00
|
|
|
setPrestige(s, m.UserID, newPrestigeLevel)
|
2019-11-19 08:20:05 +07:00
|
|
|
s.ChannelMessageSend(m.ChannelID,
|
|
|
|
fmt.Sprintf(
|
|
|
|
"**PRESTIGE > ** <@%s>, you have prestiged!", m.UserID,
|
|
|
|
),
|
|
|
|
)
|
2019-11-19 06:59:32 +07:00
|
|
|
}
|
2019-11-20 08:34:14 +07:00
|
|
|
|
|
|
|
func handleStarRequest(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
commandSplit := strings.SplitN(m.Content, " ", 2)
|
|
|
|
if len(commandSplit) == 1 {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
linkSplit := strings.SplitN(m.Content, "/", 7)
|
|
|
|
if len(linkSplit) < 7 {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if linkSplit[0] != "https" && linkSplit[0] != "http" {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if linkSplit[2] != "discordapp.com" && !strings.HasSuffix(linkSplit[2], ".discordapp.com") {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if linkSplit[3] != "channels" {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if linkSplit[4] != m.GuildID {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := s.MessageReactionAdd(linkSplit[5], linkSplit[6], starEmoji)
|
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "**STAR > **It doesn't seem like you've sent a valid message link!")
|
|
|
|
}
|
|
|
|
}
|