Пример #1
0
 private async Task SubstractFromBucket(SocketUser user)
 {
     try
     {
         BucketData data = new BucketData();
         if (!_bucketDict.TryGetValue(user.Id, out data))
         {
             return;
         }
         data.bucketSize -= BUCKET_DRAIN_SIZE;
         if (data.bucketSize < 0)
         {
             //RATELIMIT
             data.rateLimitedTill = DateTime.UtcNow.AddSeconds(BUCKET_RATELIMITER);
             await(await user.GetOrCreateDMChannelAsync()).SendMessageAsync("" +
                                                                            $"**You have been ratelimited for {BUCKET_RATELIMITER} seconds. Please do not spam commands or stars! If you continue doing so your lockout will increase in time!**\n" +
                                                                            "If this was by mistake and you did not spam. join https://discord.gg/Pah4yj5 and @ me");
             await SentryService.SendMessage($"**Rate limit occured:**\n" +
                                             $"User: {user.Username}#{user.Discriminator} \t{user.Id}");
         }
         _bucketDict.TryUpdate(user.Id, data);
         //TODO SAVE DATABASE
     }
     catch (Exception e)
     {
         await SentryService.SendError(e);
     }
 }
Пример #2
0
 public bool CheckIfRatelimited(SocketUser user)
 {
     try
     {
         BucketData data = new BucketData();
         if (!_bucketDict.TryGetValue(user.Id, out data))
         {
             return(false);
         }
         if (data.rateLimitedTill.CompareTo(DateTime.UtcNow) >= 0)
         {
             return(true);
         }
         if (data.bucketSize <= 0)
         {
             return(true);
         }
         // if (data.combo >= COMBO_MAX)
         //      return true;
         return(false);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         SentryService.SendError(e);
     }
     return(false);
 }
Пример #3
0
        private async Task <bool> CheckComboAndAdd(SocketUser user)
        {
            try
            {
                BucketData data = new BucketData();
                if (!_bucketDict.TryGetValue(user.Id, out data))
                {
                    return(false);
                }
                //Check if still in combo time
                if (DateTime.UtcNow.Subtract(data.lastCommand).TotalSeconds <= COMBO_TIME_INTERVALL)
                {
                    //COMBO BREAKER IF NEEDED
                    data.combo      += 1;
                    data.lastCommand = DateTime.UtcNow;
                    if (data.combo >= COMBO_MAX)
                    {
                        data.rateLimitedTill = DateTime.UtcNow.AddSeconds(COMBO_RATELIMITER);
                        await(await user.GetOrCreateDMChannelAsync()).SendMessageAsync("" +
                                                                                       $"**You have been ratelimited for {COMBO_RATELIMITER} seconds. Your ratelimit was triggered by the combo breaker and thus your time is higher than normal! Please do not spam commands or stars! If you continue doing so your lockout will increase in time!**\n" +
                                                                                       "If this was by mistake and you did not spam. join https://discord.gg/Pah4yj5 and @ me");
                        await SentryService.SendMessage($"**Rate limit occured:**\n" +
                                                        $"User: {user.Username}#{user.Discriminator} \t{user.Id}");

                        data.bucketSize -= COMBO_PENALTY;
                        _bucketDict.TryUpdate(user.Id, data);
                        //TODO SAVE DATABASE
                        return(false);
                    }
                    _bucketDict.TryUpdate(user.Id, data);
                    //TODO SAVE DATABASE
                    return(true);
                }
                //Reset combo
                data.lastCommand = DateTime.UtcNow;
                data.combo       = 1;
                _bucketDict.TryUpdate(user.Id, data);
                //TODO SAVE DATABASE
                return(true);
            }
            catch (Exception e)
            {
                await SentryService.SendError(e);
            }
            return(false);
        }
Пример #4
0
 private void CreateBucketIfNotExistant(SocketUser user)
 {
     try
     {
         if (!_bucketDict.ContainsKey(user.Id))
         {
             BucketData data = new BucketData
             {
                 bucketSize      = BUCKET_INITIAL_FILL,
                 lastCommand     = DateTime.UtcNow,
                 combo           = 0,
                 rateLimitedTill = DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10))
             };
             _bucketDict.TryAdd(user.Id, data);
             //TODO SAVE DATABASE
             return;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         SentryService.SendError(e);
     }
 }