Example #1
0
        private async Task CheckUserAutoban(IGuildUser user)
        {
            FloofDataContext _floofDb       = new FloofDataContext();
            BanOnJoin        badUserAutoban = _floofDb.BansOnJoin.AsQueryable().Where(u => u.UserID == user.Id).FirstOrDefault();

            if (badUserAutoban != null) // user is in the list to be autobanned
            {
                //sends message to user
                EmbedBuilder builder = new EmbedBuilder();
                builder.Title       = "⚖️ Ban Notification";
                builder.Description = $"You have been automatically banned from {user.Guild.Name}";
                builder.AddField("Reason", badUserAutoban.Reason);
                builder.Color = ADMIN_COLOR;
                await user.SendMessageAsync("", false, builder.Build());

                await user.Guild.AddBanAsync(user.Id, 0, $"{badUserAutoban.ModUsername} -> {badUserAutoban.Reason} (autobanned on user join)");

                try
                {
                    _floofDb.Remove(badUserAutoban);
                    await _floofDb.SaveChangesAsync();

                    return;
                }
                catch (Exception ex) // db error
                {
                    Log.Error("Error with the auto ban on join system: " + ex);
                    return;
                }
            }
        }
Example #2
0
        public bool hasFilteredWord(FloofDataContext floofDb, string messageContent, ulong serverId) // names
        {
            // return false if none of the serverIds match or filtering has been disabled for the server
            if (!floofDb.FilterConfigs.AsQueryable()
                .Any(x => x.ServerId == serverId && x.IsOn))
            {
                return(false);
            }

            DateTime currentTime = DateTime.Now;

            if (_lastRefreshedTime == null || currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
            {
                _filteredWords = floofDb.FilteredWords.AsQueryable()
                                 .Where(x => x.ServerId == serverId).ToList();
                _lastRefreshedTime = currentTime;
            }

            foreach (var filteredWord in _filteredWords)
            {
                Regex r = new Regex($"{filteredWord.Word}",
                                    RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (r.IsMatch(messageContent))
                {
                    return(true);
                }
            }
            return(false);
        }
        public async Task HandleWelcomeGate(SocketGuildUser before, SocketGuildUser after)
        {
            if (before.IsPending == after.IsPending) // no welcome gate change
            {
                return;
            }
            FloofDataContext floofDb = new FloofDataContext();
            var         guild        = after.Guild;
            WelcomeGate serverConfig = floofDb.WelcomeGateConfigs.Find(guild.Id);

            if (serverConfig == null || serverConfig.Toggle == false || serverConfig.RoleId == null) // disabled
            {
                return;
            }

            try
            {
                var userRole = guild.GetRole((ulong)serverConfig.RoleId);
                if (userRole == null)// role does not exist anymore
                {
                    Log.Error("Unable to automatically assign a role for the welcome gate - role does not exist");
                    return;
                }

                await after.AddRoleAsync(userRole);
            }
            catch (Exception ex)
            {
                Log.Error("An exception occured when trying to add roles for the welcome gate: " + ex.ToString());
            }
        }
Example #4
0
        public bool IsToggled(IGuild guild)
        {
            // check if the logger is toggled on in this server
            // check the status of logger
            FloofDataContext _floofDb = new FloofDataContext();

            var ServerConfig = _floofDb.LogConfigs.Find(guild.Id);

            if (ServerConfig == null) // no entry in DB for server - not configured
            {
                return(false);
            }

            return(ServerConfig.IsOn);
        }
Example #5
0
        public async Task <ITextChannel> GetChannel(Discord.IGuild guild, string eventName = null)
        {
            if (eventName == null)
            {
                return(null);
            }

            FloofDataContext _floofDb = new FloofDataContext();

            var serverConfig = _floofDb.LogConfigs.Find(guild.Id);

            System.Reflection.PropertyInfo propertyInfo = serverConfig.GetType().GetProperty(eventName);
            ulong logChannel  = (ulong)(propertyInfo.GetValue(serverConfig, null));
            var   textChannel = await guild.GetTextChannelAsync(logChannel);

            return(textChannel);
        }
Example #6
0
        private async Task LogErrorInDiscordChannel(IResult result, SocketMessage originalMessage)
        {
            FloofDataContext _floofDb = new FloofDataContext();

            var userMsg = originalMessage as SocketUserMessage; // the original command
            var channel = userMsg.Channel as ITextChannel;      // the channel of the original command

            if (channel == null)
            {
                return;
            }

            var serverConfig = _floofDb.ErrorLoggingConfigs.Find(channel.GuildId); // no db result

            if (serverConfig == null)
            {
                return;
            }

            if ((!serverConfig.IsOn) || (serverConfig.ChannelId == null)) // not configured or disabled
            {
                return;
            }

            Discord.ITextChannel errorLoggingChannel = await channel.Guild.GetTextChannelAsync((ulong)serverConfig.ChannelId); // can return null if channel invalid

            if (errorLoggingChannel == null)
            {
                return;
            }


            Embed embed = generateErrorEmbed(userMsg.Author, result, userMsg);
            await errorLoggingChannel.SendMessageAsync("", false, embed);

            return;
        }
        public async Task CheckForExcessiveJoins(IGuild guild)
        {
            var server = guild as SocketGuild;

            if (server == null)
            {
                return;
            }
            var _floofDb     = new FloofDataContext();
            var serverConfig = GetServerConfig(guild, _floofDb);

            // raid protection not configured or disabled
            if (serverConfig == null || !serverConfig.Enabled)
            {
                return;
            }
            // increment user join count for guild
            if (numberOfJoins.ContainsKey(guild))
            {
                numberOfJoins[guild] += 1;
                if (numberOfJoins[guild] >= maxNumberOfJoins)
                {
                    var modRole    = (serverConfig.ModRoleId != null) ? server.GetRole((ulong)serverConfig.ModRoleId) : null;
                    var modChannel = (serverConfig.ModChannelId != null) ? server.GetChannel((ulong)serverConfig.ModChannelId) as ITextChannel : null;
                    await NotifyModerators(modRole, modChannel, "Excessive number of new joins in short time period.");

                    Log.Information("An excessive number of joins was detected in server ID " + server.Id);
                    numberOfJoins[guild] = 0;
                    return;
                }
            }
            else // add 1 to number of joins in that guild
            {
                numberOfJoins.Add(guild, 1);
            }
            userJoinTimeout(guild);
        }
Example #8
0
        public bool hasFilteredWord(FloofDataContext floofDb, string messageContent, ulong serverId, ulong channelId) // messages
        {
            // return false if none of the serverIds match or filtering has been disabled for the server
            if (!floofDb.FilterConfigs.AsQueryable()
                .Any(x => x.ServerId == serverId && x.IsOn))
            {
                return(false);
            }

            // whitelist means we don't have the filter on for this channel
            if (floofDb.FilterChannelWhitelists.AsQueryable()
                .Any(x => x.ChannelId == channelId && x.ServerId == serverId))
            {
                return(false);
            }

            DateTime currentTime = DateTime.Now;

            if (_lastRefreshedTime == null || currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
            {
                _filteredWords = floofDb.FilteredWords.AsQueryable()
                                 .Where(x => x.ServerId == serverId).ToList();
                _lastRefreshedTime = currentTime;
            }

            foreach (var filteredWord in _filteredWords)
            {
                Regex r = new Regex(@$ "\b({Regex.Escape(filteredWord.Word)})\b",
                                    RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (r.IsMatch(messageContent))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #9
0
        public List <string> filteredWordsInName(FloofDataContext floofDb, string messageContent, ulong serverId) // names
        {
            // return false if none of the serverIds match or filtering has been disabled for the server
            if (!floofDb.FilterConfigs.AsQueryable()
                .Any(x => x.ServerId == serverId && x.IsOn))
            {
                return(null);
            }

            DateTime currentTime = DateTime.Now;

            if (_lastRefreshedTime == null || currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
            {
                _filteredWords = floofDb.FilteredWords.AsQueryable()
                                 .Where(x => x.ServerId == serverId).ToList();
                _lastRefreshedTime = currentTime;
            }

            List <string> DetectedWords = new List <string>();

            foreach (var filteredWord in _filteredWords)
            {
                if (messageContent.ToLower().Contains(filteredWord.Word.ToLower()))
                {
                    DetectedWords.Add(filteredWord.Word);
                }
            }
            if (DetectedWords.Count() == 0)
            {
                return(null);
            }
            else
            {
                return(DetectedWords);
            }
        }
        // return true is message triggered raid protection, false otherwise
        public async Task <bool> CheckMessage(FloofDataContext _floofDb, SocketMessage msg)
        {
            // can return null
            var userMsg = msg as SocketUserMessage;

            if (userMsg == null || msg.Author.IsBot)
            {
                return(false);
            }
            // can return null
            var channel = userMsg.Channel as ITextChannel;

            if (channel == null)
            {
                return(false);
            }
            var guild = channel.Guild as SocketGuild;

            if (guild == null)
            {
                return(false);
            }

            var serverConfig = GetServerConfig(guild, _floofDb);

            // raid protection not configured or disabled
            if (serverConfig == null || !serverConfig.Enabled)
            {
                return(false);
            }

            // users with the exceptions role are immune to raid protection
            if (serverConfig.ExceptionRoleId != null)
            {
                // returns null if exception role doe not exist anymore
                var exceptionsRole = guild.GetRole((ulong)serverConfig.ExceptionRoleId);
                var guildUser      = guild.GetUser(userMsg.Author.Id);
                // role must exist and user must exist in server
                if (exceptionsRole != null && guildUser != null)
                {
                    foreach (IRole role in guildUser.Roles)
                    {
                        if (role.Id == exceptionsRole.Id)
                        {
                            return(false);
                        }
                    }
                }
            }

            // get other values from db and get their associated roles and channels
            var mutedRole    = (serverConfig.MutedRoleId != null) ? guild.GetRole((ulong)serverConfig.MutedRoleId) : null;
            var modRole      = (serverConfig.ModRoleId != null) ? guild.GetRole((ulong)serverConfig.ModRoleId) : null;
            var modChannel   = (serverConfig.ModChannelId != null) ? guild.GetChannel((ulong)serverConfig.ModChannelId) as ITextChannel : null;
            var banOffenders = serverConfig.BanOffenders;

            // ensure our dictionaries contain the guild
            ensureGuildInDictionaries(guild.Id);
            // now we run our checks. If any of them return true, we have a bad boy

            // checks for filtered words
            bool filteredWord = CheckMessageForFilteredWords(userMsg, guild.Id);
            // this will ALWAYS ban users regardless of muted role or not
            bool spammedMentions = CheckMentions(userMsg, guild, modRole, modChannel).Result;
            // this will check their messages and see if they are spamming
            bool userSpammedMessages = CheckUserMessageCount(userMsg, guild.Id);
            // this checks for spamming letters in a row
            bool userSpammedLetters = CheckLetterSpam(userMsg, guild.Id);
            // this checks for posting invite links
            bool userSpammedInviteLink = CheckInviteLinks(userMsg, guild.Id);
            // check for spammed emojis
            bool userSpammedEmojis = CheckEmojiSpam(userMsg, guild.Id);

            if (spammedMentions)
            {
                return(false); // user already banned
            }
            if (filteredWord || userSpammedMessages || userSpammedLetters || userSpammedInviteLink || userSpammedEmojis)
            {
                if (userPunishmentCount[guild.Id].ContainsKey(userMsg.Author.Id))
                {
                    // they have been too much of a bad boye >:(
                    if (userPunishmentCount[guild.Id][msg.Author.Id] > maxNumberOfPunishments)
                    {
                        // remove them from the dictionary
                        userPunishmentCount[guild.Id].Remove(userMsg.Author.Id);
                        // add to the list of punished users
                        punishedUsers[guild.Id].Add(userMsg.Author);
                        punishedUsersTimeout(guild.Id, userMsg.Author);
                        // decide if we need to notify the mods of a potential raid
                        if ((modRole != null) && (modChannel != null) && (punishedUsers.Count >= maxNumberPunishedUsers))
                        {
                            await NotifyModerators(modRole, modChannel, "Excessive amount of users punished in short time frame.");
                        }
                        // if the muted role is set and we are not banning people
                        if ((mutedRole != null) && (!banOffenders))
                        {
                            var guildUser = guild.GetUser(userMsg.Author.Id);
                            try
                            {
                                await guildUser.AddRoleAsync(mutedRole);

                                await msg.Channel.SendMessageAsync(userMsg.Author.Mention + " you have received too many warnings. You are muted as a result.");
                            }
                            catch (Exception e)
                            {
                                Log.Error("Unable to mute user for raid protection: " + e);
                            }
                            return(true);
                        }
                        else // ban user by default
                        {
                            try
                            {
                                string reason = "Raid Protection => Triggered too many bot responses";
                                //sends message to user
                                EmbedBuilder builder = new EmbedBuilder();
                                builder.Title       = "⚖️ Ban Notification";
                                builder.Description = $"You have been banned from {guild.Name}";
                                builder.AddField("Reason", reason);
                                builder.Color = Discord.Color.Red;
                                await msg.Author.SendMessageAsync("", false, builder.Build());

                                await guild.AddBanAsync(msg.Author, 0, reason);
                            }
                            catch (Exception e)
                            {
                                Log.Error("Unable to ban user for raid protection: " + e);
                            }
                            return(false); // dont need to delete message as the ban already handled that
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
        public RaidProtectionConfig GetServerConfig(IGuild guild, FloofDataContext _floofDb)
        {
            RaidProtectionConfig serverConfig = _floofDb.RaidProtectionConfigs.Find(guild.Id);

            return(serverConfig);
        }
Example #12
0
 public LoggerCommands(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }
 public RaidProtectionCommands(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }
Example #14
0
 public TagCommands(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
Example #15
0
 public ErrorLoggingCommands(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }
Example #16
0
 static readonly ulong SERVER_ID = BotConfigFactory.Config.ModMailServer; // TODO: Replace this so that it works on more servers
 public ModMailModule(FloofDataContext _floofDB)
 {
     _floofDb = _floofDB;
 }
Example #17
0
 public Administration(FloofDataContext floofDB) => _floofDB = floofDB;
Example #18
0
 public WelcomeGateConfig(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }
 public WelcomeGateService(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
Example #20
0
        public async Task OnReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            var msg  = message.Value as IUserMessage;
            var chan = channel as ITextChannel;

            if (reaction.User.Value.IsBot || msg == null || chan == null)
            {
                return;
            }

            var serverConfig = _floofDb.NicknameAlertConfigs.Find(chan.Guild.Id);

            if (serverConfig == null || !serverConfig.IsOn || serverConfig.Channel == 0) // not configured/disabled
            {
                return;
            }

            if (alertMessageIdsDic != null && alertMessageIdsDic.ContainsKey(msg.Id))
            {
                SocketGuildUser badUser;
                alertMessageIdsDic.TryGetValue(msg.Id, out badUser);
                var moderator = badUser.Guild.GetUser(reaction.UserId);

                if (reaction.Emote.Name.Equals(BAN_EMOJI.Name))
                {
                    try
                    {
                        //sends message to user
                        EmbedBuilder builder = new EmbedBuilder();
                        builder.Title       = "⚖️ Ban Notification";
                        builder.Description = $"You have been banned from {badUser.Guild.Name}";
                        builder.AddField("Reason", "Banned by BOT for an inappropriate name");
                        builder.Color = Color.DarkOrange;

                        await badUser.SendMessageAsync("", false, builder.Build());

                        await badUser.Guild.AddBanAsync(badUser, 0, $"{moderator.Username}#{moderator.Discriminator} ({moderator.Id}) -> Inappropriate Name");

                        await channel.SendMessageAsync($"Got it! I banned {badUser.Username}#{badUser.Discriminator}!");
                    }
                    catch (Exception ex)
                    {
                        await channel.SendMessageAsync("Unable to ban user. Do I have the permissions?");

                        Log.Error("Unable to ban user for bad name: " + ex);
                    }
                    alertMessageIdsDic.Remove(msg.Id);
                }
                else if (reaction.Emote.Name.Equals(WARN_EMOJI.Name))
                {
                    try
                    {
                        FloofDataContext _floofDb = new FloofDataContext();
                        _floofDb.Add(new Warning
                        {
                            DateAdded   = DateTime.Now,
                            Forgiven    = false,
                            GuildId     = badUser.Guild.Id,
                            Moderator   = $"{moderator.Username}#{moderator.Discriminator}",
                            ModeratorId = moderator.Id,
                            Reason      = $"{moderator.Username}#{moderator.Discriminator} -> Warned by BOT for an inappropriate name",
                            UserId      = badUser.Id
                        });
                        _floofDb.SaveChanges();

                        EmbedBuilder builder = new EmbedBuilder();
                        builder.Title       = "⚖️ Warn Notification";
                        builder.Description = $"You have recieved a warning in {badUser.Guild.Name}";
                        builder.AddField("Reason", "Warned by BOT for an inappropriate name");
                        builder.Color = Color.DarkOrange;
                        await badUser.SendMessageAsync("", false, builder.Build());

                        await channel.SendMessageAsync($"Got it! I warned {badUser.Username}#{badUser.Discriminator}!");
                    }
                    catch (Exception ex)
                    {
                        await channel.SendMessageAsync("Unable to warn user. Do I have the permissions?");

                        Log.Error("Unable to warn user for bad name: " + ex);
                    }
                    alertMessageIdsDic.Remove(msg.Id);
                    return;
                }
                else if (reaction.Emote.Name.Equals(KICK_EMOJI.Name))
                {
                    try
                    {
                        //sends message to user
                        EmbedBuilder builder = new EmbedBuilder();
                        builder.Title       = "🥾 Kick Notification";
                        builder.Description = $"You have been Kicked from {badUser.Guild.Name}";
                        builder.AddField("Reason", "Kicked by BOT for an inappropriate name");
                        builder.Color = Color.DarkOrange;
                        await badUser.SendMessageAsync("", false, builder.Build());

                        await badUser.KickAsync($"{badUser.Username}#{badUser.Discriminator} -> Inappropriate Name");

                        await channel.SendMessageAsync($"Got it! I kicked {badUser.Username}#{badUser.Discriminator}!");
                    }
                    catch (Exception ex)
                    {
                        await channel.SendMessageAsync("Unable to kick user. Do I have the permissions?");

                        Log.Error("Unable to kick user for bad name: " + ex);
                    }
                    alertMessageIdsDic.Remove(msg.Id);
                }
                else if (reaction.Emote.Name.Equals(REMOVE_NICKNAME_EMOJI.Name))
                {
                    try
                    {
                        await badUser.Guild.GetUser(badUser.Id).ModifyAsync(user => user.Nickname = "");

                        await channel.SendMessageAsync($"Got it! I removed {badUser.Username}#{badUser.Discriminator}'s nickname!");
                    }
                    catch (Exception ex)
                    {
                        await channel.SendMessageAsync("Unable to remove their nickname. Do I have the permissions?");

                        Log.Error("Unable to remove nickname for bad name: " + ex);
                    }
                    alertMessageIdsDic.Remove(msg.Id);
                }
                else if (reaction.Emote.Name.Equals(NO_ACTION_EMOJI.Name))
                {
                    await channel.SendMessageAsync($"Got it! I took no action against {badUser.Username}#{badUser.Discriminator}!");

                    alertMessageIdsDic.Remove(msg.Id);
                }
                return;
            }
        }
Example #21
0
 public NicknameAlertService(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
Example #22
0
 public UserAssignableRoleCommands(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
 public UserRoleRetentionService(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
Example #24
0
 public Filter(FloofDataContext floofDb)
 {
     _floofDb = floofDb;
 }
Example #25
0
 public ModMailConfigModule(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }
Example #26
0
 public NicknameAlert(FloofDataContext floofDB)
 {
     _floofDB = floofDB;
 }