Created
September 8, 2016 16:04
-
-
Save malles/4b97102350c328e65890296cf9a47560 to your computer and use it in GitHub Desktop.
Bacon ipsum plugin for Hangupsbot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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