C
C
cenox2020-12-09 21:45:08
Python
cenox, 2020-12-09 21:45:08

What to do if the bot is flooding with demotivators?

Hello, I have a code for a VK bot that generates demotivators using words and photos taken from a conversation. (example: https://vk.com/neurobred )
There are lines in the generation that are responsible for clearing the base after generating the demotivator. (text + photos are removed from the databases), and it turns out that after each generation the database of words and pictures disappears, and you have to write words in the conversation again.
Base cleaning:

f = open(dir_to_txt + str(ans.peer_id) + '.txt', 'w', encoding='utf8')
                f.write('')
                f.close()
                f = open(dir_to_pic + str(ans.peer_id) + '.txt', 'w', encoding='utf8')
                f.write('')

I decided to delete these lines of cleaning the database, at first everything was ok, but after reaching this value, the Bot starts to respond with a demotivator to EVERY message, this is due to the fact that the database already has those same 20 lines of text and 3 photos (lines above) How can I fix this? So that the bot, when reaching 20 messages and 3 pictures, does not flood me with demotivators. If someone will test the script, then in the folder with a .py file, create a folder "Dialogs" and "Images" The code is attached below:
if lines >= 20 and pic2 >= 3:
await ans(f'', attachment=photo)
                f = open(dir_to_txt + str(ans.peer_id) + '.txt', 'w', encoding='utf8')
                f.write('')
                f.close()
                f = open(dir_to_pic + str(ans.peer_id) + '.txt', 'w', encoding='utf8')
                f.write('')
                f.close()

@bot.on.message()
async def lsmsg(ans: Message):
    await ans('Я работаю только в беседах .-.')
    
bot.run_polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2020-12-09
@cen0x

if lines >= 20 and pic2 >= 3
add to the condition that the number must be a multiple of 20 as you wrote in the description of the bot
and lines % 20 == 0
Python I don't know. so the remainder of the division may be written differently in its syntax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question