Skip to content

Commit bf20c56

Browse files
committed
More progress forum
1 parent 28b0edd commit bf20c56

File tree

1 file changed

+91
-7
lines changed

1 file changed

+91
-7
lines changed

techsupport_bot/commands/forum.py

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
"""The channel slowmode modification extension
1+
""" ""The channel slowmode modification extension
22
Holds only a single slash command"""
33

44
from __future__ import annotations
55

6+
import re
67
from typing import TYPE_CHECKING, Self
78

89
import discord
@@ -31,6 +32,23 @@ class ForumChannel(cogs.BaseCog):
3132
)
3233

3334
channel_id = "1288279278839926855"
35+
disallowed_title_patterns = [
36+
re.compile(
37+
r"^(?:I)?(?:\s)?(?:need|please I need|please|pls|plz)?(?:\s)?help(?:\s)?(?:me|please)?(?:\?|!)?$",
38+
re.IGNORECASE,
39+
),
40+
re.compile(r"^\S+$"), # Very short single-word titles
41+
re.compile(
42+
r"\b(it('?s)? not working|not working|issue|problem|error)\b", re.IGNORECASE
43+
),
44+
re.compile(r"\b(urgent|ASAP|quick help|fast)\b", re.IGNORECASE),
45+
re.compile(r"[!?]{3,}"), # Titles with excessive punctuation
46+
]
47+
48+
disallowed_body_patterns = [
49+
re.compile(r"^.{0,14}$"), # Bodies shorter than 15 characters
50+
re.compile(r"^(\[[^\]]*\])?https?://\S+$"), # Only links in the body
51+
]
3452

3553
@forum_group.command(
3654
name="solved",
@@ -41,9 +59,19 @@ async def markSolved(self: Self, interaction: discord.Interaction) -> None:
4159
channel = await interaction.guild.fetch_channel(int(self.channel_id))
4260
if interaction.channel.parent == channel:
4361
if interaction.user != interaction.channel.owner:
44-
await interaction.response.send_message("You cannot do this")
62+
embed = discord.Embed(
63+
title="Permission Denied",
64+
description="You cannot do this",
65+
color=discord.Color.red(),
66+
)
67+
await interaction.response.send_message(embed=embed)
4568
return
46-
await interaction.response.send_message("Marked as solved")
69+
embed = discord.Embed(
70+
title="Thread Marked as Solved",
71+
description="This thread has been archived and locked.",
72+
color=discord.Color.green(),
73+
)
74+
await interaction.response.send_message(embed=embed)
4775
await interaction.channel.edit(
4876
name=f"[SOLVED] {interaction.channel.name}"[:100],
4977
archived=True,
@@ -53,7 +81,63 @@ async def markSolved(self: Self, interaction: discord.Interaction) -> None:
5381
@commands.Cog.listener()
5482
async def on_thread_create(self: Self, thread: discord.Thread) -> None:
5583
channel = await thread.guild.fetch_channel(int(self.channel_id))
56-
threads = channel.threads
57-
print(threads)
58-
if thread.parent == channel:
59-
await thread.send("HI")
84+
if thread.parent != channel:
85+
return
86+
87+
embed = discord.Embed(
88+
title="Thread Rejected",
89+
description="Your thread doesn't meet our posting requirements. Please make sure you have a descriptive title and good body.",
90+
color=discord.Color.red(),
91+
)
92+
93+
# Check if the thread title is disallowed
94+
if any(
95+
pattern.search(thread.name) for pattern in self.disallowed_title_patterns
96+
):
97+
await thread.send(embed=embed)
98+
await thread.edit(
99+
name=f"[REJECTED] {thread.name}"[:100],
100+
archived=True,
101+
locked=True,
102+
)
103+
return
104+
105+
# Check if the thread body is disallowed
106+
messages = [message async for message in thread.history(limit=5)]
107+
if messages:
108+
body = messages[-1].content
109+
if any(pattern.search(body) for pattern in self.disallowed_body_patterns):
110+
await thread.send(embed=embed)
111+
await thread.edit(
112+
name=f"[REJECTED] {thread.name}"[:100],
113+
archived=True,
114+
locked=True,
115+
)
116+
return
117+
118+
# Check if the thread creator has an existing open thread
119+
for existing_thread in channel.threads:
120+
if (
121+
existing_thread.owner_id == thread.owner_id
122+
and not existing_thread.archived
123+
and existing_thread.id != thread.id
124+
):
125+
embed = discord.Embed(
126+
title="Duplicate Thread Detected",
127+
description="You already have an open thread. Please continue in your existing thread.",
128+
color=discord.Color.orange(),
129+
)
130+
await thread.send(embed=embed)
131+
await thread.edit(
132+
name=f"[DUPLICATE] {thread.name}"[:100],
133+
archived=True,
134+
locked=True,
135+
)
136+
return
137+
138+
embed = discord.Embed(
139+
title="Welcome!",
140+
description="Your thread has been created successfully!",
141+
color=discord.Color.blue(),
142+
)
143+
await thread.send(embed=embed)

0 commit comments

Comments
 (0)