Somehow the last commit stuffed up. Lets try it again
This commit is contained in:
parent
98ff0ab723
commit
8dbf9b6a65
1 changed files with 9 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
||||||
# # Lukeroge
|
# Plugin by Lukeroge
|
||||||
|
# <lukeroge@gmail.com> <https://github.com/lukeroge/CloudBot/>
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -15,7 +17,7 @@ class ShortenError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
def tiny(url, user, apikey):
|
def bitly(url, user, apikey):
|
||||||
try:
|
try:
|
||||||
params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'})
|
params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'})
|
||||||
j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params)
|
j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params)
|
||||||
|
@ -28,6 +30,8 @@ def tiny(url, user, apikey):
|
||||||
@hook.command
|
@hook.command
|
||||||
def shorten(inp, bot = None):
|
def shorten(inp, bot = None):
|
||||||
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided"
|
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided"
|
||||||
user = bot.config['api_keys']['bitly_user']
|
api_user = bot.config.get("api_keys", {}).get("bitly_user", None)
|
||||||
api = bot.config['api_keys']['bitly_api']
|
api_key = bot.config.get("api_keys", {}).get("bitly_api", None)
|
||||||
return tiny(inp, user, api)
|
if api_key is None:
|
||||||
|
return "error: no api key set"
|
||||||
|
return bitly(inp, api_user, api_key)
|
Reference in a new issue