From 6b228061c449bf7ebc3916483fc1a8ea5f197bf9 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Fri, 22 Sep 2023 17:06:37 -0400 Subject: [PATCH 1/8] main test setup --- main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..6a9d0a1 --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +from decouple import config +import discord + +def check_profanity(sentence): + if(): + return True + return False + + +token = config("DISCORD_BOT_TOKEN") + + +bot = discord.Client() + + +@bot.event +async def on_message(message): + word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] + + # CHECKS IF THE MESSAGE THAT WAS SENT IS EQUAL TO "HELLO". + if message.content.lower() == "hello": + # SENDS BACK A MESSAGE TO THE CHANNEL. + await message.channel.send("hey testing 123") + + + + +bot.run(token) From 9e3349ef3b03c53b73bda8da64a572f964ac1034 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Tue, 26 Sep 2023 17:05:51 -0400 Subject: [PATCH 2/8] Working input comparisons --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 6a9d0a1..e512260 100644 --- a/main.py +++ b/main.py @@ -1,28 +1,56 @@ from decouple import config import discord +from discord.ext import commands -def check_profanity(sentence): - if(): - return True - return False +async def check_profanity(sentence): + word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] + for word in word_list: + if(sentence == word): + # If a word from the list is found, send a response + return word -token = config("DISCORD_BOT_TOKEN") +if __name__ =='__main__': + # Define your intents + intents = discord.Intents.default() + intents.typing = False + intents.presences = False + intents.messages = True + intents.message_content = True + token = config("DISCORD_BOT_TOKEN") -bot = discord.Client() + # Initialize the bot with the specified intents + bot = discord.Client(intents=intents) -@bot.event -async def on_message(message): - word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] - # CHECKS IF THE MESSAGE THAT WAS SENT IS EQUAL TO "HELLO". - if message.content.lower() == "hello": - # SENDS BACK A MESSAGE TO THE CHANNEL. - await message.channel.send("hey testing 123") - + @bot.event + async def on_ready(): + print(f'Logged in as {bot.user.name}') - + @bot.event + async def on_message(message): + word_list = ["apple", "banana", "cherry"] -bot.run(token) + # Convert the message content to lowercase for case-insensitive matching + content = message.content.lower().strip() + + # Check if any word in the list is in the message content + profanity = "" + if message.author == bot.user: + return + # for word in word_list: + # # await message.channel.send(word) + # if(str(content) == word): + # # If a word from the list is found, send a response + # profanity = word + + profanity = check_profanity(content) + if(profanity != "") : + await message.channel.send("Word isnt allowed, "+ profanity) + else: + await message.channel.send("Clean message" + profanity) + + + bot.run(token) From af2ecf4a71c044ef21b04ea41b04c84742ca4240 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Fri, 29 Sep 2023 17:01:42 -0400 Subject: [PATCH 3/8] Working profanity checker --- main.py | 49 +-- profanity-list.txt | 816 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 844 insertions(+), 21 deletions(-) create mode 100644 profanity-list.txt diff --git a/main.py b/main.py index e512260..b71913f 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,26 @@ from discord.ext import commands -async def check_profanity(sentence): - word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] - for word in word_list: - if(sentence == word): - # If a word from the list is found, send a response - return word - +def check_profanity(sentence): + bad_words = set() + + # Specify the file path + file_path = "profanity-list.txt" # Replace with the path to your file + # Open the file and append its contents to the set + with open(file_path, "r") as file: + for line in file: + # Assuming each line in the file contains a single item to add to the set + item = line.strip() # Remove leading/trailing whitespace + bad_words.add(item) + words = sentence.split() + sentence_set = set(words) + # word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] + + # for word in word_list: + # if(sentence == word): + # # If a word from the list is found, send a response + # return word + return sentence_set.intersection(bad_words) if __name__ =='__main__': # Define your intents @@ -31,26 +44,20 @@ async def on_ready(): @bot.event async def on_message(message): - word_list = ["apple", "banana", "cherry"] # Convert the message content to lowercase for case-insensitive matching content = message.content.lower().strip() # Check if any word in the list is in the message content - profanity = "" if message.author == bot.user: return - # for word in word_list: - # # await message.channel.send(word) - # if(str(content) == word): - # # If a word from the list is found, send a response - # profanity = word - + if content.startswith("!"): + return profanity = check_profanity(content) - if(profanity != "") : - await message.channel.send("Word isnt allowed, "+ profanity) - else: - await message.channel.send("Clean message" + profanity) - - + print(profanity) + if(len(profanity) != 0 ) : + # await message.channel.send("Clean message") + # else: + await message.channel.send(f"Profanity isn't allowed.") + bot.run(token) diff --git a/profanity-list.txt b/profanity-list.txt new file mode 100644 index 0000000..0f3de71 --- /dev/null +++ b/profanity-list.txt @@ -0,0 +1,816 @@ +(ock +[ock +.f uc k +@rse +@rsehol +@unt +[unt +< unt +<***s +<**t +<**ts +<**t's +<*nt +<.unt +>k +f00k +f00ked +f0oked +fack +fackin +facking +fag +fagg0t +faggits +faggot +fagits +fags +fanny +fc*king +fck +f'ck +fck ing +fck1ng +fckeud +fckin +fcking +fcks +fckw1t +fckwit +fcuk +fcuked +fcuker +fcukin +fcuking +fcuks +feck +feckin +fecking +f---ed +fekking +felch +felched +felching +feltch +feltcher +feltching +f-----g +f---ing +f--k +fkin +fking +flange +flucknuts +fo0ked +foad +f-o-a-d +fook +fookd +fooked +fooker +fookin +fookin' +fooking +frig +frigging +frigin +friging +fu Date: Tue, 3 Oct 2023 16:59:12 -0400 Subject: [PATCH 4/8] Working DM for messages with profanity --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b71913f..2a7a09b 100644 --- a/main.py +++ b/main.py @@ -58,6 +58,13 @@ async def on_message(message): if(len(profanity) != 0 ) : # await message.channel.send("Clean message") # else: - await message.channel.send(f"Profanity isn't allowed.") + curses = "" + for badWord in profanity: + curses += badWord + ", " + user = message.author + dm_channel = await user.create_dm() + await dm_channel.send(f"Words like " + curses+" aren't allowed.") + + # await message.channel.send(f"Profanity isn't allowed.") bot.run(token) From afbcad92d628a2c70c67b887df1626cf4f5e31af Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Fri, 6 Oct 2023 16:32:33 -0400 Subject: [PATCH 5/8] V1 of timeouts Missing timeouts perms --- main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 2a7a09b..a11b3a2 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ from decouple import config import discord from discord.ext import commands +from datetime import timedelta def check_profanity(sentence): @@ -63,8 +64,11 @@ async def on_message(message): curses += badWord + ", " user = message.author dm_channel = await user.create_dm() - await dm_channel.send(f"Words like " + curses+" aren't allowed.") - + await dm_channel.send(f"Words like " + curses.rstrip()+" aren't allowed.") # await message.channel.send(f"Profanity isn't allowed.") - + timeout_duration = timedelta(minutes=1) + await user.timeout(timeout_duration, reason="Violated server rules") + + # To remove the timeout (unmute) + # await user.timeout(None) bot.run(token) From 208b3ef188292df67560831d84c81ba8681b7687 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Fri, 6 Oct 2023 16:57:02 -0400 Subject: [PATCH 6/8] Checks certain channels to check msg's --- main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index a11b3a2..e60a72e 100644 --- a/main.py +++ b/main.py @@ -46,6 +46,15 @@ async def on_ready(): @bot.event async def on_message(message): + + # Define a list of channel IDs where you want the function to work + allowed_channel_ids = [1157414659587063898, 1154875483553529981] # Replace with your desired channel IDs + + # Check if the message is sent in one of the allowed channels + if message.channel.id not in allowed_channel_ids: + print(message.channel.id) + return # Exit the function if it's not in an allowed channel + print("after") # Convert the message content to lowercase for case-insensitive matching content = message.content.lower().strip() @@ -66,9 +75,7 @@ async def on_message(message): dm_channel = await user.create_dm() await dm_channel.send(f"Words like " + curses.rstrip()+" aren't allowed.") # await message.channel.send(f"Profanity isn't allowed.") - timeout_duration = timedelta(minutes=1) - await user.timeout(timeout_duration, reason="Violated server rules") - # To remove the timeout (unmute) - # await user.timeout(None) bot.run(token) + + From 104fd6102631baf6263ecfc43653c0f60171fe58 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Tue, 10 Oct 2023 17:01:02 -0400 Subject: [PATCH 7/8] Refactor/cleanup, formal warning --- main.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index e60a72e..cd8f5dc 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,6 @@ def check_profanity(sentence): bad_words = set() - # Specify the file path file_path = "profanity-list.txt" # Replace with the path to your file # Open the file and append its contents to the set @@ -17,12 +16,6 @@ def check_profanity(sentence): bad_words.add(item) words = sentence.split() sentence_set = set(words) - # word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] - - # for word in word_list: - # if(sentence == word): - # # If a word from the list is found, send a response - # return word return sentence_set.intersection(bad_words) if __name__ =='__main__': @@ -34,27 +27,21 @@ def check_profanity(sentence): intents.message_content = True token = config("DISCORD_BOT_TOKEN") - # Initialize the bot with the specified intents bot = discord.Client(intents=intents) - @bot.event async def on_ready(): print(f'Logged in as {bot.user.name}') @bot.event async def on_message(message): - - # Define a list of channel IDs where you want the function to work allowed_channel_ids = [1157414659587063898, 1154875483553529981] # Replace with your desired channel IDs # Check if the message is sent in one of the allowed channels if message.channel.id not in allowed_channel_ids: - print(message.channel.id) return # Exit the function if it's not in an allowed channel - print("after") # Convert the message content to lowercase for case-insensitive matching content = message.content.lower().strip() @@ -64,17 +51,24 @@ async def on_message(message): if content.startswith("!"): return profanity = check_profanity(content) - print(profanity) if(len(profanity) != 0 ) : - # await message.channel.send("Clean message") - # else: - curses = "" - for badWord in profanity: - curses += badWord + ", " user = message.author dm_channel = await user.create_dm() - await dm_channel.send(f"Words like " + curses.rstrip()+" aren't allowed.") - # await message.channel.send(f"Profanity isn't allowed.") + await message.delete() + await dm_channel.send( + f"Hello {message.author},\n" + "\n" + "We've noticed that you used inappropriate language in our Discord server. We take our community guidelines seriously to maintain a respectful and enjoyable environment for all members." + "\n" + "Please keep in mind our server rules:\n" + "1. Be respectful to others.\n" + "2. Avoid offensive language and slurs.\n" + "3. No spamming or excessive caps.\n" + "4. Follow channel-specific guidelines.\n" + "You have received a warning for this violation. This warning is a reminder of our rules and a request to adhere to them. Repeated violations may lead to further actions, such as muting or removal from the server.\n" + "If you have any questions or concerns, feel free to reach out to the server moderators or administrators. We encourage positive and respectful interactions among our members." + ) + bot.run(token) From b44d36367eef45a11b5e61d3bb6c047358553740 Mon Sep 17 00:00:00 2001 From: darrenW04 Date: Tue, 24 Oct 2023 16:14:15 -0400 Subject: [PATCH 8/8] merging CJ's code and fix conflicts --- main.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index cd8f5dc..79aeb1b 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,12 @@ import discord from discord.ext import commands from datetime import timedelta - +from captcha.image import ImageCaptcha +import random +import io +import os +from PIL import Image +import asyncio def check_profanity(sentence): bad_words = set() @@ -18,6 +23,8 @@ def check_profanity(sentence): sentence_set = set(words) return sentence_set.intersection(bad_words) + + if __name__ =='__main__': # Define your intents intents = discord.Intents.default() @@ -26,6 +33,61 @@ def check_profanity(sentence): intents.messages = True intents.message_content = True token = config("DISCORD_BOT_TOKEN") + captcha_generator = ImageCaptcha() + + captchas ={} + + async def send_captcha(member): + while True: # Continues until correct CAPTCHA or timeout + data = ''.join(random.choices('ABCDEFGHJKMNPQRSTUVWXYZ123456789', k=5)) + captcha_image = captcha_generator.generate(data) + captcha_bytes = captcha_image.getvalue() + + temp_file = f"captcha_{member.id}.png" + with open(temp_file, "wb") as f: + f.write(captcha_bytes) + + captchas[member.id] = data + + dm_channel = await member.create_dm() + + image = Image.open(temp_file) + image.close() + + file = discord.File(fp=temp_file, filename="captcha.png") + + embed = discord.Embed(title="Verification", description="Solve the CAPTCHA to get verified!") + await dm_channel.send(embed=embed, file=file) + + fail_count = 0 + timeout = 180 + start_time = asyncio.get_event_loop().time() + + while (asyncio.get_event_loop().time() - start_time) < timeout: + try: + response = await bot.wait_for('message', check=lambda m: m.author == member and isinstance(m.channel, discord.DMChannel), timeout=timeout) + + if response.content == captchas[member.id]: + role = discord.utils.get(member.guild.roles, name="Verified") + await member.add_roles(role) + await dm_channel.send(f"Welcome {member.mention}, you are now verified and have been given the 'Verified' role!") + del captchas[member.id] + return + else: + fail_count += 1 + if fail_count < 3: + await dm_channel.send(f"Sorry {member.mention}, that's incorrect. You have {3 - fail_count} attempts left. A new captcha will be sent after your remaining attempts run out.") + else: + await dm_channel.send(f"Sorry {member.mention}, that's incorrect. Generating a new CAPTCHA for you...") + break # Exit the inner loop to generate a new CAPTCHA + + except asyncio.TimeoutError: + await dm_channel.send(f"Verification timed out. Please request a new CAPTCHA if you wish to verify.") + return + + os.remove(temp_file) + + # Initialize the bot with the specified intents bot = discord.Client(intents=intents) @@ -48,6 +110,10 @@ async def on_message(message): # Check if any word in the list is in the message content if message.author == bot.user: return + + if message.guild is None: + return + if content.startswith("!"): return profanity = check_profanity(content) @@ -68,8 +134,21 @@ async def on_message(message): "You have received a warning for this violation. This warning is a reminder of our rules and a request to adhere to them. Repeated violations may lead to further actions, such as muting or removal from the server.\n" "If you have any questions or concerns, feel free to reach out to the server moderators or administrators. We encourage positive and respectful interactions among our members." ) + if message.author.id in captchas: + if message.content == captchas[message.author.id]: + await message.author.send(f"Welcome {message.author.mention}, you are now verified!") + role = discord.utils.get(message.guild.roles, name="Verified") + await message.author.add_roles(role) + del captchas[message.author.id] + else: + await message.author.send(f"{message.author.mention}, that's incorrect. Please try again.") + @bot.event + async def on_member_join(member): + await send_captcha(member) + + bot.run(token)