add urlinfo plugin

This commit is contained in:
jkhsjdhjs 2021-05-14 19:20:19 +00:00
parent cf2fe25d68
commit 233cfc9089

31
bot/urlinfo.py Normal file
View File

@ -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<target>\S+) :.*(?P<url>https?:\/\/\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())