aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Den4200 <[email protected]>2021-03-28 13:19:40 -0400
committerGravatar Den4200 <[email protected]>2021-03-28 13:21:32 -0400
commit39d71b578b5f1cfaae2acd01743f8b7522e2c490 (patch)
treec4c2981d207edaca069742b85c6706cd70949cc3
parentMerge remote-tracking branch 'refs/remotes/origin/feat/dmrelay' into feat/dmr... (diff)
Reduce API calls in `!dmrelay`.
-rw-r--r--bot/exts/moderation/dm_relay.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/bot/exts/moderation/dm_relay.py b/bot/exts/moderation/dm_relay.py
index cc63a80fe..a03230b3d 100644
--- a/bot/exts/moderation/dm_relay.py
+++ b/bot/exts/moderation/dm_relay.py
@@ -22,22 +22,11 @@ class DMRelay(Cog):
"""Relays the direct message history between the bot and given user."""
log.trace(f"Relaying DMs with {user.name} ({user.id})")
- if self.bot.user == user:
- await ctx.send(f"{Emojis.cross_mark} No direct message history with myself.")
+ if user.bot:
+ await ctx.send(f"{Emojis.cross_mark} No direct message history with bots.")
return
- # Force cache to update
- await user.history(limit=1).flatten()
-
- if not user.dm_channel:
- await ctx.send(f"{Emojis.cross_mark} No direct message history with {user.mention}.")
- return
-
- output = textwrap.dedent(f"""\
- User: {user} ({user.id})
- Channel ID: {user.dm_channel.id}\n
- """)
-
+ output = ""
async for msg in user.history(limit=limit, oldest_first=True):
created_at = msg.created_at.strftime(r"%Y-%m-%d %H:%M")
@@ -57,7 +46,16 @@ class DMRelay(Cog):
if attachments:
output += attachments + "\n"
- paste_link = await send_to_paste_service(output, extension="txt")
+ if not output:
+ await ctx.send(f"{Emojis.cross_mark} No direct message history with {user.mention}.")
+ return
+
+ metadata = textwrap.dedent(f"""\
+ User: {user} ({user.id})
+ Channel ID: {user.dm_channel.id}\n
+ """)
+
+ paste_link = await send_to_paste_service(metadata + output, extension="txt")
await ctx.send(paste_link)
async def cog_check(self, ctx: Context) -> bool: