示例#1
0
        private BlacklistViolationResult CheckViolation(SocketMessage m)
        {
            if (GlobalBlacklist.CheckViolation(m.Content))
            {
                return new BlacklistViolationResult {
                           IsViolating = true
                }
            }
            ;
            var blacklist = ChannelBlacklists.FirstOrDefault(x => x.Channel == m.Channel as SocketTextChannel);

            if (blacklist == null)
            {
                return new BlacklistViolationResult {
                           IsViolating = false
                }
            }
            ;
            return(new BlacklistViolationResult {
                Blacklist = blacklist, IsViolating = blacklist.CheckViolation(m.Content)
            });
        }
示例#2
0
        public async Task <bool> LoadConfigurationAsync()
        {
            if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "config", "blacklist.json")))
            {
                return(false);
            }

            using (var configStream = File.OpenRead(Path.Combine(Directory.GetCurrentDirectory(), "config", "blacklist.json")))
            {
                using (var configReader = new StreamReader(configStream))
                {
                    var serializedConfig = await configReader.ReadToEndAsync();

                    var config = JsonConvert.DeserializeObject <BlacklistConfig>(serializedConfig);
                    if (config == null)
                    {
                        return(false);
                    }

                    foreach (var b in config.ChannelBlacklists)
                    {
                        ChannelBlacklists.Add(new ChannelBlacklist
                        {
                            Channel  = _client.GetChannel(b.ChannelId) as SocketTextChannel,
                            List     = b.List.Select(x => new Regex(x)).ToList(),
                            MuteTime = b.MuteTime,
                            Enabled  = b.Enabled
                        });
                    }

                    GlobalBlacklist.List     = config.GlobalList.Select(x => new Regex(x)).ToList();
                    GlobalBlacklist.MuteTime = config.GlobalMuteTime;
                    GlobalBlacklist.Enabled  = config.GlobalEnabled;

                    return(true);
                }
            }
        }