Add pickle when restart

This commit is contained in:
yasir 2023-02-14 12:56:13 +07:00
parent 8df34e6dce
commit f6523c1ff8
2 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,8 @@
import asyncio
import importlib
import re
import os
import pickle
import traceback
from logging import getLogger
@ -68,6 +70,11 @@ async def start_bot():
)
except Exception as e:
LOGGER.error(str(e))
if os.path.exists("restart.pickle"):
with open('restart.pickle', 'rb') as status:
chat_id, message_id = pickle.load(status)
os.remove("restart.pickle")
await app.edit_message_text(chat_id=chat_id, message_id=message_id, text="<b>Bot restarted successfully!</b>")
asyncio.create_task(auto_clean())
await idle()

View file

@ -2,6 +2,7 @@ import asyncio
import io
import os
import sys
import pickle
import traceback
from inspect import getfullargspec
@ -199,7 +200,9 @@ async def update_restart(_, message):
await message.reply_text(f"<code>{out}</code>")
except Exception as e:
return await message.reply_text(str(e))
await message.reply_text("<b>Updated with default branch, restarting now.</b>")
msg = await message.reply_text("<b>Updated with default branch, restarting now.</b>")
with open('restart.pickle', 'wb') as status:
pickle.dump([message.chat.id, msg.id], status)
os.execvp(sys.executable, [sys.executable, "-m", "misskaty"])