Skip to content

Instantly share code, notes, and snippets.

@malles
Created September 8, 2016 16:04
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/4b97102350c328e65890296cf9a47560 to your computer and use it in GitHub Desktop.
Save malles/4b97102350c328e65890296cf9a47560 to your computer and use it in GitHub Desktop.
Bacon ipsum plugin for Hangupsbot
import asyncio, json, logging
import urllib
import plugins
logger = logging.getLogger(__name__)
def _initialise(bot):
plugins.register_user_command(["bacon"])
def bacon(bot, event, paras=1, *args):
"""Draw line between points"""
params = {
"type": "meat-and-filler",
"start-with-lorem": "1",
"paras": paras
}
yield from get_lorem(bot, event, params)
@asyncio.coroutine
def get_lorem(bot, event, params):
logger.info("Fetching bacon {}".format(params))
f = urllib.request.urlopen("https://baconipsum.com/api/?{}".format(urllib.parse.urlencode(params)))
res = json.loads(f.read().decode('utf-8'))
if res:
yield from bot.coro_send_message(event.conv, "<br/><br/>".join(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment