From ceb3002281b5c163d838cc1891c6adbc8ff10075 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Tue, 20 Jul 2021 21:40:38 +0000 Subject: [PATCH] urlinfo: fix some NoneType attribute errors --- bot/urlinfo.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bot/urlinfo.py b/bot/urlinfo.py index c780c67..238a91d 100644 --- a/bot/urlinfo.py +++ b/bot/urlinfo.py @@ -44,7 +44,18 @@ class URLInfo(Plugin): bytes_io.seek(0) tree = etree.parse(bytes_io, etree.HTMLParser()).getroot() - title_elements = tree.xpath("/html/head/title") - if len(title_elements) > 0: - self.bot.privmsg(target, '\x02[URLInfo]\x02 ' + title_elements[0].text.strip()) + if tree is None: + return + + title_elements = tree.xpath("/html/head/title") + if len(title_elements) == 0: + return + + title = title_elements[0].text + if title is None: + return + + title = title.strip() + if title: + self.bot.privmsg(target, '\x02[URLInfo]\x02 ' + title)