aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-02-23 02:46:03 -0800
committerGravatar GitHub <[email protected]>2021-02-23 02:46:03 -0800
commita43b11b3cf431cf358fff8a581276afa25fb3508 (patch)
treeaac8969c16934b533e484812568d29ee33541214
parentUpdate max available channels to 3 (diff)
parentUse textwrap.shorten instead of custom function (diff)
Merge pull request #1429 from python-discord/dm-on-open-help-channel
DM on open help channel
-rw-r--r--bot/constants.py1
-rw-r--r--bot/exts/help_channels/_cog.py1
-rw-r--r--bot/exts/help_channels/_message.py35
-rw-r--r--config-default.yml1
4 files changed, 38 insertions, 0 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 8a93ff9cf..69bc82b89 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -326,6 +326,7 @@ class Icons(metaclass=YAMLGetter):
filtering: str
green_checkmark: str
+ green_questionmark: str
guild_update: str
hash_blurple: str
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 0995c8a79..a18ddc900 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -102,6 +102,7 @@ class HelpChannels(commands.Cog):
await _cooldown.revoke_send_permissions(message.author, self.scheduler)
await _message.pin(message)
+ await _message.dm_on_open(message)
# Add user with channel for dormant check.
await _caches.claimants.set(message.channel.id, message.author.id)
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index 2bbd4bdd6..4113e51c5 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -1,4 +1,5 @@
import logging
+import textwrap
import typing as t
from datetime import datetime
@@ -92,6 +93,40 @@ 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=textwrap.shorten(message.content, width=100, placeholder="..."),
+ inline=False,
+ )
+ embed.add_field(
+ name="Conversation",
+ 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.
diff --git a/config-default.yml b/config-default.yml
index 8e9a29a51..7d9afaa0e 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -90,6 +90,7 @@ style:
filtering: "https://cdn.discordapp.com/emojis/472472638594482195.png"
green_checkmark: "https://raw.githubusercontent.com/python-discord/branding/master/icons/checkmark/green-checkmark-dist.png"
+ green_questionmark: "https://raw.githubusercontent.com/python-discord/branding/master/icons/checkmark/green-question-mark-dist.png"
guild_update: "https://cdn.discordapp.com/emojis/469954765141442561.png"
hash_blurple: "https://cdn.discordapp.com/emojis/469950142942806017.png"