Exemple #1
0
        public async Task SetRewardRole(string roleName, ulong reqScore)
        {
            IRole role = Context.Guild.Roles.FirstOrDefault(x => x.Name == roleName);

            role ??= await Context.Guild.CreateRoleAsync(roleName);

            if (role is null)
            {
                await ReplyImage("Nie udało się dodać roli");

                return;
            }

            var rankReward = await _statisticsRepository.GetRankReward(Context.Guild.Id, Context.User.Id);

            if (rankReward is null)
            {
                rankReward = new RankReward
                {
                    GuildId  = Context.Guild.Id,
                    ReqScore = reqScore,
                    RoleId   = role.Id,
                    AddedBy  = Context.User.Id
                };
                await _statisticsRepository.AddRankReward(rankReward);
                await ReplyImage($"Do listy nagórd dodano rangę {role} za {reqScore} punktów");
            }
            else
            {
                if (reqScore == 0)
                {
                    await _statisticsRepository.DeleteRankReward(rankReward);
                    await ReplyImage($"Usunięto z listy nagród rangę {role.Name}.");
                }
                else
                {
                    rankReward.ReqScore = reqScore;
                    await _statisticsRepository.UpdateRankReward(rankReward);
                    await ReplyImage($"Rola {role} kosztuje teraz {reqScore} punktów");
                }
            }
        }