Skip to content

Commit afa6b7f

Browse files
committed
Add thread reminders
1 parent f0ee7f5 commit afa6b7f

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

cogs/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from . import mod_message
66
from . import pinned_message
77
from . import streaming_events
8+
from . import threads_please
89
from . import track_react
910

1011
CloseSupportThread = close_support.CloseSupportThread
@@ -13,4 +14,5 @@
1314
ModMessage = mod_message.ModMessage
1415
PinnedMessage = pinned_message.PinnedMessage
1516
StreamingEvents = streaming_events.StreamingEvents
17+
ThreadReminder = threads_please.ThreadReminder
1618
TrackReact = track_react.TrackReact

cogs/mentor_requests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def update_track_requests(self, track: str) -> dict[str, str]:
9898
thread = got
9999
self.threads[track] = thread
100100

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

cogs/threads_please.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Discord Cog to remind people to use threads."""
2+
3+
import logging
4+
import re
5+
import string
6+
import time
7+
from typing import cast, Sequence
8+
9+
import discord
10+
import prometheus_client # type: ignore
11+
from discord.ext import commands
12+
13+
from cogs import base_cog
14+
15+
logger = logging.getLogger(__name__)
16+
17+
TITLE = "Reminder: Please Use Threads"
18+
REMINDER = "Please use threads in this channel. Rather than replying to a message, please create a thread."
19+
DURATION = 120
20+
21+
22+
class ThreadReminder(base_cog.BaseCog):
23+
"""Reminds people using "reply to" to use threads."""
24+
25+
qualified_name = TITLE
26+
27+
def __init__(
28+
self,
29+
*,
30+
channels: list[int],
31+
**kwargs,
32+
) -> None:
33+
super().__init__(**kwargs)
34+
self.channels = channels
35+
self.prom_counter = prometheus_client.Counter(
36+
"thread_reminder", "How many times thread reminder was triggered."
37+
)
38+
39+
@commands.Cog.listener()
40+
async def on_message(self, message: discord.Message) -> None:
41+
"""React to non-threaded responses with a reminder."""
42+
channel = message.channel
43+
if message.author.bot or message.reference is None:
44+
return
45+
if channel is None or channel.type != discord.ChannelType.text:
46+
return
47+
if channel.id not in self.channels:
48+
return
49+
50+
self.usage_stats[message.author.display_name] += 1
51+
self.prom_counter.inc()
52+
typed_channel = cast(discord.TextChannel, channel)
53+
thread = await typed_channel.create_thread(name=TITLE, auto_archive_duration=60)
54+
content = f"{message.author.mention} {REMINDER}\n\n{message.jump_url}"
55+
await thread.send(content=content, suppress_embeds=True)

conf.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
"""Configuration values for Exercism Cogs."""
22
# pylint: disable=C0301
3+
4+
CHANNEL_ID = {
5+
"Exercism #photos": 1203795616594010192,
6+
"Exercism #programming": 1157359032760287302,
7+
"Exercism #bootcamp-signup-questions": 1314074955880857731,
8+
"test": 1091223069407842306,
9+
}
310
# General
411

512
GUILD_ID = 854117591135027261
@@ -141,21 +148,27 @@
141148
# Test channel in test server.
142149
1091223069407842306: "This is a pinned message.",
143150
# Exercism #photo channel
144-
1203795616594010192: """\
151+
CHANNEL_ID["Exercism #photos"]: """\
145152
> **📸 Pinned Reminder 📸**
146-
> Use this channel to share photos of your pets, family, art, or anything else that is meaningful to you.
153+
> Use this channel to share photos you took of your pets, family, art, or anything else that is meaningful to you.
147154
> If someone else's photo catches your eye, please use threads to discuss.
148155
> Thank you for being part of our Exercism community!""",
149156
1326564185643024394: """\
150157
> **Pinned Reminder**
151158
> 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!""",
152159
# Exercism #programming
153-
1157359032760287302: """\
160+
CHANNEL_ID["Exercism #programming"]: """\
154161
> ** Pinned Reminder **
155162
> 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!""",
156-
# Exercism #bootcamp-signup-questions
157-
1314074955880857731: """\
163+
# Exercism
164+
CHANNEL_ID["Exercism #bootcamp-signup-questions"]: """\
158165
> ** Pinned Reminder **
159166
> If you're missing the #bootcamp role/color/channel, please double check you synced your Exercism account to Discord.
160167
> See <https://exercism.org/settings/integrations>. If you are synced and it still doesn't work, try unlinking and relinking :slight_smile:""",
161168
}
169+
170+
THREAD_REMINDER_CHANNELS = [
171+
CHANNEL_ID["Exercism #photos"],
172+
CHANNEL_ID["Exercism #programming"],
173+
CHANNEL_ID["test"],
174+
]

exercism_discord_bot.py

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def get_cogs(self) -> dict[commands.CogMeta, dict[str, Any]]:
114114
"default_location_url": conf.DEFAULT_STREAMING_URL,
115115
"sqlite_db": find_setting("SQLITE_DB"),
116116
},
117+
cogs.ThreadReminder: {
118+
"channels": conf.THREAD_REMINDER_CHANNELS,
119+
},
117120
cogs.TrackReact: {
118121
"aliases": conf.ALIASES,
119122
"case_sensitive": conf.CASE_SENSITIVE,

0 commit comments

Comments
 (0)