hln-a/hlna_bot.py

154 lines
5.7 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import time
import os
import telebot
from telebot import types
import subprocess
import yaml
import colorama
import hlna
list_config = hlna.list_config
def read_config():
if not f"{hlna.dir_config}hlna_bot":
key_api = input("Укажите ключ бота\n")
create_config(key_api)
else:
with open(f"{hlna.dir_config}hlna_bot", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
return data[0]
def create_config(key_api):
k_api = key_api
config_hlna_bot = [
{
'key_api': k_api,
}
]
with open(f"{hlna.dir_config}hlna_bot", 'w') as yamlfile:
yaml.dump(config_hlna_bot, yamlfile)
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
return k_api
data = read_config()
k_api = data['key_api']
hlna_bot = telebot.TeleBot(f"{k_api}", parse_mode=None)
@hlna_bot.message_handler(commands=["start"])
def m_start(m):
menu = types.ReplyKeyboardMarkup(resize_keyboard=True)
k_start = types.KeyboardButton("🦖 Старт")
k_stop = types.KeyboardButton("🦇 Выключить")
menu.add(k_start, k_stop)
k_restart = types.KeyboardButton("🦕 Перезагрузить")
k_update = types.KeyboardButton("🔸 Обновить")
menu.add(k_restart, k_update)
k_status = types.KeyboardButton("🧾 Статус")
menu.add(k_status)
k_mods = types.KeyboardButton("⏬ Установка модов")
menu.add(k_mods)
hlna_bot.send_message(m.chat.id, text="Привет, {0.first_name}! Это панель управления сервером".format(m.from_user),
reply_markup=menu)
@hlna_bot.message_handler(content_types=["text"])
def m_chose(m):
if m.text.strip() == '🦖 Старт':
if list_config == []:
menu_install = types.ReplyKeyboardMarkup(resize_keyboard=True)
k_install = types.KeyboardButton("Установить")
k_back = types.KeyboardButton("Назад")
menu_install.add(k_back, k_install)
hlna_bot.send_message(m.chat.id, text="{0.first_name}, ниодна карта не установлена".format(m.from_user),
reply_markup=menu_install)
hlna_bot.register_next_step_handler(m, m_install)
else:
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
for i in list_config:
k_mapname = types.KeyboardButton(f"{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() == 'Назад':
m_start(m)
# elif m.text.strip() == 'TheIsland':
# hlna.start()
def m_install(m):
if m.text.strip() == 'Установить':
hlna_bot.send_message(m.chat.id, subprocess.check_output(hlna.config(), shell=True))
print("Bot started")
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"])
# elif m.text.strip() == '🦕 Перезагрузить':
# 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 модификации")
# bot.register_next_step_handler(m, mods)
# else:
# pass
# else:
# if m.text.strip() == 'Zxx843Aj':
# th = Thread(target=check, args=(m,))
# th.start()
# id.append(m.chat.id)
# bot.send_message(m.chat.id, text="{0.first_name} вы авторизованы, нажмите /start для работы с ботом".format(m.from_user))
# return id
# def mods(m):
# 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