diff --git a/core/scripts/telegrambot/utils/command.py b/core/scripts/telegrambot/utils/command.py new file mode 100644 index 0000000..bf8f645 --- /dev/null +++ b/core/scripts/telegrambot/utils/command.py @@ -0,0 +1,26 @@ +import telebot +import subprocess +import json +import os +import shlex +from dotenv import load_dotenv +from telebot import types + +load_dotenv() + +API_TOKEN = os.getenv('API_TOKEN') +ADMIN_USER_IDS = json.loads(os.getenv('ADMIN_USER_IDS')) +CLI_PATH = '/etc/hysteria/core/cli.py' +BACKUP_DIRECTORY = '/opt/hysbackup' +bot = telebot.TeleBot(API_TOKEN) + +def run_cli_command(command): + try: + args = shlex.split(command) + result = subprocess.check_output(args, stderr=subprocess.STDOUT) + return result.decode('utf-8').strip() + except subprocess.CalledProcessError as e: + return f'Error: {e.output.decode("utf-8")}' + +def is_admin(user_id): + return user_id in ADMIN_USER_IDS \ No newline at end of file