Added cuss words as a txt file that cahces at bot startup. Also some regex stuff in there so it doesn't care about capitalization etc.

This commit is contained in:
2025-08-07 23:54:07 -05:00
parent 1109c2ef77
commit 4f442c2f92
2 changed files with 50 additions and 22 deletions

37
Main.py
View File

@@ -5,6 +5,7 @@ from dotenv import load_dotenv
from pathlib import Path
import os
import sqlite_utils
import re
# Show the path we expect to load
# Explicitly find the .env file in the same directory as the script
@@ -23,6 +24,15 @@ print(f"Loaded token Succesfully")
if token is None:
raise RuntimeError(".env file not loaded or DISCORD_TOKEN not set.")
# --- Load bad words from file into a set ---
with open("bad_words.txt", "r", encoding="utf-8") as f:
BAD_WORDS = {line.strip().lower() for line in f if line.strip()}
# Compile regex pattern for performance
# \b = word boundary, (?i) = case-insensitive
bad_words_pattern = re.compile(r"\b(" + "|".join(map(re.escape, BAD_WORDS)) + r")\b", re.IGNORECASE)
token = os.getenv("DISCORD_TOKEN")
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
@@ -47,14 +57,17 @@ async def on_ready():
async def on_member_join(member):
await member.send(f"Welcome to the server {member.name}")
#Responding to cuss words
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if "shit" in message.content.lower():
#await message.delete()
await message.channel.send(f"{message.author.mention} - bro thats a bad worddddd!")
# Check if message contains a bad word
if bad_words_pattern.search(message.content):
await message.channel.send(
f"{message.author.mention} - bro thats a bad worddddd!"
)
await bot.process_commands(message)
@@ -151,21 +164,3 @@ async def points(ctx, member: discord.Member = None):
bot.run(token, log_handler=handler, log_level=logging.DEBUG)
#Aaron is fun but dumb
#Didn't I say that Already "NO YOu SAiD BlAH BLaaah" Oh Wait I'm wrong babooo boo
# AAron doesn't pay attention
# John doesn't read the manual
#another example comment
# AAron does pay attention
# John doesn't read the manual - true
#wazzzzzzup
# //testy
# John make comment now
#Johms fault
# Aaron can suck these nuts. Hi Josh

33
bad_words.txt Normal file
View File

@@ -0,0 +1,33 @@
ass
asshole
bastard
bitch
bollocks
bugger
bullshit
crap
cunt
damn
dick
douche
fag
faggot
fuck
fucker
fucking
goddamn
hell
horseshit
jackass
jerk
motherfucker
piss
prick
pussy
shit
shithead
slut
sonofabitch
twat
wanker
whore