From 233cfc90890e7f22f983a6d37c341a924712029a Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Fri, 14 May 2021 19:20:19 +0000 Subject: [PATCH] add urlinfo plugin --- bot/urlinfo.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 bot/urlinfo.py diff --git a/bot/urlinfo.py b/bot/urlinfo.py new file mode 100644 index 0000000..bf540d0 --- /dev/null +++ b/bot/urlinfo.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +import re +import irc3 +import requests +import io +from lxml import etree + +from . import Plugin + +class URLInfo(Plugin): + BLACKLIST = [ + "^https?:\/\/www\.youtube\.com", + "^https?:\/\/youtu\.be", + "^https?:\/\/w0bm\.com", + "^https?:\/\/f0ck\.me" + ] + + @irc3.event(r'(?i)^:\S+ PRIVMSG (?P\S+) :.*(?Phttps?:\/\/\S+\.\S+).*') + def url_parser(self, target: str, url: str): + for regex in self.BLACKLIST: + if re.match(regex, url): + return + try: + response = requests.get(url, timeout=10) + except requests.exceptions.ConnectionError: + return + tree = etree.parse(io.StringIO(response.text), etree.HTMLParser()).getroot() + title = tree.xpath("/html/head/title") + if len(title) > 0: + self.bot.privmsg(target, '\x02[URLInfo]\x02 ' + title[0].text.strip()) +