blob: cfc94ebb9eac6e8fc5be9486fdb1da8ad6ec1162 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import re
from src import ModuleManager, utils
ISGD_API_URL = "https://is.gd/create.php"
class Module(ModuleManager.BaseModule):
def on_load(self):
self.exports.add("shortlink", self._shortlink)
def _shortlink(self, url):
if not re.match(utils.http.REGEX_URL, url):
url = "http://%s" % url
page = utils.http.request(ISGD_API_URL, get_params=
{"format": "json", "url": url}, json=True)
if page and page.data["shorturl"]:
return page.data["shorturl"]
@utils.hook("received.command.shorten")
def shorten(self, event):
"""
:help: Shorten a given URL using the is.gd service
:usage: <url>
"""
url = None
if len(event["args"]) > 0:
url = event["args_split"][0]
else:
url = event["target"].buffer.find(utils.http.REGEX_URL)
if url:
url = re.search(utils.http.REGEX_URL, url.message).group(0)
if not url:
raise utils.EventError("No URL provided/found.")
if url:
event["stdout"].write("Shortened URL: %s" % self._shortlink(url))
else:
event["stderr"].write("Unable to shorten that URL.")
|