From c671efd665c5e2fe98bb6ac262d6c6dbf3bcf0cf Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 4 Apr 2018 12:46:26 -0400 Subject: [PATCH] Most fixes --- stealemoji/stealemoji.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index 4640f91..53d9ba5 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -1,4 +1,5 @@ import asyncio +import aiohttp from urllib.parse import urlparse @@ -61,18 +62,19 @@ class StealEmoji: currSetting = await self.config.on() await self.config.on.set(not currSetting) await ctx.send("Collection is now "+str(not currSetting)) - + + @stealemoji.command(name="bank") async def se_bank(self, ctx): """Add current server as emoji bank""" await ctx.send("This will upload custom emojis to this server\n" - "Are you sure you want to make the current server an emoji bank? (y/n)" + "Are you sure you want to make the current server an emoji bank? (y/n)") def check(m): - return upper(m.content) in ["Y","YES","N","NO"] and m.channel == ctx.channel and m.author == ctx.author + return m.content.upper() in ["Y","YES","N","NO"] and m.channel == ctx.channel and m.author == ctx.author - msg = await client.wait_for('message', check=check) + msg = await self.bot.wait_for('message', check=check) - if msg.content in ["N","NO"] + if msg.content in ["N","NO"]: await ctx.send("Cancelled") return @@ -84,13 +86,16 @@ class StealEmoji: async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): """Event handler for reaction watching""" if not reaction.custom_emoji: + print("Not a custom emoji") return if not (await self.config.on()): + print("Collecting is off") return emoji = reaction.emoji if emoji in self.bot.emojis: + print("Emoji already in bot.emojis") return # This is now a custom emoji that the bot doesn't have access to, time to steal it @@ -106,6 +111,7 @@ class StealEmoji: break if guildbank is None: + print("No guildbank to store emoji") # Eventually make a new banklist return @@ -114,13 +120,15 @@ class StealEmoji: stolemojis = await self.config.stolemoji() if emoji.id in stolemojis: + print("Emoji has already been stolen") return # Alright, time to steal it for real path = urlparse(emoji.url).path ext = os.path.splitext(path)[1] - img = await fetch_img(emoji.url) + async with aiohttp.ClientSession() as session: + img = await fetch_img(session, emoji.url) with open("\\cogs\\stealemoji\\"+emoji.name+ext, "wb") as f: f.write(img)