Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread reminders #118

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import mod_message
from . import pinned_message
from . import streaming_events
from . import threads_please
from . import track_react

CloseSupportThread = close_support.CloseSupportThread
Expand All @@ -13,4 +14,5 @@
ModMessage = mod_message.ModMessage
PinnedMessage = pinned_message.PinnedMessage
StreamingEvents = streaming_events.StreamingEvents
ThreadReminder = threads_please.ThreadReminder
TrackReact = track_react.TrackReact
2 changes: 1 addition & 1 deletion cogs/mentor_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def update_track_requests(self, track: str) -> dict[str, str]:
thread = got
self.threads[track] = thread

async with asyncio.timeout(10):
async with asyncio.timeout(15):
requests = await self.get_requests(track)
logger.debug("Found %d requests for %s.", len(requests), track)

Expand Down
58 changes: 58 additions & 0 deletions cogs/threads_please.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Discord Cog to remind people to use threads."""

import logging
from typing import cast

import discord
import prometheus_client # type: ignore
from discord.ext import commands

from cogs import base_cog

logger = logging.getLogger(__name__)

TITLE = "Reminder: Please Use Threads"
REMINDER = (
"Hi there 👋"
"You just replied to a message in the main channel, rather than in a thread."
"We're quite strict on using threads to keep things tidy in this channel."
"Please could you copy/paste your message to a thread, and delete the message from the main channel."
"Thank you! 🙂"
)
DURATION = 120


class ThreadReminder(base_cog.BaseCog):
"""Reminds people using "reply to" to use threads."""

qualified_name = TITLE

def __init__(
self,
*,
channels: list[int],
**kwargs,
) -> None:
super().__init__(**kwargs)
self.channels = channels
self.prom_counter = prometheus_client.Counter(
"thread_reminder", "How many times thread reminder was triggered."
)

@commands.Cog.listener()
async def on_message(self, message: discord.Message) -> None:
"""React to non-threaded responses with a reminder."""
channel = message.channel
if message.author.bot or message.reference is None:
return
if channel is None or channel.type != discord.ChannelType.text:
return
if channel.id not in self.channels:
return

self.usage_stats[message.author.display_name] += 1
self.prom_counter.inc()
typed_channel = cast(discord.TextChannel, channel)
thread = await typed_channel.create_thread(name=TITLE, auto_archive_duration=60)
content = f"{message.author.mention} {REMINDER}\n\n{message.jump_url}"
await thread.send(content=content, suppress_embeds=True)
23 changes: 18 additions & 5 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Configuration values for Exercism Cogs."""
# pylint: disable=C0301

CHANNEL_ID = {
"Exercism #photos": 1203795616594010192,
"Exercism #programming": 1157359032760287302,
"Exercism #bootcamp-signup-questions": 1314074955880857731,
"test": 1091223069407842306,
}
# General

GUILD_ID = 854117591135027261
Expand Down Expand Up @@ -141,21 +148,27 @@
# Test channel in test server.
1091223069407842306: "This is a pinned message.",
# Exercism #photo channel
1203795616594010192: """\
CHANNEL_ID["Exercism #photos"]: """\
> **📸 Pinned Reminder 📸**
> Use this channel to share photos of your pets, family, art, or anything else that is meaningful to you.
> Use this channel to share photos you took of your pets, family, art, or anything else that is meaningful to you.
> If someone else's photo catches your eye, please use threads to discuss.
> Thank you for being part of our Exercism community!""",
1326564185643024394: """\
> **Pinned Reminder**
> To keep things tidy in this channel, please remember to use threads when replying to people's posts. You can start a thread by hovering over the message you want to reply to, clicking on the `...` and then on "Create Thread". Thanks!""",
# Exercism #programming
1157359032760287302: """\
CHANNEL_ID["Exercism #programming"]: """\
> ** Pinned Reminder **
> To keep things tidy in this channel, please remember to use threads when replying to people's posts. You can start a thread by hovering over the message you want to reply to, clicking on the `...` and then on "Create Thread". Thanks!""",
# Exercism #bootcamp-signup-questions
1314074955880857731: """\
# Exercism
CHANNEL_ID["Exercism #bootcamp-signup-questions"]: """\
> ** Pinned Reminder **
> If you're missing the #bootcamp role/color/channel, please double check you synced your Exercism account to Discord.
> See <https://exercism.org/settings/integrations>. If you are synced and it still doesn't work, try unlinking and relinking :slight_smile:""",
}

THREAD_REMINDER_CHANNELS = [
CHANNEL_ID["Exercism #photos"],
CHANNEL_ID["Exercism #programming"],
CHANNEL_ID["test"],
]
3 changes: 3 additions & 0 deletions exercism_discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def get_cogs(self) -> dict[commands.CogMeta, dict[str, Any]]:
"default_location_url": conf.DEFAULT_STREAMING_URL,
"sqlite_db": find_setting("SQLITE_DB"),
},
cogs.ThreadReminder: {
"channels": conf.THREAD_REMINDER_CHANNELS,
},
cogs.TrackReact: {
"aliases": conf.ALIASES,
"case_sensitive": conf.CASE_SENSITIVE,
Expand Down
Loading