Change isgd.py to use Exports to offer url shortening, not events

This commit is contained in:
jesopo 2019-02-07 10:07:11 +00:00
parent 8c1c10b3c7
commit 90591ec5b4
2 changed files with 6 additions and 7 deletions

View file

@ -5,9 +5,10 @@ ISGD_API_URL = "https://is.gd/create.php"
REGEX_URL = re.compile("https?://", re.I) REGEX_URL = re.compile("https?://", re.I)
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
@utils.hook("get.shortlink") def on_load(self):
def shortlink(self, event): self.exports.add("shortlink", self._shortlink)
url = event["url"]
def _shortlink(self, url):
if not re.match(REGEX_URL, url): if not re.match(REGEX_URL, url):
url = "http://%s" % url url = "http://%s" % url
@ -23,8 +24,7 @@ class Module(ModuleManager.BaseModule):
:help: Shorten a given URL using the is.gd service :help: Shorten a given URL using the is.gd service
:usage: <url> :usage: <url>
""" """
link = self.events.on("get.shortlink").call_for_result( link = self._shortlink(event["args"])
url=event["args"])
if link: if link:
event["stdout"].write("Shortened URL: %s" % link) event["stdout"].write("Shortened URL: %s" % link)
else: else:

View file

@ -64,8 +64,7 @@ class Module(ModuleManager.BaseModule):
tweet_link = "https://twitter.com/%s/status/%s" % (username, tweet_link = "https://twitter.com/%s/status/%s" % (username,
linked_id) linked_id)
short_url = self.events.on("get.shortlink").call_for_result( short_url = self.exports.get_one("shortlink")(tweet_link)
url=tweet_link)
short_url = " - %s" % short_url if short_url else "" short_url = " - %s" % short_url if short_url else ""
if "retweeted_status" in tweet: if "retweeted_status" in tweet: