diff --git a/bot.py b/bot.py index 444ef15..231a5fa 100644 --- a/bot.py +++ b/bot.py @@ -4,6 +4,7 @@ import logging import telegram import os import subprocess +import psutil from telegram.ext import Updater, CommandHandler try: @@ -69,6 +70,23 @@ def lock(bot, update): bot.send_message(chat_id=chat_id, text="Command failed.") +def check_if_running(process_name): + for i in psutil.process_iter(): + if i.name() == process_name: + return True + return False + + +def state(bot, update): + if not check_user(bot, update): + return False + chat_id = update.message.chat_id + if check_if_running(config.lock_process): + bot.send_message(chat_id=chat_id, text="Locked.") + else: + bot.send_message(chat_id=chat_id, text="Unlocked.") + + updater = Updater(token=config.api_key) dispatcher = updater.dispatcher @@ -81,4 +99,7 @@ dispatcher.add_handler(screenshot_handler) lock_handler = CommandHandler('lock', lock) dispatcher.add_handler(lock_handler) +state_handler = CommandHandler('state', state) +dispatcher.add_handler(state_handler) + updater.start_polling() diff --git a/sample.config.py b/sample.config.py index 9f5fe6a..d3075d7 100644 --- a/sample.config.py +++ b/sample.config.py @@ -8,3 +8,8 @@ master_id = 123456789 # Command to lock the screen. Replace the command with actual command. lock = "xautolock -locknow" + +# Command to check if it is running to see if the screen is locked +# Put the name of process that is running only when the screen is +# locked. +lock_process = "i3lock"