Skip to content

Commit

Permalink
[V3 Report] Patch issue with attachment grabbing (#1822)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Michael H authored and tekulvw committed Jun 9, 2018
1 parent d5f5ddb commit 49b80e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
8 changes: 7 additions & 1 deletion redbot/cogs/mod/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,13 @@ async def check_mention_spam(self, message):
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
Expand Down
34 changes: 16 additions & 18 deletions redbot/cogs/reports/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ async def report(self, ctx: commands.Context, *, _report: str = ""):
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()
Expand All @@ -234,17 +229,10 @@ async def report(self, ctx: commands.Context, *, _report: str = ""):
"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:
Expand All @@ -261,17 +249,15 @@ async def report(self, ctx: commands.Context, *, _report: str = ""):
)
)
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

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)

Expand All @@ -280,9 +266,21 @@ def pred(m):
await author.send(_("There was an error sending your report."))
else:
await author.send(_("Your report was submitted. (Ticket #{})").format(val))
self.antispam[guild.id][author.id].stamp()
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):
"""
Expand Down

0 comments on commit 49b80e9

Please sign in to comment.