コード例 #1
0
ファイル: linkspam.py プロジェクト: warandpeace/lrrbot
	def __init__(self, loop):
		self._loop = loop
		self._re_url = loop.run_until_complete(utils.url_regex())
		self._rules = [
			{
				"re": re.compile(rule["re"], re.IGNORECASE),
				"message": rule["message"],
			}
			for rule in storage.data.get("link_spam_rules", [])
		]
		self.add_server_event("modify_link_spam_rules", self.modify_link_spam_rules)
コード例 #2
0
ファイル: spam.py プロジェクト: warandpeace/lrrbot
def do_check_links(message, rules):
	loop = asyncio.get_event_loop()
	re_url = loop.run_until_complete(utils.url_regex())
	urls = []
	for match in re_url.finditer(message):
		for url in match.groups():
			if url is not None:
				urls.append(url)
				break
	canonical_urls = loop.run_until_complete(asyncio.gather(*map(utils.canonical_url, urls), loop=loop))
	for url_chain in canonical_urls:
		for url in url_chain:
			for rule in rules:
				match = rule["re"].search(url)
				if match is not None:
					return rule["message"] % {str(i+1): v for i, v in enumerate(match.groups())}