Skip to content

Commit 09ab796

Browse files
IsaacGiHiD
andauthored
Add thread reminders (#118)
Add thread reminders. Co-authored-by: Jeremy Walker <[email protected]>
1 parent f0ee7f5 commit 09ab796

5 files changed

+83
-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

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Discord Cog to remind people to use threads."""
2+
3+
import logging
4+
from typing import cast
5+
6+
import discord
7+
import prometheus_client # type: ignore
8+
from discord.ext import commands
9+
10+
from cogs import base_cog
11+
12+
logger = logging.getLogger(__name__)
13+
14+
TITLE = "Reminder: Please Use Threads"
15+
REMINDER = (
16+
"Hi there 👋\n"
17+
"You just replied to a message in the main channel, rather than in a thread. "
18+
"We're quite strict on using threads to keep things tidy in this channel. "
19+
"Please could you copy/paste your message to a thread, "
20+
"and delete the message from the main channel.\n"
21+
"Thank you! 🙂"
22+
)
23+
DURATION = 120
24+
25+
26+
class ThreadReminder(base_cog.BaseCog):
27+
"""Reminds people using "reply to" to use threads."""
28+
29+
qualified_name = TITLE
30+
31+
def __init__(
32+
self,
33+
*,
34+
channels: list[int],
35+
**kwargs,
36+
) -> None:
37+
super().__init__(**kwargs)
38+
self.channels = channels
39+
self.prom_counter = prometheus_client.Counter(
40+
"thread_reminder", "How many times thread reminder was triggered."
41+
)
42+
43+
@commands.Cog.listener()
44+
async def on_message(self, message: discord.Message) -> None:
45+
"""React to non-threaded responses with a reminder."""
46+
channel = message.channel
47+
if message.author.bot or message.reference is None:
48+
return
49+
if channel is None or channel.type != discord.ChannelType.text:
50+
return
51+
if channel.id not in self.channels:
52+
return
53+
54+
self.usage_stats[message.author.display_name] += 1
55+
self.prom_counter.inc()
56+
typed_channel = cast(discord.TextChannel, channel)
57+
thread = await typed_channel.create_thread(name=TITLE, auto_archive_duration=60)
58+
content = f"{message.author.mention} {REMINDER}\n\n{message.jump_url}"
59+
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)