-
The purpose of the bot is to delete messages from new_dutch_words.txt document, basically 8000 lines of dutch words /// (WORKS)
-
When a different text is sent then edited to dutch words listed in new_dutch_words.txt document are supposed to be deleted /// (WORKS)
-
When extra letter is added between the blacklisted words listed in new_dutch_words.txt document, the user can bypass and the message wont be deleted /// (DOESN'T WORK, need help)
#🔒 code fix when adding extra letters between the blacklisted words
50 messages · Page 1 of 1 (latest)
@modest imp
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
@modest imp Can you give a sample, say 10-15 lines, of what the new_dutch_words.txt file looks like?
sure
i will send ss ow
sure thing
I'm a little unsure of what the problem is, I get part of what you mean in your 3rd point, here
But, when you say an extra letter added between blacklisted words
do you mean like
so lets say the first word
yeah
when i write 'smeets' it will be deleted
right
but if i write 'smeetsss' or 'smeetss' it wont be deleted
because there is extra letter
and here its the s
for example i can write smeetssa and i can bypass
I see that, im just looking through the code to better understand it
oke sure
Well, to me it makes sense that the code is doing this, because as the code is right now; it's going to search for any strings in new_dutch_words containing the pattern smeetsss, which there isn't any
yes so what do we do so that it detects the actual word from that document if extra letters are added and deletes it?
If you wanted it to do something like this though I think you could basically reverse the check in some way, say, instead of checking if a word is in new_dutch_words, you could check if new_dutch_words[index] is in the string word
However, that solution could take the code much longer to run
Just because if a word youre looking for is at the end of the list, itll loop over every string in the list
In which case you could employ a sorting algorithm for it, but take that idea with a grain of salt please, cause i'm not the most up-to-date with sorting algorithms
i will figure that out but i dont know how to explain in python to do that
It should be easy to find a way to do it, I recommend asking chatgpt to see what it says, and check it with other people on this server or with information online https://chat.openai.com/
Basically just explain what your program does, and what you want it to do. Make sure you tell it to explain the changes it made to the code, cause sometimes it doesn't
Hey @modest imp!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
def contains_dutch_words(message):
words = message.content.split()
for word in words:
# Remove extra characters from the word
clean_word = ''.join(e for e in word if e.isalnum())
# Check if the cleaned word is a Dutch word
for dutch_word in new_dutch_words:
pattern = r'\b' + dutch_word + r'\b'
if re.search(pattern, clean_word, re.IGNORECASE):
return True
return False
i will do what u told me
what do u think about this?
reading it now
i mean i have that
Oh that's just unchanged from the original code you sent, right?
damn my bad, wasted a bit of time then as I already read that
doesn't delete at all, or doesnt delete in a situation like Smeet - Smeetsssss?
Nope
@dry acorn
# Function to check if a message contains any of the Dutch words
def contains_dutch_words(message):
words = message.content.split()
for word in words:
# Remove extra characters from the word
clean_word = ''.join(e for e in word if e.isalnum())
# Check if the cleaned word is a Dutch word
for dutch_word in new_dutch_words:
pattern = r'\b' + dutch_word + r'\b'
# Modify the pattern to match the blacklisted words even when extra letters are added from either side
modified_pattern = r'\b' + dutch_word + r'\b|' + r'\b' + dutch_word + r'\b'
if re.search(modified_pattern, clean_word, re.IGNORECASE):
return True
return False
this is the updated code
gonna try now
still doesnt work
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.