Add restart command (#53)
* Add restart command This is handy when you need to restart the bot when something goes wrong. Currently, the bot restarts but doesn't send a message after restarting is done, feel free to improve this. It'll need something like storing bot status locally then on bot start, if restart status exists send a message. Signed-off-by: yshalsager <ysh-alsager@hotmail.com> * restart: switch to context based callbacks * restart: restrict the command to owner only Co-authored-by: Shivam Jha <jhashivam2020@gmail.com>
This commit is contained in:
parent
78b60d6715
commit
63a67d7a14
|
|
@ -1,5 +1,7 @@
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
|
from os import execl
|
||||||
|
from sys import executable
|
||||||
|
|
||||||
from telegram.ext import CommandHandler, run_async
|
from telegram.ext import CommandHandler, run_async
|
||||||
|
|
||||||
|
|
@ -33,6 +35,11 @@ def start(update,context):
|
||||||
|
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
|
def restart(update, context):
|
||||||
|
reply = sendMessage("Restarting, Please wait!", context.bot, update)
|
||||||
|
execl(executable, executable, "-m", "bot")
|
||||||
|
|
||||||
|
|
||||||
def ping(update, context):
|
def ping(update, context):
|
||||||
start_time = int(round(time.time() * 1000))
|
start_time = int(round(time.time() * 1000))
|
||||||
reply = sendMessage("Starting Ping", context.bot, update)
|
reply = sendMessage("Starting Ping", context.bot, update)
|
||||||
|
|
@ -80,6 +87,8 @@ def main():
|
||||||
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
||||||
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
|
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
|
||||||
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
||||||
|
restart_handler = CommandHandler(BotCommands.RestartCommand, restart,
|
||||||
|
filters=CustomFilters.owner_filter)
|
||||||
help_handler = CommandHandler(BotCommands.HelpCommand,
|
help_handler = CommandHandler(BotCommands.HelpCommand,
|
||||||
bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
||||||
stats_handler = CommandHandler(BotCommands.StatsCommand,
|
stats_handler = CommandHandler(BotCommands.StatsCommand,
|
||||||
|
|
@ -87,6 +96,7 @@ def main():
|
||||||
log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
|
log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
|
||||||
dispatcher.add_handler(start_handler)
|
dispatcher.add_handler(start_handler)
|
||||||
dispatcher.add_handler(ping_handler)
|
dispatcher.add_handler(ping_handler)
|
||||||
|
dispatcher.add_handler(restart_handler)
|
||||||
dispatcher.add_handler(help_handler)
|
dispatcher.add_handler(help_handler)
|
||||||
dispatcher.add_handler(stats_handler)
|
dispatcher.add_handler(stats_handler)
|
||||||
dispatcher.add_handler(log_handler)
|
dispatcher.add_handler(log_handler)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class _BotCommands:
|
||||||
self.AuthorizeCommand = 'authorize'
|
self.AuthorizeCommand = 'authorize'
|
||||||
self.UnAuthorizeCommand = 'unauthorize'
|
self.UnAuthorizeCommand = 'unauthorize'
|
||||||
self.PingCommand = 'ping'
|
self.PingCommand = 'ping'
|
||||||
|
self.RestartCommand = 'restart'
|
||||||
self.StatsCommand = 'stats'
|
self.StatsCommand = 'stats'
|
||||||
self.HelpCommand = 'help'
|
self.HelpCommand = 'help'
|
||||||
self.LogCommand = 'log'
|
self.LogCommand = 'log'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue