Create command
This commit is contained in:
26
core/scripts/telegrambot/utils/command.py
Normal file
26
core/scripts/telegrambot/utils/command.py
Normal file
@ -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
|
||||
Reference in New Issue
Block a user