package gacha import ( "fmt" "github.com/bwmarrin/discordgo" "PermissionGacha/db" "PermissionGacha/modules/config" ) func RollReward(s *discordgo.Session, rewardeeID string, timesToReward int) error { if timesToReward <= 0 { return nil } rewardee, err := s.GuildMember(config.GuildID, rewardeeID) if err != nil { return err } rewardCount := make(map[int]map[bool]int) shardCount := 0 for i := 0; i < timesToReward; i++ { rewardID := rand.Intn(len(gachaRewards)) success, err := gachaRewards[rewardID].Reward(s, rewardee) if err != nil { return err } if _, ok := rewardCount[rewardID]; !ok { rewardCount[rewardID] = make(map[bool]int) } if success { rewardee, err = s.GuildMember(config.GuildID, rewardeeID) if err != nil { return err } } else { shardCount++ } rewardCount[rewardID][success]++ } err = db.RewardShard(rewardeeID, shardCount) if err != nil { return err } channel, err := s.UserChannelCreate(rewardeeID) if err != nil { return err } if timesToReward == 1 { for k, v := range rewardCount { if v[true] > 0 { //They were rewarded that exact thing. s.ChannelMessageSend( channel.ID, fmt.Sprintf( "**GACHA >** <@%s>, you just levelled up! You got __%s__.", rewardeeID, gachaRewards[k].FriendlyName, ), ) } else { //They were rewarded that thing but got a shard instead. s.ChannelMessageSend( channel.ID, fmt.Sprintf( "**GACHA >** <@%s>, you just levelled up! You originally got __%s__ but you got a shard instead.", rewardeeID, gachaRewards[k].FriendlyName, ), ) } } } else { msg := fmt.Sprintf( "**GACHA >** <@%s>, you just levelled up %d times. Here are your rewards:", rewardeeID, timesToReward, ) for k, v := range rewardCount { msg += fmt.Sprintf("\n- __%s__", gachaRewards[k].FriendlyName) if v[false] > 0 { msg += fmt.Sprintf(" (%d converted to shards)", v[false]) } } s.ChannelMessageSend(channel.ID, msg) } return nil }