aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-03-24 22:32:54 +0000
committerGravatar Chris Lovering <[email protected]>2024-03-26 15:27:54 +0000
commit6c37f6d59543b213af665749f0ef241493383ac3 (patch)
tree7fb2f47c691b764a3170625c85f98407ff82de9d
parentMerge pull request #2669 from python-discord/phishing_button (diff)
Remove the help-dm feature
This feature allowed users to opt-in to getting DMs from the bot whenever someone messaged in a help channel they we participating in. This was useful in the old channel-based help system as it was hard to remember which channels you were participating in. Now that we've moved over to the forum channel, this is no longer an issue, as posts you are participating in now appear in the channel list, and others don't.
-rw-r--r--bot/exts/help_channels/_caches.py9
-rw-r--r--bot/exts/help_channels/_cog.py28
-rw-r--r--bot/exts/help_channels/_message.py73
3 files changed, 1 insertions, 109 deletions
diff --git a/bot/exts/help_channels/_caches.py b/bot/exts/help_channels/_caches.py
index 3369fc0a6..ef7b3887f 100644
--- a/bot/exts/help_channels/_caches.py
+++ b/bot/exts/help_channels/_caches.py
@@ -1,14 +1,5 @@
from async_rediscache import RedisCache
-# This cache keeps track of who has help-dms on.
-# RedisCache[discord.User.id, bool]
-help_dm = RedisCache(namespace="HelpChannels.help_dm")
-
-# This cache tracks member who are participating and opted in to help channel dms.
-# serialise the set as a comma separated string to allow usage with redis
-# RedisCache[discord.TextChannel.id, str[set[discord.User.id]]]
-session_participants = RedisCache(namespace="HelpChannels.session_participants")
-
# Stores posts that have had a non-claimant, non-bot, reply.
# Currently only used to determine whether the post was answered or not when collecting stats.
posts_with_non_claimant_messages = RedisCache(namespace="HelpChannels.posts_with_non_claimant_messages")
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index c70ce4e71..59a95ab6a 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -6,7 +6,7 @@ from pydis_core.utils import scheduling
from bot import constants
from bot.bot import Bot
-from bot.exts.help_channels import _caches, _channel, _message
+from bot.exts.help_channels import _caches, _channel
from bot.log import get_logger
from bot.utils.checks import has_any_role_check
@@ -87,30 +87,6 @@ class HelpForum(commands.Cog):
if ctx.channel.id in self.scheduler:
self.scheduler.cancel(ctx.channel.id)
- @help_forum_group.command(name="dm", root_aliases=("helpdm",))
- async def help_dm_command(
- self,
- ctx: commands.Context,
- state_bool: bool,
- ) -> None:
- """
- Allows user to toggle "Helping" DMs.
-
- If this is set to on the user will receive a dm for the channel they are participating in.
- If this is set to off the user will not receive a dm for channel that they are participating in.
- """
- state_str = "ON" if state_bool else "OFF"
-
- if state_bool == await _caches.help_dm.get(ctx.author.id, False):
- await ctx.send(f"{constants.Emojis.cross_mark} {ctx.author.mention} Help DMs are already {state_str}")
- return
-
- if state_bool:
- await _caches.help_dm.set(ctx.author.id, True)
- else:
- await _caches.help_dm.delete(ctx.author.id)
- await ctx.send(f"{constants.Emojis.ok_hand} {ctx.author.mention} Help DMs {state_str}!")
-
@help_forum_group.command(name="title", root_aliases=("title",))
async def rename_help_post(self, ctx: commands.Context, *, title: str) -> None:
"""Rename the help post to the provided title."""
@@ -167,7 +143,5 @@ class HelpForum(commands.Cog):
if not _channel.is_help_forum_post(message.channel):
return
- await _message.notify_session_participants(message)
-
if not message.author.bot and message.author.id != message.channel.owner_id:
await _caches.posts_with_non_claimant_messages.set(message.channel.id, "sentinel")
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
deleted file mode 100644
index aa6e52340..000000000
--- a/bot/exts/help_channels/_message.py
+++ /dev/null
@@ -1,73 +0,0 @@
-from operator import attrgetter
-
-import discord
-
-import bot
-from bot import constants
-from bot.exts.help_channels import _caches
-from bot.log import get_logger
-from bot.utils import lock
-
-log = get_logger(__name__)
-NAMESPACE = "help"
-
-
-def _serialise_session_participants(participants: set[int]) -> str:
- """Convert a set to a comma separated string."""
- return ",".join(str(p) for p in participants)
-
-
-def _deserialise_session_participants(s: str) -> set[int]:
- """Convert a comma separated string into a set."""
- return set(int(user_id) for user_id in s.split(",") if user_id != "")
-
-
[email protected]_arg(NAMESPACE, "message", attrgetter("channel.id"))
[email protected]_arg(NAMESPACE, "message", attrgetter("author.id"))
-async def notify_session_participants(message: discord.Message) -> None:
- """
- Check if the message author meets the requirements to be notified.
-
- If they meet the requirements they are notified.
- """
- if message.channel.owner_id == message.author.id:
- return # Ignore messages sent by claimants
-
- if not await _caches.help_dm.get(message.author.id):
- return # Ignore message if user is opted out of help dms
-
- session_participants = _deserialise_session_participants(
- await _caches.session_participants.get(message.channel.id) or "",
- )
-
- if message.author.id not in session_participants:
- session_participants.add(message.author.id)
-
- embed = discord.Embed(
- title="Currently Helping",
- description=f"You're currently helping in {message.channel.mention}",
- color=constants.Colours.bright_green,
- timestamp=message.created_at,
- )
- embed.add_field(name="Conversation", value=f"[Jump to message]({message.jump_url})")
-
- try:
- await message.author.send(embed=embed)
- except discord.Forbidden:
- log.trace(
- f"Failed to send help dm message to {message.author.id}. DMs Closed/Blocked. "
- "Removing user from help dm."
- )
- await _caches.help_dm.delete(message.author.id)
- bot_commands_channel = bot.instance.get_channel(constants.Channels.bot_commands)
- await bot_commands_channel.send(
- f"{message.author.mention} {constants.Emojis.cross_mark} "
- "To receive updates on help channels you're active in, enable your DMs.",
- delete_after=constants.RedirectOutput.delete_delay,
- )
- return
-
- await _caches.session_participants.set(
- message.channel.id,
- _serialise_session_participants(session_participants),
- )