From 32b8f8062720acbde87fa8f8994993addb875a7c Mon Sep 17 00:00:00 2001 From: Steele Farnsworth Date: Sat, 1 Apr 2023 15:45:04 -0400 Subject: Ping help thread owner if thread closes without engagement. Add logic to see if anyone other than the OP (or bots) engaged in a help thread when it closes for inactivity. Currently only looks at the last 10 messages. If not, includes a ping to the OP before the embed in the closing message. --- bot/exts/help_channels/_channel.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index 670a10446..63a83c8fa 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -46,8 +46,19 @@ async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.C """Close the help post and record stats.""" embed = discord.Embed(description=CLOSED_POST_MSG) embed.set_author(name=f"{POST_TITLE} closed", icon_url=CLOSED_POST_ICON_URL) - - await closed_post.send(embed=embed) + message = '' + + # Include a ping in the close message if no one else engages, to encourage them + # to read the guide for asking better questions + if closing_reason == _stats.ClosingReason.INACTIVE and closed_post.owner is not None: + participant_ids = { + message.author.id async for message in closed_post.history(limit=10, oldest_first=False) + if not message.author.bot + } + if participant_ids == {closed_post.owner_id}: + message += closed_post.owner.mention + + await closed_post.send(message, embed=embed) await closed_post.edit(archived=True, locked=True, reason="Locked a closed help post") _stats.report_post_count() -- cgit v1.2.3 From e7b393bea0ed258941b938764bd1ff6967321cfc Mon Sep 17 00:00:00 2001 From: Steele Farnsworth Date: Tue, 4 Apr 2023 19:02:54 -0400 Subject: Add warning not to pip install unrelated packages. This is in response to recent attacks where the attacker DMs someone who opens a thread and tells the thread opener to pip install a malicious package under the false pretense that it will solve their problem. The warning replaces "For more tips, check out our guide on asking good questions", which is stated in the thread closer embed. --- bot/exts/help_channels/_channel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index 63a83c8fa..fff93dff1 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -17,13 +17,13 @@ ASKING_GUIDE_URL = "https://pythondiscord.com/pages/asking-good-questions/" BRANDING_REPO_RAW_URL = "https://raw.githubusercontent.com/python-discord/branding" POST_TITLE = "Python help channel" -NEW_POST_MSG = f""" +NEW_POST_MSG = """ **Remember to:** • **Ask** your Python question, not if you can ask or if there's an expert who can help. • **Show** a code sample as text (rather than a screenshot) and the error message, if you've got one. • **Explain** what you expect to happen and what actually happens. -For more tips, check out our guide on [asking good questions]({ASKING_GUIDE_URL}). +:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs. """ NEW_POST_FOOTER = f"Closes after a period of inactivity, or when you send {constants.Bot.prefix}close." NEW_POST_ICON_URL = f"{BRANDING_REPO_RAW_URL}/main/icons/checkmark/green-checkmark-dist.png" @@ -86,7 +86,7 @@ async def send_opened_post_message(post: discord.Thread) -> None: ) embed.set_author(name=f"{POST_TITLE} opened", icon_url=NEW_POST_ICON_URL) embed.set_footer(text=NEW_POST_FOOTER) - await post.send(embed=embed) + await post.send(embed=embed, content=post.owner.mention) async def send_opened_post_dm(post: discord.Thread) -> None: -- cgit v1.2.3 From 2ebf6c823a8a9d8af8e9c56ac7534fbeda327c7e Mon Sep 17 00:00:00 2001 From: Steele Farnsworth Date: Fri, 7 Apr 2023 11:18:00 -0400 Subject: Increase search history from 10 messages to 100. 100 is the maximum number that can be received in one request, so we may as well use that many. Also change a string `+=` to `=`. --- bot/exts/help_channels/_channel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index fff93dff1..b1a319145 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -52,11 +52,11 @@ async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.C # to read the guide for asking better questions if closing_reason == _stats.ClosingReason.INACTIVE and closed_post.owner is not None: participant_ids = { - message.author.id async for message in closed_post.history(limit=10, oldest_first=False) + message.author.id async for message in closed_post.history(limit=100, oldest_first=False) if not message.author.bot } if participant_ids == {closed_post.owner_id}: - message += closed_post.owner.mention + message = closed_post.owner.mention await closed_post.send(message, embed=embed) await closed_post.edit(archived=True, locked=True, reason="Locked a closed help post") -- cgit v1.2.3