From ca1623fa75724437be7a4b4f2cb1c716164fa8e0 Mon Sep 17 00:00:00 2001 From: xpamych Date: Thu, 9 Mar 2023 15:37:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hlna_bot.py | 67 ++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/hlna_bot.py b/hlna_bot.py index 81cd1b4..ed42642 100755 --- a/hlna_bot.py +++ b/hlna_bot.py @@ -1,16 +1,18 @@ #!/usr/bin/env python3 import errno import time +import sys import os import telebot from telebot import types import subprocess import yaml import colorama + import hlna list_config = hlna.list_config -hlna.print_line(list_config) + def start(): if not os.path.exists(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot"): @@ -35,6 +37,18 @@ def start(): start() +def check_status(m): + for i in list_config: + data = hlna.read_yaml(i) + hlna.print_line(data) + x = os.system(f"lsof -w -i :{data['Port']}") + n_srv = data['SessionName'] + if x != 0: + hlna_bot.send_message(m.chat.id, text=f"Сервер {n_srv} не работает 🛑") + elif x == 0: + hlna_bot.send_message(m.chat.id, text=f"Сервер {n_srv} запустился 🟢") + + def read_config(): with open(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot", "r") as yamlfile: data = yaml.load(yamlfile, Loader=yaml.FullLoader) @@ -53,9 +67,11 @@ def create_config(key_api): print(colorama.Fore.GREEN + "Конфиг бота создан" + colorama.Style.RESET_ALL) return k_api -start() -data = read_config() +start() + + +data = read_config() k_api = data['key_api'] hlna_bot = telebot.TeleBot(f"{k_api}", parse_mode=None) @@ -102,20 +118,8 @@ def m_chose(m): menu_start.add(k_back) hlna_bot.send_message(m.chat.id, text="{0.first_name}, выбери карту".format(m.from_user), reply_markup=menu_start) elif (m.text.strip() == '🧾 Статус'): - for i in list_config: - data = hlna.read_yaml(i) - x = os.system(f"lsof -w -i :{data['Port']}") - n_srv = data['SessionName'] - if x != 0: - hlna_bot.send_message(m.chat.id, text=f"Сервер {n_srv} не работает 🛑") - while x != 0: - time.sleep(5) - x = os.system("lsof -w -i :7778") - hlna_bot.send_message(m.chat.id, text="Сервер запустился 🟢".format( - m.from_user)) - # elif x == 0: - # time.sleep(30) - # pass + check_status(m) + elif m.text.strip() == 'Назад': m_start(m) elif m.text.strip() == 'TheIsland': @@ -127,12 +131,9 @@ def m_install(m): hlna_bot.send_message(m.chat.id, subprocess.check_output(hlna.config(), shell=True)) -print("Bot started") +print("Бот запущен") hlna_bot.polling(none_stop=True, interval=0, timeout=999) - # print("Start") - # - # subprocess.run(["arkmanager", "start", "--alwaysrestart", "@all"]) # elif m.text.strip() == '🦇 Выключить': # subprocess.run(["arkmanager", "stop", "@all"]) @@ -158,27 +159,3 @@ hlna_bot.polling(none_stop=True, interval=0, timeout=999) # id = m.text.strip() # subprocess.run(["arkmanager", "installmods", id, "@all"]) # subprocess.run(["arkmanager", "enablemod", id, "@all"]) -# def check(m): -# -# while True: -# x = os.system("lsof -w -i :7777") -# if x!=0: -# bot.send_message(m.chat.id, text="Сервер не работает 🛑".format( -# m.from_user)) -# bot.send_message(-1001585320535,text="Сервер не работает 🛑".format( -# m.from_user),reply_markup=types.ReplyKeyboardRemove()) -# -# while x!=0: -# time.sleep(5) -# x = os.system("lsof -w -i :7778") -# bot.send_message(m.chat.id, text="Сервер запустился 🟢".format( -# m.from_user)) -# bot.send_message(-1001585320535,text="Сервер запустился 🟢".format( -# m.from_user)) -# -# elif x == 0: -# time.sleep(30) -# pass - - -