Skip to content

Commit 579207f

Browse files
committed
Include subsearch string when handling messages with uploads
1 parent 7474ff3 commit 579207f

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

cogs/JollinessEnforcement.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from __future__ import annotations
2+
3+
import discord
4+
from discord.ext import commands
5+
6+
7+
class JollinessEnforcement(commands.Cog):
8+
"""Enforces appropriate jolliness."""
9+
10+
TARGET_CHANNEL_IDS: set[int] = {
11+
485138525885431808,
12+
1292689984372867173,
13+
314856589716750346,
14+
}
15+
16+
ALLOWED_STRINGS: tuple[str, ...] = (
17+
"lol",
18+
"rofl",
19+
"lmao",
20+
"kek",
21+
)
22+
23+
NOTICE_TEXT = (
24+
"All messages must contain appropriate "
25+
"jolliness or they will be refused."
26+
)
27+
28+
def __init__(self, bot: commands.Bot) -> None:
29+
self.bot = bot
30+
self.enabled: bool = False
31+
32+
@commands.hybrid_command(name="jolliness", description="Enable or disable jolliness enforcement.")
33+
@commands.has_permissions(manage_messages=True)
34+
async def jolliness(self, ctx: commands.Context, state: str) -> None:
35+
"""Enable or disable the enforcement."""
36+
state = state.lower()
37+
38+
if state in ("on", "enable", "enabled", "true"):
39+
self.enabled = True
40+
await ctx.reply("Jolliness enforcement enabled.")
41+
elif state in ("off", "disable", "disabled", "false"):
42+
self.enabled = False
43+
await ctx.reply("Jolliness enforcement disabled.")
44+
else:
45+
await ctx.reply("Use 'on' or 'off'.")
46+
47+
@jolliness.error
48+
async def jolliness_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
49+
if isinstance(error, commands.MissingPermissions):
50+
await ctx.reply("You do not have permission to use this command.")
51+
else:
52+
raise error
53+
54+
@commands.Cog.listener()
55+
async def on_message(self, message: discord.Message) -> None:
56+
if not self.enabled:
57+
return
58+
59+
if message.guild is None:
60+
return
61+
62+
if self.bot.user is not None and message.author.id == self.bot.user.id:
63+
return
64+
65+
channel = message.channel
66+
if isinstance(channel, discord.Thread):
67+
parent_id = channel.parent_id
68+
else:
69+
parent_id = channel.id
70+
71+
if parent_id not in self.TARGET_CHANNEL_IDS:
72+
return
73+
74+
content = message.content.lower()
75+
76+
if any(term in content for term in self.ALLOWED_STRINGS):
77+
return
78+
79+
try:
80+
await message.delete()
81+
except (discord.Forbidden, discord.HTTPException):
82+
return
83+
84+
try:
85+
await message.channel.send(
86+
f"{message.author.mention} {self.NOTICE_TEXT}",
87+
delete_after=3,
88+
allowed_mentions=discord.AllowedMentions(users=True, roles=False, everyone=False),
89+
)
90+
except (discord.Forbidden, discord.HTTPException):
91+
pass
92+
93+
94+
async def setup(bot: commands.Bot) -> None:
95+
await bot.add_cog(JollinessEnforcement(bot))

kurisu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
'cogs.server_logs',
6767
'cogs.soap',
6868
'cogs.titletxtparse',
69-
'cogs.slursearch'
69+
'cogs.slursearch',
70+
'cogs.JollinessEnforcement'
7071
)
7172

7273
DEBUG = False

0 commit comments

Comments
 (0)