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

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

View File

@ -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")