aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gustav Odinger <[email protected]>2021-02-23 04:00:01 +0100
committerGravatar Gustav Odinger <[email protected]>2021-02-23 04:00:01 +0100
commite1d269d82eed8a01d3d3b0ff33d05e3c79324007 (patch)
tree8f2ae11debc8cc487c7f134c5a56d7f77e6c3838
parentAdd truncate_message util (diff)
Add function to DM users when opening help channel
-rw-r--r--bot/exts/help_channels/_message.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index 2bbd4bdd6..12ac4035d 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -8,6 +8,7 @@ import bot
from bot import constants
from bot.exts.help_channels import _caches
from bot.utils.channel import is_in_category
+from bot.utils.messages import truncate_message
log = logging.getLogger(__name__)
@@ -92,6 +93,38 @@ async def is_empty(channel: discord.TextChannel) -> bool:
return False
+async def dm_on_open(message: discord.Message) -> None:
+ """
+ DM claimant with a link to the claimed channel's first message, with a 100 letter preview of the message.
+
+ Does nothing if the user has DMs disabled.
+ """
+ embed = discord.Embed(
+ title="Help channel opened",
+ description=f"You claimed {message.channel.mention}.",
+ colour=bot.constants.Colours.bright_green,
+ timestamp=message.created_at,
+ )
+
+ embed.set_thumbnail(url=constants.Icons.green_questionmark)
+ embed.add_field(
+ name="Your message", value=truncate_message(message, limit=100), inline=False
+ )
+ embed.add_field(
+ name="Want to go there?",
+ value=f"[Jump to message!]({message.jump_url})",
+ inline=False,
+ )
+
+ try:
+ await message.author.send(embed=embed)
+ log.trace(f"Sent DM to {message.author.id} after claiming help channel.")
+ except discord.errors.Forbidden:
+ log.trace(
+ f"Ignoring to send DM to {message.author.id} after claiming help channel: DMs disabled."
+ )
+
+
async def notify(channel: discord.TextChannel, last_notification: t.Optional[datetime]) -> t.Optional[datetime]:
"""
Send a message in `channel` notifying about a lack of available help channels.