From 38452a095971bd45b580d4fa55a23924eb497302 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sun, 15 Dec 2024 00:32:13 +0330 Subject: [PATCH] Create command --- core/scripts/telegrambot/utils/command.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/scripts/telegrambot/utils/command.py 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