From 71f798fe5e39e3bfc82ee0f9a423fad7f5c9b88b Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 3 Oct 2018 19:45:19 +0530 Subject: [PATCH] Add /lock --- bot.py | 13 +++++++++++++ sample.config.py | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index b704b8d..0a31003 100644 --- a/bot.py +++ b/bot.py @@ -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() diff --git a/sample.config.py b/sample.config.py index e81d659..9f5fe6a 100644 --- a/sample.config.py +++ b/sample.config.py @@ -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"