Aloow !shorten to find the last posted url and shorten it
This commit is contained in:
parent
df42f1d9c5
commit
50e3206a9f
1 changed files with 13 additions and 4 deletions
|
@ -2,7 +2,7 @@ import re
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
ISGD_API_URL = "https://is.gd/create.php"
|
ISGD_API_URL = "https://is.gd/create.php"
|
||||||
REGEX_URL = re.compile("https?://", re.I)
|
REGEX_URL = re.compile("https?://\S+", re.I)
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
def on_load(self):
|
||||||
|
@ -18,14 +18,23 @@ class Module(ModuleManager.BaseModule):
|
||||||
if page and page.data["shorturl"]:
|
if page and page.data["shorturl"]:
|
||||||
return page.data["shorturl"]
|
return page.data["shorturl"]
|
||||||
|
|
||||||
@utils.hook("received.command.shorten", min_args=1)
|
@utils.hook("received.command.shorten")
|
||||||
def shorten(self, event):
|
def shorten(self, event):
|
||||||
"""
|
"""
|
||||||
: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._shortlink(event["args"])
|
url = None
|
||||||
|
if len(event["args"]) > 0:
|
||||||
|
url = event["args_split"][0]
|
||||||
|
else:
|
||||||
|
url = event["target"].buffer.find(REGEX_URL)
|
||||||
|
if url:
|
||||||
|
url = re.search(REGEX_URL, url.message).group(0)
|
||||||
|
if not url:
|
||||||
|
raise utils.EventError("No URL provided/found.")
|
||||||
|
|
||||||
if link:
|
if link:
|
||||||
event["stdout"].write("Shortened URL: %s" % link)
|
event["stdout"].write("Shortened URL: %s" % self._shortlink(url))
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Unable to shorten that URL.")
|
event["stderr"].write("Unable to shorten that URL.")
|
||||||
|
|
Loading…
Reference in a new issue