public async Task WarnUser([Remainder] SocketGuildUser user = null)
        {
            if (user == null)
            {
                await Context.Channel.SendMessageAsync("You need to input a valid username!");

                return;
            }

            await Context.Channel.SendMessageAsync(Warn(user));

            UserAccountsManager.CheckUserWarnStatus(user);
        }
示例#2
0
        /// <summary>
        /// Checks how many users are mention in a single message, if it is higher then the threshold then remove it
        /// </summary>
        /// <param name="message">The message to check</param>
        /// <param name="guild">The guild of the message</param>
        /// <returns>Whether the user is allowed to do that action</returns>
        public bool CheckMentionUsers(SocketUserMessage message, SocketGuild guild)
        {
            SocketGuildUser user = (SocketGuildUser)message.Author;

            UserAccountServerData serverAccount =
                UserAccountsManager.GetAccount(user).GetOrCreateServer(guild.Id);

            if (serverAccount.IsAccountNotWarnable)
            {
                return(false);
            }

            //If it is the owner of the Discord server, ignore
            if (user.Id == guild.OwnerId)
            {
                return(false);
            }

            //If user is a admin, ignore
            if (user.GuildPermissions.Administrator)
            {
                return(false);
            }

            int guildMemberCount = guild.Users.Count;
            int mentionCount     = message.MentionedUsers.Count;

            int percentage = mentionCount / guildMemberCount * 100;

            if (percentage > ServerListsManager.GetServer(guild).AntiSpamSettings.MentionUsersPercentage)
            {
                return(false);
            }

            message.Channel.SendMessageAsync(
                $"Hey {message.Author.Mention}, listing all members of this Discord server is not allowed!")
            .GetAwaiter().GetResult();

            message.DeleteAsync().GetAwaiter().GetResult();

            serverAccount.Warnings++;

            UserAccountsManager.CheckUserWarnStatus(user);
            UserAccountsManager.SaveAccounts();

            return(true);
        }