diff --git a/Main.py b/Main.py index 745a290..8cdc905 100644 --- a/Main.py +++ b/Main.py @@ -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 that’s a bad worddddd!" + ) await bot.process_commands(message) @@ -150,22 +163,4 @@ 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 \ No newline at end of file +bot.run(token, log_handler=handler, log_level=logging.DEBUG) \ No newline at end of file diff --git a/bad_words.txt b/bad_words.txt new file mode 100644 index 0000000..2a0987a --- /dev/null +++ b/bad_words.txt @@ -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 \ No newline at end of file