Add /lock

This commit is contained in:
Ceda EI 2018-10-03 19:45:19 +05:30
parent 34299e2cfc
commit 71f798fe5e
2 changed files with 18 additions and 1 deletions

13
bot.py
View File

@ -49,6 +49,16 @@ def screenshot(bot, update):
os.remove(screenshot)
def lock(bot, update):
command = config.lock.split()
exitcode = subprocess.call(command)
chat_id = update.message.chat_id
# Only send message if command fails because another script will send the
# message on successful lock
if exitcode != 0:
bot.send_message(chat_id=chat_id, text="Command failed.")
updater = Updater(token=config.api_key)
dispatcher = updater.dispatcher
@ -58,4 +68,7 @@ dispatcher.add_handler(start_handler)
screenshot_handler = CommandHandler('screenshot', screenshot)
dispatcher.add_handler(screenshot_handler)
lock_handler = CommandHandler('lock', lock)
dispatcher.add_handler(lock_handler)
updater.start_polling()

View File

@ -2,5 +2,9 @@
# Replace the key by the actual token recieved from BotFather
api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Replace 123456789 with your own user id.
# User ID of the user allowed to use the bot. Replace 123456789 with
# your own user id.
master_id = 123456789
# Command to lock the screen. Replace the command with actual command.
lock = "xautolock -locknow"