From ab96f0fa23f399d292e9c336e71a100cfe89e67b Mon Sep 17 00:00:00 2001 From: Date: Wed, 28 Feb 2018 21:04:45 -0500 Subject: [PATCH] Got discord.py to work with scrython. --- discord_bot.py | 8 ++++---- scrython/cards/cards_object.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/discord_bot.py b/discord_bot.py index f3c506b..73403bd 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -28,9 +28,9 @@ async def mtg(name): mana_cost = card.mana_cost() string = """ - {cardname} {mana_cost} - {type_line} {set_code} {rarity} - {oracle_text}{power_toughness} +{cardname} {mana_cost} +{type_line} {set_code} {rarity} +{oracle_text}{power_toughness} """.format( cardname=card.name(), mana_cost=mana_cost, @@ -41,6 +41,6 @@ async def mtg(name): power_toughness=PT ) - await self.bot.say(string) + await bot.say(string) bot.run(BotUtils.AUTH_TOKEN) diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index 73558bb..e7d98bf 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -1,6 +1,7 @@ import aiohttp import asyncio import urllib.parse +from threading import Thread class CardsObject(object): """ @@ -90,8 +91,13 @@ class CardsObject(object): async with aiohttp.ClientSession(loop=loop) as client: self.scryfallJson = await getRequest(client, self._url) - loop = asyncio.get_event_loop() - loop.run_until_complete(main(loop)) + def do_everything(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(main(loop)) + + t = Thread(target=do_everything) + t.run() if self.scryfallJson['object'] == 'error': raise Exception(self.scryfallJson['details'])