hln-a/hlna_bot.py
2023-02-20 10:38:15 +03:00

114 lines
4.5 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 hlna
key_api = input("Укажите ключ бота")
hlna_bot = telebot.TeleBot(f"{key_api}", parse_mode=None)
map_server = hlna.list_config
@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 map_server == []:
hlna_bot.send_message(m.chat.id, text="{0.first_name}, ниодна карта не установлена".format(m.from_user))
else:
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
for i in map_server:
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_start(m):
# 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
print("Bot starting")
hlna_bot.polling(none_stop=True, interval=0, timeout=999)