This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/shorten.py

20 lines
581 B
Python
Raw Normal View History

2012-03-23 01:32:48 +01:00
# Plugin by Lukeroge
2012-04-21 05:55:52 +02:00
from util import hook
from urllib2 import HTTPError
from util.web import bitly, ShortenError
2011-11-20 10:23:31 +01:00
2012-03-23 01:32:48 +01:00
2011-11-20 10:23:31 +01:00
@hook.command
2012-03-23 01:32:48 +01:00
def shorten(inp, bot=None):
2012-02-28 03:03:43 +01:00
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided."
2012-03-07 08:06:41 +01:00
api_user = bot.config.get("api_keys", {}).get("bitly_user", None)
2012-02-26 10:08:36 +01:00
api_key = bot.config.get("api_keys", {}).get("bitly_api", None)
if api_key is None:
return "error: no api key set"
2012-04-21 05:55:52 +02:00
try:
return bitly(inp, api_user, api_key)
except (HTTPError, ShortenError):
return "Could not shorten %s!" % inp