aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-07-15 10:15:08 +0200
committerGravatar GitHub <[email protected]>2020-07-15 10:15:08 +0200
commit90d2a77becb39d6b3c0056ea7c05b4a9e4d16f50 (patch)
tree76858d09e04d55a8f4d366c7ab98b4cde778d753
parentAdd some stats for DMs sent and received. (diff)
Ves' refactor
Co-authored-by: Sebastiaan Zeeff <[email protected]>
-rw-r--r--bot/cogs/dm_relay.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/bot/cogs/dm_relay.py b/bot/cogs/dm_relay.py
index edfcccf6d..0c3eddf42 100644
--- a/bot/cogs/dm_relay.py
+++ b/bot/cogs/dm_relay.py
@@ -41,23 +41,24 @@ class DMRelay(Cog):
NOTE: This feature will be removed if it is overused.
"""
- user_id = await self.dm_cache.get("last_user")
- last_dm_user = ctx.guild.get_member(user_id) if user_id else None
+ if not member:
+ user_id = await self.dm_cache.get("last_user")
+ member = ctx.guild.get_member(user_id) if user_id else None
+
+ # If we still don't have a Member at this point, give up
+ if not member:
+ log.debug("This bot has never gotten a DM, or the RedisCache has been cleared.")
+ await ctx.message.add_reaction("❌")
+ return
try:
- if member:
- await member.send(message)
- await ctx.message.add_reaction("✅")
- self.bot.stats.incr("dm_relay.dm_sent")
- return
- elif last_dm_user:
- await last_dm_user.send(message)
- await ctx.message.add_reaction("✅")
- self.bot.stats.incr("dm_relay.dm_sent")
- return
- else:
- log.debug("This bot has never gotten a DM, or the RedisCache has been cleared.")
- await ctx.message.add_reaction("❌")
+ await member.send(message)
+ except discord.errors.Forbidden:
+ log.debug("User has disabled DMs.")
+ await ctx.message.add_reaction("❌")
+ else:
+ await ctx.message.add_reaction("✅")
+ self.bot.stats.incr("dm_relay.dm_sent")
except discord.errors.Forbidden:
log.debug("User has disabled DMs.")
await ctx.message.add_reaction("❌")