Skip to content

Commit

Permalink
Готово, осталось дописать шаблон!
Browse files Browse the repository at this point in the history
  • Loading branch information
islamcscom committed Feb 24, 2023
1 parent 6a7b030 commit 529c8ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cuttle_builder/APIFileCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def create_commands_file(self, code: str) -> None:
Path(self._bot_directory) / 'on_startup_commands.py')
self._write_file_insert(path_to_file, code)

def create_utils_file(self, code: str) -> None:
"""
Создает файл с кодом функции для сохранения username и user id
Args:
code (str): Подготовленный код(содержимое файла)
"""
assert isinstance(code, str)

path_to_file = str(
Path(self._bot_directory) / 'utils' / 'save_id_and_username.py')
self._write_file_insert(path_to_file, code)

def create_config_file(self, code) -> None:
assert isinstance(code, str)

Expand Down
14 changes: 12 additions & 2 deletions cuttle_builder/bot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def create_bot(self) -> None:
self._create_app_file()
self._create_on_startup_commands_file()
self._create_log_dir_if_it_doesnt_exist()
self._create_utils_file()
for message in self._messages:
self.create_file_handlers(message)
self._create_init_handler_files()
Expand Down Expand Up @@ -135,10 +136,13 @@ def create_file_handlers(self, message: BotMessage) -> None:
# Создание клавиатуры для сообщения.
keyboard_name = self.create_keyboard(message.id, keyboard_type)
keyboard_generation_counter += 1

additional_functions_from_top_of_answer += self._tab_from_new_line('save_id_and_username('
'message.from_user.id, '
'message.from_user.name)')
# Создание стартовых хэндлеров.
imports_for_start_handler = imports_for_handler + '\n' + 'from aiogram.dispatcher.filters import ' \
'Command'
'Command\n' \
'from utils.save_id_and_username import save_id_and_username'
start_handler_code = self._create_state_handler(
command='start',
prev_state='*',
Expand Down Expand Up @@ -381,6 +385,12 @@ def _create_on_startup_commands_file(self) -> None:
commands_code = generate_commands_code(self._commands)
self._file_manager.create_commands_file(commands_code)

def _create_utils_file(self) -> None:
utils_method = str(
CUTTLE_BUILDER_PATH / 'builder' / 'additional' / 'samples' / 'save_id_and_username.txt')
code = self._file_manager.read_text_file_content(utils_method)
self._file_manager.create_utils_file(code)

def _create_state(self) -> str:
"""generate code of state class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
async def save_id_and_username(id, username):
user_id = message.from_user.id # TODO Сохранение в JSON файл в директории бота
username = user.username# TODO Сохранение в JSON файл в директории бота
return user_id, username

0 comments on commit 529c8ab

Please sign in to comment.