Change bitly.py to use delimited events

This commit is contained in:
jesopo 2018-09-09 16:07:39 +01:00 committed by Dan
parent fc8e3818fe
commit 908d64f5c6

View file

@ -10,10 +10,9 @@ class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot self.bot = bot
self.events = events self.events = events
events.on("get").on("shortlink").hook(self.shortlink) events.on("get.shortlink").hook(self.shortlink)
events.on("received").on("command").on("shorten" events.on("received.command.shorten").hook(self.shorten, min_args=1,
).hook(self.shorten, min_args=1, help="Shorten a URL.", help="Shorten a URL.", usage="<url>")
usage="<url>")
def shortlink(self, event): def shortlink(self, event):
url = event["url"] url = event["url"]
@ -26,8 +25,8 @@ class Module(object):
return data["data"]["url"] return data["data"]["url"]
def shorten(self, event): def shorten(self, event):
link = self.events.on("get").on("shortlink" link = self.events.on("get.shortlink").call_for_result(
).call_for_result(url=event["args"]) url=event["args"])
if link: if link:
event["stdout"].write("Short URL: %s" % link) event["stdout"].write("Short URL: %s" % link)
else: else: