|
|
@ -1,13 +1,9 @@
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import aiohttp
|
|
|
|
|
|
|
|
import discord
|
|
|
|
import discord
|
|
|
|
from aiohttp.typedefs import StrOrURL
|
|
|
|
from redbot.core import Config, checks, commands
|
|
|
|
from redbot.core import Config, commands, checks
|
|
|
|
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
|
|
|
|
|
|
|
|
from redbot.core.commands import Cog
|
|
|
|
from redbot.core.commands import Cog
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Replaced with discord.Asset.read()
|
|
|
|
# Replaced with discord.Asset.read()
|
|
|
|
# async def fetch_img(session: aiohttp.ClientSession, url: StrOrURL):
|
|
|
|
# async def fetch_img(session: aiohttp.ClientSession, url: StrOrURL):
|
|
|
|
# async with session.get(url) as response:
|
|
|
|
# async with session.get(url) as response:
|
|
|
@ -50,6 +46,8 @@ class StealEmoji(Cog):
|
|
|
|
|
|
|
|
|
|
|
|
self.config.register_global(**default_global)
|
|
|
|
self.config.register_global(**default_global)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.is_on = await self.config.on()
|
|
|
|
|
|
|
|
|
|
|
|
@commands.group()
|
|
|
|
@commands.group()
|
|
|
|
async def stealemoji(self, ctx: commands.Context):
|
|
|
|
async def stealemoji(self, ctx: commands.Context):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -86,6 +84,9 @@ class StealEmoji(Cog):
|
|
|
|
"""Toggles whether emoji's are collected or not"""
|
|
|
|
"""Toggles whether emoji's are collected or not"""
|
|
|
|
curr_setting = await self.config.on()
|
|
|
|
curr_setting = await self.config.on()
|
|
|
|
await self.config.on.set(not curr_setting)
|
|
|
|
await self.config.on.set(not curr_setting)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.is_on = await self.config.on()
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.send("Collection is now " + str(not curr_setting))
|
|
|
|
await ctx.send("Collection is now " + str(not curr_setting))
|
|
|
|
|
|
|
|
|
|
|
|
@checks.is_owner()
|
|
|
|
@checks.is_owner()
|
|
|
@ -138,13 +139,13 @@ class StealEmoji(Cog):
|
|
|
|
# print("Not a custom emoji")
|
|
|
|
# print("Not a custom emoji")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if not (await self.config.on()): # TODO: Make this cached
|
|
|
|
if not self.is_on:
|
|
|
|
print("Collecting is off")
|
|
|
|
# print("Collecting is off")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
emoji: discord.Emoji = reaction.emoji
|
|
|
|
emoji: discord.Emoji = reaction.emoji
|
|
|
|
if emoji in self.bot.emojis:
|
|
|
|
if emoji in self.bot.emojis:
|
|
|
|
print("Emoji already in 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
|
|
|
@ -160,18 +161,24 @@ class StealEmoji(Cog):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if guildbank is None:
|
|
|
|
if guildbank is None:
|
|
|
|
print("No guildbank to store emoji")
|
|
|
|
# print("No guildbank to store emoji")
|
|
|
|
# Eventually make a new banklist
|
|
|
|
# Eventually make a new banklist
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Next, have I saved this emoji before (because uploaded emoji != orignal emoji)
|
|
|
|
# Next, have I saved this emoji before (because uploaded emoji != orignal emoji)
|
|
|
|
|
|
|
|
|
|
|
|
stolemojis = await self.config.stolemoji()
|
|
|
|
if str(emoji.id) in await self.config.stolemoji():
|
|
|
|
|
|
|
|
# print("Emoji has already been stolen")
|
|
|
|
if emoji.id in stolemojis: # TODO: This is not preventing duplicates
|
|
|
|
|
|
|
|
print("Emoji has already been stolen")
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# stolemojis = await self.config.stolemoji()
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# print(stolemojis.keys())
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if emoji.id in stolemojis:
|
|
|
|
|
|
|
|
# print("Emoji has already been stolen")
|
|
|
|
|
|
|
|
# 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]
|
|
|
@ -192,10 +199,10 @@ class StealEmoji(Cog):
|
|
|
|
name=emoji.name, image=img, reason="Stole from " + str(user)
|
|
|
|
name=emoji.name, image=img, reason="Stole from " + str(user)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except discord.Forbidden as e:
|
|
|
|
except discord.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 discord.HTTPException as e:
|
|
|
|
except discord.HTTPException as e:
|
|
|
|
print("HTTPException exception")
|
|
|
|
# print("HTTPException exception")
|
|
|
|
raise e # Unhandled error
|
|
|
|
raise e # Unhandled error
|
|
|
|
|
|
|
|
|
|
|
|
# If you get this far, YOU DID IT
|
|
|
|
# If you get this far, YOU DID IT
|
|
|
|