мааааленькая работа над ботом

This commit is contained in:
Евгений Храмов 2023-03-03 13:56:18 +03:00
parent 8148537b36
commit 8aeb00cef1
2 changed files with 48 additions and 18 deletions

18
hlna.py

@ -13,8 +13,8 @@ import click_completion
from rcon.source import Client
home_dir = Path.home()
dir_server = f"{home_dir}/ARK_Servers/Server"
config_hlna = f"{home_dir}/.config/hlna/"
dir_server = f"{home_dir}/ARK_Servers/"
dir_config = f"{home_dir}/.config/hlna/"
mods_id = ""
listen_server = True
@ -36,8 +36,8 @@ def find_file(path):
return arr
list_config = find_file(config_hlna)
delist_config = find_file(config_hlna+"deactivated")
list_config = find_file(dir_config)
delist_config = find_file(dir_config+"deactivated")
def print_line(text):
@ -67,7 +67,7 @@ def check_int(number=""):
create_dir(dir_server)
create_dir(config_hlna)
create_dir(dir_config)
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
@ -249,7 +249,7 @@ def yaml_create(cluster_server, map_s, name_server, port_server, query_port, rco
'clusterdir' : cluster_dir_override
}
]
with open(config_hlna + f"{name_server}", 'w') as yamlfile:
with open(dir_config + f"{name_server}", 'w') as yamlfile:
yaml.dump(settings_hlna, yamlfile)
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
@ -261,7 +261,7 @@ def enablemap(m,e):
"""Тут переписать надо"""
m = m.split(",")
# m = check_name_map(m, False)
create_dir(config_hlna + "deactivated")
create_dir(dir_config + "deactivated")
if e == True:
port_s = []
query_p = []
@ -279,7 +279,7 @@ def enablemap(m,e):
print("Предлагаем заменить")
if data['QueryPort'] in query_p:
print("Заменить query port?")
x = os.system(f"mv {config_hlna}deactivated/{i} {config_hlna + i} 2>> {config_hlna}logs") #Добавить текущее время
x = os.system(f"mv {dir_config}deactivated/{i} {dir_config + i} 2>> {dir_config}logs") #Добавить текущее время
if x == 0:
print(f"Карта активирована - {i}")
else:
@ -294,7 +294,7 @@ def enablemap(m,e):
if i in delist_config:
print(f"Карта {i} уже есть в деактивированных")
continue
x = os.system(f"mv {config_hlna + i} {config_hlna}deactivated/{i} 2>> {config_hlna}logs") #Добавить текущее время
x = os.system(f"mv {dir_config + i} {dir_config}deactivated/{i} 2>> {dir_config}logs") #Добавить текущее время
if x == 0:
print(f"Карта деактивирована - {i}")
else:

@ -4,14 +4,40 @@ import os
import telebot
from telebot import types
import subprocess
import yaml
import colorama
import hlna
key_api = '6192661772:AAHB1dw4rXHOglgyTOpcsxwvLn4d3AKkvP4'
#key_api = input("Укажите ключ бота\n")
hlna_bot = telebot.TeleBot(f"{key_api}", parse_mode=None)
map_server = hlna.list_config
list_config = hlna.list_config
k_api = ""
def read_config():
with open(f"{hlna.dir_config} + hlna_bot", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
return data[0] # возвращаем словарь со всеми значениями
def create_config():
k_api = key_api
config_hlna_bot = [
{
'key_api': k_api,
}
]
with open(f"hlna.config_hlna", 'w') as yamlfile:
yaml.dump(f"{config_hlna_bot} + hlna_bot", yamlfile)
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
return k_api
read_config()
if k_api == "":
key_api = input("Укажите ключ бота\n")
create_config()
read_config()
hlna_bot = telebot.TeleBot(f"{k_api}", parse_mode=None)
@hlna_bot.message_handler(commands=["start"])
def m_start(m):
@ -37,16 +63,17 @@ def m_start(m):
@hlna_bot.message_handler(content_types=["text"])
def m_chose(m):
if m.text.strip() == '🦖 Старт':
if map_server == []:
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.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 map_server:
for i in list_config:
k_mapname = types.KeyboardButton(f"{i}")
menu_start.add(k_mapname)
k_back = types.KeyboardButton("Назад")
@ -56,11 +83,14 @@ def m_chose(m):
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 starting")
print("Bot started")
hlna_bot.polling(none_stop=True, interval=0, timeout=999)
# print("Start")