[V3 Report] Patch issue with attachment grabbing (#1822)

* This fixes the issue on report's side

* This prevents delete_delay from causing future issues where message objects are needed

* black format pass

* use the tools we have to clean this logic up a lot
This commit is contained in:
Michael H 2018-06-08 21:08:00 -04:00 committed by Will
parent d5f5ddbec5
commit 49b80e9fe3
2 changed files with 23 additions and 19 deletions

View File

@ -1440,7 +1440,13 @@ class Mod:
return True
return False
async def on_command(self, ctx: commands.Context):
async def on_command_completion(self, ctx: commands.Context):
await self._delete_delay(ctx)
async def on_command_error(self, ctx: commands.Context, error):
await self._delete_delay(ctx)
async def _delete_delay(self, ctx: commands.Context):
"""Currently used for:
* delete delay"""
guild = ctx.guild

View File

@ -212,11 +212,6 @@ class Reports:
guild = await self.discover_guild(
author, prompt=_("Select a server to make a report in by number.")
)
else:
try:
await ctx.message.delete()
except discord.Forbidden:
pass
if guild is None:
return
g_active = await self.config.guild(guild).active()
@ -234,17 +229,10 @@ class Reports:
"later."
)
)
if author.id in self.user_cache:
return await author.send(
_("Please finish making your prior report before making an additional one")
)
if ctx.guild:
try:
await ctx.message.delete()
except (discord.Forbidden, discord.HTTPException):
pass
self.user_cache.append(author.id)
if _report:
@ -261,9 +249,7 @@ class Reports:
)
)
except discord.Forbidden:
await ctx.send(_("This requires DMs enabled."))
self.user_cache.remove(author.id)
return
return await ctx.send(_("This requires DMs enabled."))
def pred(m):
return m.author == author and m.channel == dm.channel
@ -271,7 +257,7 @@ class Reports:
try:
message = await self.bot.wait_for("message", check=pred, timeout=180)
except asyncio.TimeoutError:
await author.send(_("You took too long. Try again later."))
return await author.send(_("You took too long. Try again later."))
else:
val = await self.send_report(message, guild)
@ -282,7 +268,19 @@ class Reports:
await author.send(_("Your report was submitted. (Ticket #{})").format(val))
self.antispam[guild.id][author.id].stamp()
self.user_cache.remove(author.id)
@report.after_invoke
async def report_cleanup(self, ctx: commands.Context):
"""
The logic is cleaner this way
"""
if ctx.author.id in self.user_cache:
self.user_cache.remove(ctx.author.id)
if ctx.guild and ctx.invoked_subcommand is None:
if ctx.channel.permissions_for(ctx.guild.me).manage_messages:
try:
await ctx.message.delete()
except discord.NotFound:
pass
async def on_raw_reaction_add(self, payload):
"""