This commit is contained in:
2023-03-08 17:41:05 +03:00
parent 93a57c083f
commit 935c268d74
2 changed files with 39 additions and 27 deletions

View File

@ -10,12 +10,12 @@ import colorama
import hlna
list_config = hlna.list_config
hlna.print_line(list_config)
def start():
if not os.path.exists(f"{hlna.dir_config}bot/hlna_bot"):
if not os.path.exists(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot"):
key_api = input("Укажите ключ бота\n")
os.chdir(hlna.dir_config)
os.chdir(f"{hlna.home_dir}/.config/hlna/")
try:
os.mkdir("bot")
except OSError as e:
@ -31,12 +31,12 @@ def start():
elif x == "y":
read_config()
elif x == "n":
os.remove(f"{hlna.dir_config}bot/hlna_bot")
os.remove(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot")
start()
def read_config():
with open(f"{hlna.dir_config}bot/hlna_bot", "r") as yamlfile:
with open(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
return data[0]
@ -48,7 +48,7 @@ def create_config(key_api):
'key_api': k_api,
}
]
with open(f"{hlna.dir_config}bot/hlna_bot", 'w') as yamlfile:
with open(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot", 'w') as yamlfile:
yaml.dump(config_hlna_bot, yamlfile)
print(colorama.Fore.GREEN + "Конфиг бота создан" + colorama.Style.RESET_ALL)
return k_api
@ -93,18 +93,33 @@ def m_chose(m):
reply_markup=menu_install)
hlna_bot.register_next_step_handler(m, m_install)
else:
hlna.read_yaml(list_config, flag=True)
hlna.read_yaml(list_config[-1], flag=True)
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
for i in list_config:
k_mapname = types.KeyboardButton(f"{i}")
k_mapname = types.KeyboardButton(i)
menu_start.add(k_mapname)
k_back = types.KeyboardButton("Назад")
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
elif m.text.strip() == 'Назад':
m_start(m)
# elif m.text.strip() == 'TheIsland':
# hlna.start()
elif m.text.strip() == 'TheIsland':
hlna.start()
def m_install(m):
@ -125,14 +140,7 @@ hlna_bot.polling(none_stop=True, interval=0, timeout=999)
# subprocess.run(["arkmanager","restart", "--alwaysrestart", "--warn", "@all"])
# elif (m.text.strip() == '🔸 Обновить'):
# subprocess.run(["arkmanager", "update", "--update-mods", "@all"])
# elif (m.text.strip() == '🧾 Статус'):
# x = os.system("lsof -w -i :7777")
# if x!=0:
# bot.send_message(m.chat.id, text="Сервер не работает 🛑".format(
# m.from_user))
# else:
# bot.send_message(m.chat.id, text="Сервер работает 🟢".format(
# m.from_user))
#
#
# elif (m.text.strip() == '⏬ Установка модов'):
# bot.send_message(m.from_user.id, "Введите id модификации")