package commands import ( "crypto/rand" "fmt" "github.com/bwmarrin/discordgo" "PermissionGacha/modules/level" ) func handleLevelCommand(s *discordgo.Session, args []string, m *discordgo.MessageCreate) error { levels, rawXP, err := level.GetLevelAndXP(m.Author.ID) if err != nil { return fmt.Errorf("commands: handleLevelCommand: error while getting level and XP: %w", err) } randomSource := make([]byte, 1) rand.Read(randomSource) xp := rawXP - (rawXP % 100) + ((int(randomSource[0]) + 128) % 100) levelUpRequirement := level.GetLevelUpRequirement(levels) s.ChannelMessageSend( m.ChannelID, fmt.Sprintf( "<@%s> is now level %d. (%d XP/%d XP) [%.1f%%]", m.Author.ID, levels, xp, levelUpRequirement, float64(xp)/float64(levelUpRequirement)*100, ), ) return nil }