Пример #1
0
                public bool CheckUserRatelimit(ulong id, ulong guildId, SocketGuildUser optUser)
                {
                    HashSet <ulong> ignoreUsers;
                    HashSet <ulong> ignoreRoles;

                    if ((IgnoredUsers.TryGetValue(guildId, out ignoreUsers) && ignoreUsers.Contains(id)) ||
                        (optUser != null && IgnoredRoles.TryGetValue(guildId, out ignoreRoles) && optUser.RoleIds.Any(x => ignoreRoles.Contains(x))))
                    {
                        return(false);
                    }

                    var usr = Users.GetOrAdd(id, (key) => new RatelimitedUser()
                    {
                        UserId = id
                    });

                    if (usr.MessageCount >= MaxMessages)
                    {
                        return(true);
                    }
                    usr.MessageCount++;
                    var _ = Task.Run(async() =>
                    {
                        try
                        {
                            await Task.Delay(PerSeconds * 1000, cancelSource.Token);
                        }
                        catch (OperationCanceledException) { }
                        usr.MessageCount--;
                    });

                    return(false);
                }