Переименование, работа над ботом

This commit is contained in:
Евгений Храмов 2023-02-19 17:32:52 +03:00
parent 9faf10a493
commit cf8c255419
3 changed files with 132 additions and 65 deletions

@ -1,50 +0,0 @@
#!/usr/bin/env python3
import time
import telebot
from telebot import types
key_api = input("Укажите ключ бота")
dodo_bot = telebot.Telebot(f"{key_api}", parse_mode=None)
@bot.message_handler(commans=['start', 'help'])
def start_bot(message):
bot.reply_to(message, message.text)
@bot.message_handler(content_types=['text'])
def menu(a):
if a.text == "Inline_menu":
mainmenu = types.InlineKeyboardMarkup()
key1 = types.InlineKeyboardButton(text='Кнопка 1', callback_data='key1')
key2 = types.InlineKeyboardButton(text='Кнопка 2', callback_data='key2')
mainmenu.add(key1, key2)
bot.send_message(a.chat.id, 'Это главное меню!', reply_markup=mainmenu)
@bot.callback_query_handler(func=lambda call: True)
def back(call):
if call.data == "mainmenu":
mainmenu = types.InlineKeyboardMarkup()
key1 = types.InlineKeyboardButton(text='Кнопка 1', callback_data='key1')
key2 = types.InlineKeyboardButton(text='Кнопка 2', callback_data='key2')
mainmenu.add(key1, key2)
bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id, reply_markup=mainmenu)
elif call.data == "key1":
next_menu = types.InlineKeyboardMarkup()
key3 = types.InlineKeyboardButton(text='Кнопка 3', callback_data='key3')
back = types.InlineKeyboardButton(text='Назад', callback_data='mainmenu')
next_menu.add(key3, back)
bot.edit_message_text('Это меню уровня 2, для кнопки1!', call.message.chat.id, call.message.message_id,
reply_markup=next_menu)
elif call.data == "key2":
next_menu2 = types.InlineKeyboardMarkup()
key4 = types.InlineKeyboardButton(text='Кнопка 4', callback_data='key4')
back = types.InlineKeyboardButton(text='Назад', callback_data='mainmenu')
next_menu2.add(key4, back)
bot.edit_message_text('Это меню уровня 2, для кнопки2!', call.message.chat.id, call.message.message_id,
reply_markup=next_menu2)
bot.polling()

@ -9,15 +9,17 @@ import colorama
home_dir = Path.home()
dir_server = f"{home_dir}/ARK_Servers/"
config_dodo = f"{home_dir}/.config/dodo/"
config_hlna = f"{home_dir}/.config/hlna/"
mods_id = ""
listen_server = True
@click.group()
def dodo():
def hlna():
pass
list_config = next(os.walk(config_dodo), (None, None, []))[2] # [] if no file
list_config = next(os.walk(config_hlna), (None, None, []))[2] # [] if no file
x = list_config.count('.directory')
if x>0:
list_config.remove('.directory')
@ -52,15 +54,15 @@ def check_int(number=""):
create_dir(dir_server)
create_dir(config_dodo)
create_dir(config_hlna)
@dodo.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
def config(map_server=list_config):
query_p = []
port_s = []
for i in map_server:
with open(f"{home_dir}/.config/dodo/{i}", "r") as yamlfile:
with open(f"{home_dir}/.config/hlna/{i}", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
data = data[0]
port_s.append(data['Port'])
@ -175,7 +177,7 @@ def config(map_server=list_config):
def yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override):
settings_dodo = [
settings_hlna = [
{
'Cluster' : cluster_server,
'SessionName' : name_server,
@ -191,12 +193,14 @@ def yaml_create(cluster_server, map_server, name_server, port_server, query_port
print(cluster_id)
if cluster_id != None:
settings_dodo[0]['clusterid'] = cluster_id
settings_dodo[0]['clusterdir'] = cluster_dir_override
with open(config_dodo + f"{map_server[-1]}", 'w') as yamlfile:
data = yaml.dump(settings_dodo, yamlfile)
settings_hlna[0]['clusterid'] = cluster_id
settings_hlna[0]['clusterdir'] = cluster_dir_override
with open(config_hlna + f"{map_server[-1]}", 'w') as yamlfile:
data = yaml.dump(settings_hlna, yamlfile)
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
@dodo.command()
@hlna.command()
def servers(map_servers=list_config):
if map_servers==[]:
print("Сервера не установлены")
@ -216,7 +220,7 @@ def servers(map_servers=list_config):
print("\n")
@dodo.command(help='Для запуска, сконфигурированного сервера или кластера')
@hlna.command(help='Для запуска, сконфигурированного сервера или кластера')
def start(map_server=list_config):
map_choise = []
while True:
@ -256,7 +260,7 @@ def start(map_server=list_config):
def read_yaml(map_server):
with open(f"{home_dir}/.config/dodo/{map_server}", "r") as yamlfile:
with open(f"{home_dir}/.config/hlna/{map_server}", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
data = data[0]
dir_server = data['ServerPath']
@ -276,4 +280,4 @@ def read_yaml(map_server):
if __name__ == '__main__':
dodo()
hlna()

113
hlna_bot.py Executable file

@ -0,0 +1,113 @@
#!/usr/bin/env python3
import time
import os
import telebot
from telebot import types
import hlna
key_api = "6192661772:AAHB1dw4rXHOglgyTOpcsxwvLn4d3AKkvP4"
#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 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() == 'Назад':
hlna_bot.register_next_step_handler(m, start)
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)