Ejemplo n.º 1
0
        public async Task AddPoints(CommandContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.User.IsBot)
            {
                return;
            }

            var   GuildId = context.Guild.Id;
            var   UserId  = context.User.Id;
            ulong Points  = (ulong)_rand.Next(10, 20);

            var statistics = await _statisticsRepository.GetUserStatistics(GuildId, UserId);

            if (statistics is null)
            {
                statistics = new UserStatistic()
                {
                    UserId            = UserId,
                    GuildId           = GuildId,
                    Score             = Points,
                    LastScoredMessage = DateTime.Now
                };
                await _statisticsRepository.AddUserStatistic(statistics);
            }
            else
            {
                if ((DateTime.Now - statistics.LastScoredMessage).Minutes < 2)
                {
                    return;
                }
                statistics.Score += Points;
                await _statisticsRepository.UpdateStatistics(statistics);
            }

            var user = (context.User as SocketGuildUser);

            var roles = await _statisticsRepository.GetRankRewards(GuildId);

            var userRoles = (
                from reward in roles
                join userRole in context.Guild.Roles on reward.RoleId equals userRole.Id
                where reward.ReqScore <= statistics.Score
                orderby reward.ReqScore
                select userRole).ToArray();

            if (userRoles.Length <= 0)
            {
                return;
            }

            IEnumerable <IRole> rolesToRemove = userRoles[0..^ 1];
Ejemplo n.º 2
0
        public async Task GetRewardRoles()
        {
            var rewards = await _statisticsRepository.GetRankRewards(Context.Guild.Id);

            StringBuilder sb = new StringBuilder();

            foreach (var reward in rewards)
            {
                var role = Context.Guild.Roles.Where(x => x.Id == reward.RoleId).FirstOrDefault();
                sb.Append($"{role.Name} - {reward.ReqScore}\n");
            }

            await ReplyImage(sb.ToString());
        }