def filter_domains(self, event, config): urls = URL_RE.findall(URL_RE.sub('', event.content)) for url in urls: try: parsed = urllib.parse.urlparse(url) except: continue if config.domains_whitelist and parsed.netloc.lower() not in config.domains_whitelist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'whitelist', 'url': url, 'domain': parsed.netloc, }) elif config.domains_blacklist and parsed.netloc.lower() in config.domains_blacklist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'blacklist', 'url': url, 'domain': parsed.netloc }) else: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'other', 'url': url, 'domain': parsed.netloc })
def filter_domains(self, event, config): urls = URL_RE.findall(INVITE_LINK_RE.sub('', event.content)) if event.author.id in event.config.ignored_users: return for url in urls: try: parsed = urlparse.urlparse(url) except: continue if (config.domains_whitelist or not config.domains_blacklist)\ and parsed.netloc.lower() not in config.domains_whitelist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'whitelist', 'url': url, 'domain': parsed.netloc, }) elif config.domains_blacklist and parsed.netloc.lower( ) in config.domains_blacklist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'blacklist', 'url': url, 'domain': parsed.netloc })
def check_message_simple(self, event, member, rule): def check_bucket(name, base_text, func): check, bucket = rule.get_bucket(name, event.guild.id) if not bucket: return if not bucket.check(event.author.id, func(event) if callable(func) else func): raise Violation( rule, check, event, member, name.upper(), base_text + ' ({} / {}s)'.format(bucket.count(event.author.id), bucket.size(event.author.id))) check_bucket('max_messages', 'Too Many Messages', 1) check_bucket('max_mentions', 'Too Many Mentions', lambda e: len(e.mentions)) check_bucket('max_links', 'Too Many Links', lambda e: len(URL_RE.findall(e.message.content))) check_bucket('max_upper_case', 'Too Many Capitals', lambda e: len(UPPER_RE.findall(e.message.content))) # TODO: unicode emoji too pls check_bucket('max_emojis', 'Too Many Emojis', lambda e: len(EMOJI_RE.findall(e.message.content))) check_bucket( 'max_newlines', 'Too Many Newlines', lambda e: e.message.content. count('\n') + e.message.content.count('\r')) check_bucket('max_attachments', 'Too Many Attachments', lambda e: len(e.message.attachments)) if rule.max_duplicates and rule.max_duplicates.interval and rule.max_duplicates.count: self.check_duplicate_messages(event, member, rule)
def filter_domains(self, event, config): urls = URL_RE.findall(INVITE_LINK_RE.sub('', event.content)) for url in urls: try: parsed = urlparse.urlparse(url) if parsed.scheme == '': parsed = urlparse.urlparse("https://"+url) except: continue if (config.domains_whitelist or not config.domains_blacklist)\ and parsed.netloc.lower() not in config.domains_whitelist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'whitelist', 'url': url, 'domain': parsed.netloc, }) elif config.domains_blacklist and parsed.netloc.lower() in config.domains_blacklist: raise Censorship(CensorReason.DOMAIN, event, ctx={ 'hit': 'blacklist', 'url': url, 'domain': parsed.netloc })