мааааленькая работа над ботом
This commit is contained in:
parent
8148537b36
commit
8aeb00cef1
18
hlna.py
18
hlna.py
@ -13,8 +13,8 @@ import click_completion
|
|||||||
from rcon.source import Client
|
from rcon.source import Client
|
||||||
|
|
||||||
home_dir = Path.home()
|
home_dir = Path.home()
|
||||||
dir_server = f"{home_dir}/ARK_Servers/Server"
|
dir_server = f"{home_dir}/ARK_Servers/"
|
||||||
config_hlna = f"{home_dir}/.config/hlna/"
|
dir_config = f"{home_dir}/.config/hlna/"
|
||||||
mods_id = ""
|
mods_id = ""
|
||||||
listen_server = True
|
listen_server = True
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ def find_file(path):
|
|||||||
return arr
|
return arr
|
||||||
|
|
||||||
|
|
||||||
list_config = find_file(config_hlna)
|
list_config = find_file(dir_config)
|
||||||
delist_config = find_file(config_hlna+"deactivated")
|
delist_config = find_file(dir_config+"deactivated")
|
||||||
|
|
||||||
|
|
||||||
def print_line(text):
|
def print_line(text):
|
||||||
@ -67,7 +67,7 @@ def check_int(number=""):
|
|||||||
|
|
||||||
|
|
||||||
create_dir(dir_server)
|
create_dir(dir_server)
|
||||||
create_dir(config_hlna)
|
create_dir(dir_config)
|
||||||
|
|
||||||
|
|
||||||
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
@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
|
'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)
|
yaml.dump(settings_hlna, yamlfile)
|
||||||
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ def enablemap(m,e):
|
|||||||
"""Тут переписать надо"""
|
"""Тут переписать надо"""
|
||||||
m = m.split(",")
|
m = m.split(",")
|
||||||
# m = check_name_map(m, False)
|
# m = check_name_map(m, False)
|
||||||
create_dir(config_hlna + "deactivated")
|
create_dir(dir_config + "deactivated")
|
||||||
if e == True:
|
if e == True:
|
||||||
port_s = []
|
port_s = []
|
||||||
query_p = []
|
query_p = []
|
||||||
@ -279,7 +279,7 @@ def enablemap(m,e):
|
|||||||
print("Предлагаем заменить")
|
print("Предлагаем заменить")
|
||||||
if data['QueryPort'] in query_p:
|
if data['QueryPort'] in query_p:
|
||||||
print("Заменить query port?")
|
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:
|
if x == 0:
|
||||||
print(f"Карта активирована - {i}")
|
print(f"Карта активирована - {i}")
|
||||||
else:
|
else:
|
||||||
@ -294,7 +294,7 @@ def enablemap(m,e):
|
|||||||
if i in delist_config:
|
if i in delist_config:
|
||||||
print(f"Карта {i} уже есть в деактивированных")
|
print(f"Карта {i} уже есть в деактивированных")
|
||||||
continue
|
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:
|
if x == 0:
|
||||||
print(f"Карта деактивирована - {i}")
|
print(f"Карта деактивирована - {i}")
|
||||||
else:
|
else:
|
||||||
|
48
hlna_bot.py
48
hlna_bot.py
@ -4,14 +4,40 @@ import os
|
|||||||
import telebot
|
import telebot
|
||||||
from telebot import types
|
from telebot import types
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import yaml
|
||||||
|
import colorama
|
||||||
import hlna
|
import hlna
|
||||||
|
|
||||||
key_api = '6192661772:AAHB1dw4rXHOglgyTOpcsxwvLn4d3AKkvP4'
|
list_config = hlna.list_config
|
||||||
#key_api = input("Укажите ключ бота\n")
|
k_api = ""
|
||||||
hlna_bot = telebot.TeleBot(f"{key_api}", parse_mode=None)
|
|
||||||
map_server = hlna.list_config
|
|
||||||
|
|
||||||
|
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"])
|
@hlna_bot.message_handler(commands=["start"])
|
||||||
def m_start(m):
|
def m_start(m):
|
||||||
@ -37,16 +63,17 @@ def m_start(m):
|
|||||||
@hlna_bot.message_handler(content_types=["text"])
|
@hlna_bot.message_handler(content_types=["text"])
|
||||||
def m_chose(m):
|
def m_chose(m):
|
||||||
if m.text.strip() == '🦖 Старт':
|
if m.text.strip() == '🦖 Старт':
|
||||||
if map_server == []:
|
if list_config == []:
|
||||||
menu_install = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
menu_install = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
||||||
k_install = types.KeyboardButton("Установить")
|
k_install = types.KeyboardButton("Установить")
|
||||||
k_back = types.KeyboardButton("Назад")
|
k_back = types.KeyboardButton("Назад")
|
||||||
menu_install.add(k_back, k_install)
|
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)
|
hlna_bot.register_next_step_handler(m, m_install)
|
||||||
else:
|
else:
|
||||||
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
||||||
for i in map_server:
|
for i in list_config:
|
||||||
k_mapname = types.KeyboardButton(f"{i}")
|
k_mapname = types.KeyboardButton(f"{i}")
|
||||||
menu_start.add(k_mapname)
|
menu_start.add(k_mapname)
|
||||||
k_back = types.KeyboardButton("Назад")
|
k_back = types.KeyboardButton("Назад")
|
||||||
@ -56,11 +83,14 @@ def m_chose(m):
|
|||||||
m_start(m)
|
m_start(m)
|
||||||
# elif m.text.strip() == 'TheIsland':
|
# elif m.text.strip() == 'TheIsland':
|
||||||
# hlna.start()
|
# hlna.start()
|
||||||
|
|
||||||
|
|
||||||
def m_install(m):
|
def m_install(m):
|
||||||
if m.text.strip() == 'Установить':
|
if m.text.strip() == 'Установить':
|
||||||
hlna_bot.send_message(m.chat.id, subprocess.check_output(hlna.config(), shell=True))
|
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)
|
hlna_bot.polling(none_stop=True, interval=0, timeout=999)
|
||||||
|
|
||||||
# print("Start")
|
# print("Start")
|
||||||
|
Loading…
Reference in New Issue
Block a user