示例#1
0
        public async Task <int> InsertRetribution(Retribution retrib)
        {
            var cmd = "INSERT INTO retributions(RetributerUserId, RetributeeUserId, Reason, PointsRedistributed, numUsers, Time, Success) values(@RetributerID,@RetributeeID,@Reason,@Points,@Count,@Time,@Success)";

            return(await connection.ExecuteAsync(cmd, new { RetributerID = retrib.RetributerUserId, RetributeeID = retrib.RetributeeUserId, Reason = retrib.Reason, Points = retrib.PointsRedistributed, Count = retrib.numUsers, Time = retrib.Time, Success = retrib.Success }));
        }
示例#2
0
        public async Task RetributionAsync(IUser user, [Remainder] string reason)
        {
            int cooldownDuration = 86400;//1 day

            if (user is null)
            {
                return;
            }

            Cooldown cd = await GameService.GetCooldown("retribution");

            if (cd is null)
            {
                cd = new Cooldown("retribution", DateTimeOffset.UnixEpoch.ToUnixTimeSeconds());
                await GameService.InsertCooldown(cd);
            }

            if (cd.LastExecuted + cooldownDuration >= DateTimeOffset.UtcNow.ToUnixTimeSeconds())
            {
                TimeSpan t = TimeSpan.FromSeconds(cd.LastExecuted + cooldownDuration - DateTimeOffset.UtcNow.ToUnixTimeSeconds());
                await ReplyAsync(string.Format("Command on cooldown for {0}", t.ToString(@"hh\:mm\:ss\:fff")));

                return;
            }
            else
            {
                cd.LastExecuted = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                await GameService.UpdateCooldown(cd);

                Retribution retrib;
                if (Rand.Next() % 2 == 0)
                {
                    retrib = new Retribution(Context.User.Id, user.Id, reason, 0, 0, DateTimeOffset.UtcNow.ToUnixTimeSeconds(), false);
                    await GameService.InsertRetribution(retrib);
                    await ReplyAsync(string.Format("{0} was not Retributed today, Ronners!", user.Username));

                    return;
                }


                User victim = await GameService.GetUserByID(user.Id);

                int points = victim.RonPoints;
                if (points <= 0)
                {
                    retrib = new Retribution(Context.User.Id, user.Id, reason, 0, 0, DateTimeOffset.UtcNow.ToUnixTimeSeconds(), false);
                    await GameService.InsertRetribution(retrib);
                    await ReplyAsync(string.Format("{0} was not Retributed today, because they have negative points!", user.Username));

                    return;
                }
                victim.RonPoints = 0;
                await GameService.UpdateUser(victim);

                var receivers = await GameService.GetUsers();

                int pointsEach = points / receivers.Count();
                foreach (var receiver in receivers)
                {
                    receiver.RonPoints += pointsEach;
                    await GameService.UpdateUser(receiver);
                }

                await GameService.UpdateUser(victim);//Remove any points reassigned to the user;

                retrib = new Retribution(Context.User.Id, user.Id, reason, points, receivers.Count(), DateTimeOffset.UtcNow.ToUnixTimeSeconds(), true);
                await GameService.InsertRetribution(retrib);
                await ReplyAsync(string.Format("{0} has been retributed, because {1}.\nLosing {2} points. Ronners!", user.Username, reason, points));
            }
        }