aboutsummaryrefslogtreecommitdiff
path: root/modules/title.py
diff options
context:
space:
mode:
authorGravatar dngfx2018-08-31 10:50:37 +0100
committerGravatar dngfx2018-08-31 10:50:37 +0100
commitabed9cf4ea71dcbad2dd2c049683b8d14b942e09 (patch)
tree3e40caf63fa7e1500469f4ad9a0c45c51808aad4 /modules/title.py
parentFix a copy paste fail in IRCLineHandler that caused PARTs to be handled as QUITs (diff)
signature
Reformat
Diffstat (limited to 'modules/title.py')
-rw-r--r--modules/title.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/modules/title.py b/modules/title.py
index df19a6ec..ce31d80b 100644
--- a/modules/title.py
+++ b/modules/title.py
@@ -3,31 +3,33 @@ import Utils
REGEX_URL = re.compile("https?://\S+", re.I)
+
class Module(object):
- def __init__(self, bot):
- bot.events.on("received").on("command").on("title", "t").hook(
- self.title, help="Get the title of the provided or most "
- "recent URL.", usage="[URL]")
+ def __init__(self, bot):
+ bot.events.on("received").on("command").on("title", "t").hook(
+ self.title, help="Get the title of the provided or most "
+ "recent URL.", usage="[URL]")
- def title(self, event):
- url = None
- if len(event["args"]) > 0:
- url = event["args_split"][0]
- else:
- url = event["buffer"].find(REGEX_URL)
- if url:
- url = re.search(REGEX_URL, url.message).group(0)
- if not url:
- event["stderr"].write("No URL provided/found.")
- return
- soup = Utils.get_url(url, soup=True)
- if not soup:
- event["stderr"].write("Failed to get URL.")
- return
- title = soup.title
- if title:
- title = title.text.replace("\n", " ").replace("\r", ""
- ).replace(" ", " ").strip()
- event["stdout"].write(title)
- else:
- event["stderr"].write("No title found.")
+ def title(self, event):
+ url = None
+ if len(event["args"]) > 0:
+ url = event["args_split"][0]
+ else:
+ url = event["buffer"].find(REGEX_URL)
+ if url:
+ url = re.search(REGEX_URL, url.message).group(0)
+ if not url:
+ event["stderr"].write("No URL provided/found.")
+ return
+ soup = Utils.get_url(url, soup=True)
+ if not soup:
+ event["stderr"].write("Failed to get URL.")
+ return
+ title = soup.title
+ if title:
+ title = title.text.replace("\n", " ").replace("\r", ""
+ ).replace(" ",
+ " ").strip()
+ event["stdout"].write(title)
+ else:
+ event["stderr"].write("No title found.")