Skip to content

Instantly share code, notes, and snippets.

@malles
Created September 8, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malles/0e7c821b08cf835c3e159d7cb57fd9f1 to your computer and use it in GitHub Desktop.
Save malles/0e7c821b08cf835c3e159d7cb57fd9f1 to your computer and use it in GitHub Desktop.
Create short urls and lmgtfy urls in your Hangupsbot
import asyncio
from urllib.request import urlopen
import plugins
def _initialise(bot):
plugins.register_user_command(["lmgtfy"])
plugins.register_user_command(["shorten"])
def lmgtfy(bot, event, *args):
search = "http://lmgtfy.com/?q={}".format("+".join(args))
message = yield from short_url(search)
yield from bot.coro_send_message(event.conv, message)
def shorten(bot, event, *args):
message = yield from short_url(args[0])
yield from bot.coro_send_message(event.conv, message)
@asyncio.coroutine
def short_url(url):
f = urlopen("http://tinyurl.com/api-create.php?url={}".format(url))
res = f.read().decode('utf-8')
if res:
return res
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment