fight-fixes
bobloy 7 years ago
parent a10cbafdef
commit 8dfbf0972a

@ -12,6 +12,7 @@ from discord.ext import commands
from redbot.core import Config from redbot.core import Config
from redbot.core.bot import Red from redbot.core.bot import Red
# from redbot.core import data_manager
async def fetch_img(session, url): async def fetch_img(session, url):
with aiohttp.Timeout(10): with aiohttp.Timeout(10):
@ -40,10 +41,8 @@ class StealEmoji:
"require_colons": False, "require_colons": False,
"managed": False, "managed": False,
"guild_id": None, "guild_id": None,
"created_at": None,
"url": None, "url": None,
"roles": [], "animated": False
"guild": None # Will not save this one
} }
self.config.register_global(**default_global) self.config.register_global(**default_global)
@ -82,7 +81,7 @@ class StealEmoji:
guildbanks.append(ctx.guild.id) guildbanks.append(ctx.guild.id)
await ctx.send("This server has been added as an emoji bank") await ctx.send("This server has been added as an emoji bank")
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:
@ -115,7 +114,7 @@ class StealEmoji:
# Eventually make a new banklist # Eventually make a new banklist
return return
# Next, have I saved this emoji before (in self.bot.emojis should've done this) # Next, have I saved this emoji before (because uploaded emoji != orignal emoji)
stolemojis = await self.config.stolemoji() stolemojis = await self.config.stolemoji()
@ -124,30 +123,44 @@ class StealEmoji:
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]
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
img = await fetch_img(session, emoji.url) img = await fetch_img(session, emoji.url)
with open("\\cogs\\stealemoji\\"+emoji.name+ext, "wb") as f: # path = data_manager.cog_data_path(cog_instance=self) / (emoji.name+ext)
f.write(img)
# with path.open("wb") as f:
# f.write(img)
# urllib.urlretrieve(emoji.url, emoji.name+ext) # urllib.urlretrieve(emoji.url, emoji.name+ext)
try: try:
await guildbank.create_custom_emoji(name=emoji.name,image="\\cogs\\stealemoji\\"+emoji.name+ext,reason="Stole from "+str(user)) await guildbank.create_custom_emoji(name=emoji.name,image=img,reason="Stole from "+str(user))
except Forbidden as e: except Forbidden as e:
print("PermissionError - no permission to add emojis") print("PermissionError - no permission to add emojis")
raise PermissionError("No permission to add emojis") from e raise PermissionError("No permission to add emojis") from e
except HTTPException: except HTTPException:
print("Unhandled exception") print("HTTPException exception")
pass # Unhandled error raise HTTPException # Unhandled error
# If you get this far, YOU DID IT # If you get this far, YOU DID IT
owner = await self.bot.application_info() save_dict = self.default_stolemoji.copy()
owner = owner.owner e_dict = vars(emoji)
await owner.send("Just added emoji "+str(emoji)+" to server "+str(guildbank))
for k in e_dict:
if k in save_dict:
save_dict[k] = e_dict[k]
save_dict["guildbank"] = guildbank.id
async with self.config.stolemoji() as stolemoji:
stolemoji[emoji.id] = save_dict
#Enable the below if you want to get notified when it works
# owner = await self.bot.application_info()
# owner = owner.owner
# await owner.send("Just added emoji "+str(emoji)+" to server "+str(guildbank))
# add to config.stolemoji()?

Loading…
Cancel
Save