#🔒 code fix when adding extra letters between the blacklisted words

50 messages · Page 1 of 1 (latest)

modest imp
#
  1. The purpose of the bot is to delete messages from new_dutch_words.txt document, basically 8000 lines of dutch words /// (WORKS)

  2. When a different text is sent then edited to dutch words listed in new_dutch_words.txt document are supposed to be deleted /// (WORKS)

  3. 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)

https://paste.pythondiscord.com/Z73Q

keen lynxBOT
#

@modest imp

Python help channel opened

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.

dry acorn
#

@modest imp Can you give a sample, say 10-15 lines, of what the new_dutch_words.txt file looks like?

dry acorn
modest imp
dry acorn
#

But, when you say an extra letter added between blacklisted words

#

do you mean like

modest imp
#

so lets say the first word

dry acorn
#

Smeets
O
uitpakken

#

?

dry acorn
modest imp
#

when i write 'smeets' it will be deleted

dry acorn
#

right

modest imp
#

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

dry acorn
#

I see that, im just looking through the code to better understand it

modest imp
#

oke sure

dry acorn
#

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

modest imp
#

yes so what do we do so that it detects the actual word from that document if extra letters are added and deletes it?

dry acorn
#

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

modest imp
dry acorn
#

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

keen lynxBOT
#

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.
modest imp
#
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?

dry acorn
#

reading it now

modest imp
#

i mean i have that

dry acorn
#

Oh that's just unchanged from the original code you sent, right?

modest imp
#

yes, its real one

#

nothing changed

#

but still doesnt delete

dry acorn
#

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?

modest imp
#

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

keen lynxBOT
#
Python help channel closed

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.