K
K
Kaccup2021-10-08 12:15:26
Chats
Kaccup, 2021-10-08 12:15:26

How to give a bot a mute to a user if he swears?

there is a list of words.
How to force the bot to issue a Mute to the user if the words it types in the chat match the words in the list.

@bot.message_handler(content_types=["text"])
def handle_text(message):
for x in blacklist:
if x in message.text:
bot.delete_message(message.chat.id, message.message_id)
time.sleep(1 )
bot.send_message(message.chat.id, 'Mute for 15 minutes!')

actually the question is, how to add?
without using a database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2021-10-08
@Kaccup

without using a database.

No way. Well, that is, of course, you can store the database as an array in RAM, but when you restart the script, you will lose all data about muted users and you will no longer unban them in time. Yes. you can still save to a file, but why?
In general, the task looks like this:
1. Finish your script for a mute or a temporary ban, keeping in the database (or RAM) data about when the ban for each user expires;
2. Every minute (or second) run through this database and unban those whose unbanned time is less than the current time.
Well, yes, a word filter is very difficult. All it takes is to change one character into the words "x-y-and-unknown" to Latin and it will not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question