Skip to content

Commit

Permalink
restart: inform the user that restarting is complete (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: yshalsager <ysh-alsager@hotmail.com>
  • Loading branch information
yshalsager authored Apr 25, 2020
1 parent 4410f4e commit b02990d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import shutil
import signal
from os import execl
import pickle

from os import execl, path, remove
from sys import executable

from telegram.ext import CommandHandler, run_async
Expand Down Expand Up @@ -36,7 +38,10 @@ def start(update,context):

@run_async
def restart(update, context):
reply = sendMessage("Restarting, Please wait!", context.bot, update)
restart_message = sendMessage("Restarting, Please wait!", context.bot, update)
# Save restart message object in order to reply to it after restarting
with open('restart.pickle', 'wb') as status:
pickle.dump(restart_message, status)
execl(executable, executable, "-m", "bot")


Expand Down Expand Up @@ -83,6 +88,13 @@ def bot_help(update, context):

def main():
fs_utils.start_cleanup()
# Check if the bot is restarting
if path.exists('restart.pickle'):
with open('restart.pickle', 'rb') as status:
restart_message = pickle.load(status)
restart_message.edit_text("Restarted Successfully!")
remove('restart.pickle')

start_handler = CommandHandler(BotCommands.StartCommand, start,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
Expand Down

0 comments on commit b02990d

Please sign in to comment.