fight-fixes
bobloy 7 years ago
parent 93a8adc130
commit c671efd665

@ -1,4 +1,5 @@
import asyncio import asyncio
import aiohttp
from urllib.parse import urlparse from urllib.parse import urlparse
@ -61,18 +62,19 @@ class StealEmoji:
currSetting = await self.config.on() currSetting = await self.config.on()
await self.config.on.set(not currSetting) await self.config.on.set(not currSetting)
await ctx.send("Collection is now "+str(not currSetting)) await ctx.send("Collection is now "+str(not currSetting))
@stealemoji.command(name="bank")
async def se_bank(self, ctx): async def se_bank(self, ctx):
"""Add current server as emoji bank""" """Add current server as emoji bank"""
await ctx.send("This will upload custom emojis to this server\n" 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): 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") await ctx.send("Cancelled")
return return
@ -84,13 +86,16 @@ class StealEmoji:
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
"""Event handler for reaction watching""" """Event handler for reaction watching"""
if not reaction.custom_emoji: if not reaction.custom_emoji:
print("Not a custom emoji")
return return
if not (await self.config.on()): if not (await self.config.on()):
print("Collecting is off")
return return
emoji = reaction.emoji emoji = reaction.emoji
if emoji in self.bot.emojis: if emoji in self.bot.emojis:
print("Emoji already in bot.emojis")
return return
# This is now a custom emoji that the bot doesn't have access to, time to steal it # 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 break
if guildbank is None: if guildbank is None:
print("No guildbank to store emoji")
# Eventually make a new banklist # Eventually make a new banklist
return return
@ -114,13 +120,15 @@ class StealEmoji:
stolemojis = await self.config.stolemoji() stolemojis = await self.config.stolemoji()
if emoji.id in stolemojis: if emoji.id in stolemojis:
print("Emoji has already been stolen")
return return
# Alright, time to steal it for real # Alright, time to steal it for real
path = urlparse(emoji.url).path path = urlparse(emoji.url).path
ext = os.path.splitext(path)[1] 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: with open("\\cogs\\stealemoji\\"+emoji.name+ext, "wb") as f:
f.write(img) f.write(img)

Loading…
Cancel
Save