11from __future__ import annotations
22
3+ import re
4+
35import discord
46from discord .ext import commands
57
@@ -13,41 +15,42 @@ class JollinessEnforcement(commands.Cog):
1315 314856589716750346 ,
1416 }
1517
16- ALLOWED_STRINGS : tuple [str , ...] = (
17- "lol" ,
18- "rofl" ,
19- "lmao" ,
20- "kek" ,
21- )
22-
2318 NOTICE_TEXT = (
2419 "All messages must contain appropriate "
2520 "jolliness or they will be refused."
2621 )
2722
23+ LAUGH_REGEX = re .compile (
24+ r"(lol+|lmao+|rofl+|kek+|(?:ha){2,}|(?:he){2,}|(?:ho){2,}|tee\s?hee|xd+|:d)" ,
25+ re .IGNORECASE ,
26+ )
27+
2828 def __init__ (self , bot : commands .Bot ) -> None :
2929 self .bot = bot
3030 self .enabled : bool = False
3131
32- @commands .hybrid_command (name = "jolliness" , description = "Enable or disable jolliness enforcement." )
33- @commands .has_permissions (manage_messages = True )
32+ @commands .hybrid_command (
33+ name = "jolliness" ,
34+ description = "Enable or disable jolliness enforcement." ,
35+ )
36+ @commands .has_permissions (manage_server = True )
3437 async def jolliness (self , ctx : commands .Context , state : str ) -> None :
3538 """Enable or disable the enforcement."""
3639 state = state .lower ()
3740
3841 if state in ("on" , "enable" , "enabled" , "true" ):
3942 self .enabled = True
40- await ctx .reply ("Jolliness enforcement enabled." )
43+ await ctx .send ("Jolliness enforcement enabled." )
4144 elif state in ("off" , "disable" , "disabled" , "false" ):
4245 self .enabled = False
43- await ctx .reply ("Jolliness enforcement disabled." )
46+ await ctx .send ("Jolliness enforcement disabled." )
4447 else :
45- await ctx .reply ("Use 'on' or 'off'." )
48+ await ctx .send ("Use 'on' or 'off'." )
4649
4750 @jolliness .error
4851 async def jolliness_error (self , ctx : commands .Context , error : commands .CommandError ) -> None :
4952 if isinstance (error , commands .MissingPermissions ):
50- await ctx .reply ("You do not have permission to use this command." )
53+ await ctx .send ("You do not have permission to use this command." )
5154 else :
5255 raise error
5356
@@ -71,9 +74,11 @@ async def on_message(self, message: discord.Message) -> None:
7174 if parent_id not in self .TARGET_CHANNEL_IDS :
7275 return
7376
74- content = message .content .lower ()
77+ # Don't eat the toggle command itself
78+ if message .content .lower ().startswith (".jolliness" ):
79+ return
7580
76- if any ( term in content for term in self .ALLOWED_STRINGS ):
81+ if self .LAUGH_REGEX . search ( message . content ):
7782 return
7883
7984 try :
@@ -85,7 +90,11 @@ async def on_message(self, message: discord.Message) -> None:
8590 await message .channel .send (
8691 f"{ message .author .mention } { self .NOTICE_TEXT } " ,
8792 delete_after = 3 ,
88- allowed_mentions = discord .AllowedMentions (users = True , roles = False , everyone = False ),
93+ allowed_mentions = discord .AllowedMentions (
94+ users = True ,
95+ roles = False ,
96+ everyone = False ,
97+ ),
8998 )
9099 except (discord .Forbidden , discord .HTTPException ):
91100 pass
0 commit comments