add (as yet untested) Your Own URL Shortener support in yourls.py
This commit is contained in:
parent
e41ea90c62
commit
843d9fb77f
1 changed files with 36 additions and 0 deletions
36
modules/yourls.py
Normal file
36
modules/yourls.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from src import ModuleManager, utils
|
||||
|
||||
def _parse(s):
|
||||
parsed = urllib.parse.urlpare(s)
|
||||
return urllib.parse.urljoin(s, parsed.path), parsed.query
|
||||
|
||||
SETTING = utils.FunctionSetting(_parse, "yourls",
|
||||
"Set YOURLS server (and token) to use for URL shortening",
|
||||
example="https://bitbot.dev/yourls-api.php?1002a612b4",
|
||||
format=utils.sensitive_format)
|
||||
|
||||
@utils.export("botset", SETTING)
|
||||
@utils.export("serverset", SETTING)
|
||||
@utils.export("channelset", SETTING)
|
||||
class Module(ModuleManager.BaseModule):
|
||||
@utils.export("shorturl-x-yourls")
|
||||
def _shorturl(self, server, context, url):
|
||||
if len(url) < 20:
|
||||
return None
|
||||
|
||||
setting = server.get_setting("yourls",
|
||||
self.bot.get_setting("yourls", None))
|
||||
if context:
|
||||
setting = context.get_setting("yourls", setting)
|
||||
|
||||
if not setting == None:
|
||||
url, token = setting
|
||||
|
||||
page = utils.http.request(URL, post_data={
|
||||
"signature": token,
|
||||
"action": "shorturl",
|
||||
"url": url,
|
||||
"format": "json"}).json()
|
||||
if page:
|
||||
return page["shorturl"]
|
||||
return None
|
Loading…
Reference in a new issue