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 pipisa_functions import pipisa_time
|
||||||
from DBChat import user_operations
|
from DBChat import user_operations
|
||||||
from TopMsg import topdicks
|
from TopMsg import topdicks
|
||||||
|
from handlers import post_cleaner
|
||||||
|
|
||||||
|
|
||||||
#### https://docs.python-arango.com/en/main/
|
#### https://docs.python-arango.com/en/main/
|
||||||
@ -51,15 +52,13 @@ async def up_dick(message: types.Message):
|
|||||||
pipisa_word = ForReadDict.RandomDick()
|
pipisa_word = ForReadDict.RandomDick()
|
||||||
change_word = change_words.ChangeWord(result)
|
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"@\
|
enl_message = await bot.send_message(message.chat.id, f"@\
|
||||||
{message.from_user.username}, \
|
{message.from_user.username}, \
|
||||||
ваш <em>{pipisa_word}</em> ,{change_word(result)} на <b>{abs(result)}</b> см!\n\ \
|
ваш <em>{pipisa_word}</em> ,{change_word(result)} на <b>{abs(result)}</b> см!\n\ \
|
||||||
Теперь он равен <b>{updetedDick}</b> см! ")
|
Теперь он равен <b>{updetedDick}</b> см! ")
|
||||||
|
|
||||||
|
post_cleaner.cleanup_sequence(user['user_id'], enl_message.id, message.chat.id)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
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,
|
'dick_size': updetedDick,
|
||||||
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
'attempts': user['attempts'] + 1,
|
'attempts': user['attempts'] + 1,
|
||||||
'chat_id': message.chat.id,
|
'chat_id': message.chat.id
|
||||||
'reply_id': enl_message.id
|
|
||||||
|
|
||||||
},
|
},
|
||||||
overwrite_mode='update'
|
overwrite_mode='update'
|
||||||
)
|
)
|
||||||
@ -82,13 +79,12 @@ async def up_dick(message: types.Message):
|
|||||||
print(f'ошибка в обновлении пиписы @{message.from_user.username}')
|
print(f'ошибка в обновлении пиписы @{message.from_user.username}')
|
||||||
print(update_err)
|
print(update_err)
|
||||||
else:
|
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'@\
|
error_msg = await bot.send_message(message.chat.id, f'@\
|
||||||
{message.from_user.username},🚫 вы уже крутили пипису, \
|
{message.from_user.username},🚫 вы уже крутили пипису, \
|
||||||
ее размер <b>{user["dick_size"]}</b> см! ')
|
ее размер <b>{user["dick_size"]}</b> см! ')
|
||||||
|
|
||||||
|
post_cleaner.cleanup_sequence(user['user_id'], error_msg.id, error_msg.chat.id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
metadata = dicks_collection.insert(
|
metadata = dicks_collection.insert(
|
||||||
{
|
{
|
||||||
@ -99,7 +95,6 @@ async def up_dick(message: types.Message):
|
|||||||
'datetimes': user['datetimes'] ,
|
'datetimes': user['datetimes'] ,
|
||||||
'attempts': user['attempts'] + 1,
|
'attempts': user['attempts'] + 1,
|
||||||
'chat_id': message.chat.id,
|
'chat_id': message.chat.id,
|
||||||
'reply_id': error_msg.id
|
|
||||||
},
|
},
|
||||||
overwrite_mode='update'
|
overwrite_mode='update'
|
||||||
)
|
)
|
||||||
|
@ -13,42 +13,20 @@ def get_remove_collection():
|
|||||||
|
|
||||||
return remove_collection
|
return remove_collection
|
||||||
|
|
||||||
|
async def cleanup_sequence(userID: int, messageID:int, chatID:int):
|
||||||
|
|
||||||
|
|
||||||
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):
|
|
||||||
#remove last reply and check posts older than 5 minutes to delete
|
#remove last reply and check posts older than 5 minutes to delete
|
||||||
remove_collection = get_remove_collection
|
remove_collection = get_remove_collection
|
||||||
try:
|
try:
|
||||||
clean_candidate = remove_collection.find(
|
clean_candidate = remove_collection.find(
|
||||||
{
|
{
|
||||||
'user_id': userID,
|
'_key': userID,
|
||||||
'chat_id': chatID
|
'chat_id': chatID
|
||||||
},
|
},
|
||||||
skip=0, limit=1000)
|
skip=0, limit=1000)
|
||||||
|
|
||||||
prev_enl_message_id = clean_candidate["messageID"]
|
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()
|
current_time = datetime.datetime.now()
|
||||||
too_old = current_time-datetime.timedelta(min=5)
|
too_old = current_time-datetime.timedelta(min=5)
|
||||||
@ -61,13 +39,31 @@ async def cleaner(userID:int, chatID:int):
|
|||||||
for old_Post in old_posts:
|
for old_Post in old_posts:
|
||||||
if old_Post["datetimes"] <= too_old:
|
if old_Post["datetimes"] <= too_old:
|
||||||
to_delete_ID = old_Post["messageID"]
|
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:
|
except Exception as autoCleanErr:
|
||||||
print(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
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user