[V3 AntiPhoneClapper] Add unload, formatting
This commit is contained in:
@@ -10,8 +10,10 @@ BaseCog = getattr(commands, "Cog", object)
|
||||
|
||||
class AntiPhoneClapper(BaseCog):
|
||||
"""This cog deletes bad GIFs that will crash phone clients."""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.session = aiohttp.ClientSession()
|
||||
self.config = Config.get_conf(self, 2719371001, force_registration=True)
|
||||
|
||||
default_guild = {"watching": []}
|
||||
@@ -53,7 +55,9 @@ class AntiPhoneClapper(BaseCog):
|
||||
else:
|
||||
return await ctx.send("Channel is not being watched.")
|
||||
await self.config.guild(ctx.guild).watching.set(channel_list)
|
||||
await ctx.send(f"{self.bot.get_channel(channel.id).mention} will not have bad gifs removed.")
|
||||
await ctx.send(
|
||||
f"{self.bot.get_channel(channel.id).mention} will not have bad gifs removed."
|
||||
)
|
||||
|
||||
def is_phone_clapper(self, im):
|
||||
limit = im.size
|
||||
@@ -75,10 +79,10 @@ class AntiPhoneClapper(BaseCog):
|
||||
return
|
||||
|
||||
for att in m.attachments:
|
||||
if not att.filename.endswith('.gif') or att.size > 200000:
|
||||
if not att.filename.endswith(".gif") or att.size > 200000:
|
||||
continue
|
||||
|
||||
async with aiohttp.ClientSession().get(att.url) as resp:
|
||||
async with self.session.get(att.url) as resp:
|
||||
data = await resp.content.read()
|
||||
f = BytesIO(data)
|
||||
try:
|
||||
@@ -90,11 +94,16 @@ class AntiPhoneClapper(BaseCog):
|
||||
if phone_clapper:
|
||||
try:
|
||||
await m.delete()
|
||||
await m.channel.send(f"{m.author.mention} just tried to send a phone-killing GIF and I removed it.")
|
||||
await m.channel.send(
|
||||
f"{m.author.mention} just tried to send a phone-killing GIF and I removed it."
|
||||
)
|
||||
return
|
||||
except discord.errors.Forbidden:
|
||||
await m.channel.send(f"Don't send GIFs that do that, {m.author.mention}")
|
||||
print(f'Failed to delete message ({m.id}) that contained phone killing gif')
|
||||
print(f"Failed to delete message ({m.id}) that contained phone killing gif")
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
def __unload(self):
|
||||
self.bot.loop.create_task(self.session.close())
|
||||
|
||||
Reference in New Issue
Block a user