forked from Pavel_Durov/python_bot
#5 old posts delete function
This commit is contained in:
parent
150472a2de
commit
c3b6e56010
@ -8,6 +8,7 @@ from dicktxt import change_words
|
||||
from pipisa_functions import pipisa_time
|
||||
from DBChat import user_operations
|
||||
from TopMsg import topdicks
|
||||
from handlers import post_cleaner
|
||||
|
||||
|
||||
#### https://docs.python-arango.com/en/main/
|
||||
@ -50,16 +51,14 @@ async def up_dick(message: types.Message):
|
||||
|
||||
pipisa_word = ForReadDict.RandomDick()
|
||||
change_word = change_words.ChangeWord(result)
|
||||
|
||||
prev_enl_message_id = user["reply_id"]
|
||||
await bot.delete_message(prev_enl_message_id)
|
||||
|
||||
|
||||
enl_message = await bot.send_message(message.chat.id, f"@\
|
||||
{message.from_user.username}, \
|
||||
ваш <em>{pipisa_word}</em> ,{change_word(result)} на <b>{abs(result)}</b> см!\n\ \
|
||||
Теперь он равен <b>{updetedDick}</b> см! ")
|
||||
|
||||
post_cleaner.cleanup_sequence(user['user_id'], enl_message.id, message.chat.id)
|
||||
|
||||
|
||||
try:
|
||||
dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
@ -71,9 +70,7 @@ async def up_dick(message: types.Message):
|
||||
'dick_size': updetedDick,
|
||||
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'attempts': user['attempts'] + 1,
|
||||
'chat_id': message.chat.id,
|
||||
'reply_id': enl_message.id
|
||||
|
||||
'chat_id': message.chat.id
|
||||
},
|
||||
overwrite_mode='update'
|
||||
)
|
||||
@ -82,12 +79,11 @@ async def up_dick(message: types.Message):
|
||||
print(f'ошибка в обновлении пиписы @{message.from_user.username}')
|
||||
print(update_err)
|
||||
else:
|
||||
|
||||
prev_err_message_id = user["reply_id"] ##удалить предыдущее сообщение
|
||||
await bot.delete_message(prev_err_message_id)
|
||||
error_msg = await bot.send_message(message.chat.id, f'@\
|
||||
{message.from_user.username},🚫 вы уже крутили пипису, \
|
||||
ее размер <b>{user["dick_size"]}</b> см! ')
|
||||
|
||||
post_cleaner.cleanup_sequence(user['user_id'], error_msg.id, error_msg.chat.id)
|
||||
|
||||
try:
|
||||
metadata = dicks_collection.insert(
|
||||
@ -99,7 +95,6 @@ async def up_dick(message: types.Message):
|
||||
'datetimes': user['datetimes'] ,
|
||||
'attempts': user['attempts'] + 1,
|
||||
'chat_id': message.chat.id,
|
||||
'reply_id': error_msg.id
|
||||
},
|
||||
overwrite_mode='update'
|
||||
)
|
||||
|
@ -13,43 +13,21 @@ def get_remove_collection():
|
||||
|
||||
return remove_collection
|
||||
|
||||
|
||||
|
||||
def time_writer(userID: int, messageID:int, chatID:int):
|
||||
#write last reply post ID to db
|
||||
remove_collection = get_remove_collection
|
||||
message_time = datetime.datetime.now()
|
||||
|
||||
try:
|
||||
lastReply = {
|
||||
'user_id': userID,
|
||||
'datetimes': message_time,
|
||||
'chat_id': chatID,
|
||||
'messageID': messageID
|
||||
}
|
||||
|
||||
metadata = remove_collection.insert(lastReply, overwrite_mode='update')
|
||||
|
||||
except Exception as lastWriteErr:
|
||||
print(lastWriteErr)
|
||||
|
||||
return 0
|
||||
|
||||
async def cleaner(userID:int, chatID:int):
|
||||
async def cleanup_sequence(userID: int, messageID:int, chatID:int):
|
||||
|
||||
#remove last reply and check posts older than 5 minutes to delete
|
||||
remove_collection = get_remove_collection
|
||||
try:
|
||||
clean_candidate = remove_collection.find(
|
||||
{
|
||||
'user_id': userID,
|
||||
'_key': userID,
|
||||
'chat_id': chatID
|
||||
},
|
||||
skip=0, limit=1000)
|
||||
|
||||
prev_enl_message_id = clean_candidate["messageID"]
|
||||
await bot.delete_message(prev_enl_message_id)
|
||||
await bot.delete_message(prev_enl_message_id) #delete last reply to this user
|
||||
|
||||
|
||||
current_time = datetime.datetime.now()
|
||||
too_old = current_time-datetime.timedelta(min=5)
|
||||
old_posts = remove_collection.find(
|
||||
@ -61,13 +39,31 @@ async def cleaner(userID:int, chatID:int):
|
||||
for old_Post in old_posts:
|
||||
if old_Post["datetimes"] <= too_old:
|
||||
to_delete_ID = old_Post["messageID"]
|
||||
await bot.delete_message(to_delete_ID)
|
||||
to_delete_UserId = old_Post['_key']
|
||||
|
||||
#TODO: remove deleted posts ID's from DB
|
||||
await bot.delete_message(to_delete_ID) #delete old message
|
||||
old_posts.delete(to_delete_UserId) #delete old message DB entry
|
||||
|
||||
|
||||
except Exception as autoCleanErr:
|
||||
print(autoCleanErr)
|
||||
|
||||
#write last reply post ID to db
|
||||
remove_collection = get_remove_collection
|
||||
message_time = datetime.datetime.now()
|
||||
|
||||
try:
|
||||
lastReply = {
|
||||
'_key': userID,
|
||||
'datetimes': message_time,
|
||||
'chat_id': chatID,
|
||||
'messageID': messageID
|
||||
}
|
||||
|
||||
metadata = remove_collection.insert(lastReply, overwrite_mode='update') #write last reply time
|
||||
|
||||
except Exception as lastWriteErr:
|
||||
print(lastWriteErr)
|
||||
|
||||
return 0
|
||||
|
Loading…
Reference in New Issue
Block a user