Exemple #1
0
        public SpamType CheckSpam(ModerationConfig config, SocketUserMessage message, SocketGuildChannel channel, out List <SpamGuild.SpamChannel.SpamUser.SpamMessage> messages)
        {
            if (!config.UseAntiSpam)
            {
                messages = null;
                return(SpamType.None);
            }

            SpamGuild guild;

            if (SpamGuilds.ContainsKey(channel.Guild.Id))
            {
                guild = SpamGuilds[channel.Guild.Id];
            }
            else
            {
                guild = new SpamGuild(channel.Guild.Id);
                SpamGuilds.Add(channel.Guild.Id, guild);
            }

            SpamGuild.SpamChannel spamChannel;
            if (guild.SpamChannels.ContainsKey(channel.Id))
            {
                spamChannel = guild.SpamChannels[channel.Id];
            }
            else
            {
                spamChannel = new SpamGuild.SpamChannel(channel.Id);
                guild.SpamChannels.Add(channel.Id, spamChannel);
            }

            SpamGuild.SpamChannel.SpamUser spamUser;
            if (spamChannel.SpamUsers.ContainsKey(message.Author.Id))
            {
                spamUser = spamChannel.SpamUsers[message.Author.Id];
            }
            else
            {
                spamUser = new SpamGuild.SpamChannel.SpamUser(message.Author.Id);
                spamChannel.SpamUsers.Add(message.Author.Id, spamUser);
            }

            var response = spamUser.AddMessage(message, config.SpamSettings.MessagesPerTime, config.SpamSettings.SecondsToCheck, config.SpamSettings.MaxRepititions, config.SpamSettings.CacheSize, out messages);

            return(response);
        }
Exemple #2
0
        public ModerationConfig GetModerationConfig(ulong guildId)
        {
            //if there is a cached version, return that.
            //if (ModerationConfigs.ContainsKey(guildId))
            //{
            //     return ModerationConfigs[guildId];
            //}

            //Try to load it from database, otherwise create a new one and store it.
            var document = Database.Load <ModerationConfig>(ModerationConfig.DocumentName(guildId));

            if (document == null)
            {
                document = new ModerationConfig(guildId);
                Database.Store(document, ModerationConfig.DocumentName(guildId));
            }

            //Cache the document
            //ModerationConfigs.TryAdd(document.GuildId, document);
            return(document);
        }
Exemple #3
0
        public void SaveModerationConfig(ModerationConfig config)
        {
            //ModerationConfigs[config.GuildId] = config;

            Database.Store(config, ModerationConfig.DocumentName(config.GuildId));
        }