Milen/commands/migrate.go

50 lines
1.3 KiB
Go

package commands
import (
"fmt"
"math/rand"
"time"
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/level"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
func handleRecalculateLevel(dg *discordgo.Session, m *discordgo.MessageCreate, arguments []string) {
if len(arguments) == 0 {
util.SendFailEmbed(
dg, m.ChannelID, "Bot Owner Access Required",
"⚠️ This action might take a while and disable level calculation system.\nTo confirm, check console for launch code.",
)
fmt.Println("Level launch requested: " + calculationCode)
return
}
if arguments[0] != calculationCode {
util.SendFailEmbed(
dg, m.ChannelID, "Incorrect Launch Code", "You entered an incorrect code.",
)
}
util.SendSuccessEmbed(dg, m.ChannelID, "Level is being recalculated.")
level.RecalculateEverything(dg, m.GuildID)
rand.Seed(time.Now().UnixNano())
calculationCode = randomBase64(20)
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+="
var calculationCode string
func init() {
rand.Seed(time.Now().UnixNano())
calculationCode = randomBase64(20)
}
func randomBase64(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
}
return string(b)
}