Skip to content

Прочитайте, пожалуйста, файл READ_INSTRUCTION.txt, надеюсь станет пон…#3

Open
olred wants to merge 1 commit intodevfrom
dev2
Open

Прочитайте, пожалуйста, файл READ_INSTRUCTION.txt, надеюсь станет пон…#3
olred wants to merge 1 commit intodevfrom
dev2

Conversation

@olred
Copy link
Owner

@olred olred commented Mar 1, 2023

Исходник кода до встречи, не туда в начале пулл кинул

@@ -1,3 +1,113 @@
# User-specific stuff
.idea/**/workspace.xml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется gitignore не сработал
image

text=f"Нельзя загружать фотографии во время игры!",
)
)
if update.object.body == "Начать игру!":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Весь текст точно нужно вынести в отдельный модуль с const-ми

self.time_end = {}
self.storage = {}

async def handle_updates(self, updates: list[Update]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 строк - это очень много для 1 функции

Comment on lines +51 to +62
for i in self.storage.keys():
if time() - self.storage[i][0] > 30 and self.storage[i][1]:
updates.append(
Update(
type="time_out",
object=UpdateObject(
chat_id=i,
id=-1,
body="time_out",
),
)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не совсем понятно, причем тут это, когда по сообщениям проходим

)
)
for update in updates:
if update.object.chat_id not in self.active_chats.keys():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не очень хорошо, чтобы наш бот был statefull. Иначе мы не сможем его масштабировать
Например, если я захочу 3 таких приложения запустить, чтобы больше чатов мочь обработать

@@ -0,0 +1,25 @@
import asyncio
from asyncio import Task

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется где то я это уже видел

Comment on lines +104 to +109
await self.app.store.vk_api.send_message(
Message(
chat_id=update.object.chat_id,
text=f"Последний победитель: {this_chat.last_winner}",
)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Жесткий копипаст этой строки

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя на самом деле просто текст меняется

  • ты сообщения отправляешь 1 за другим, а мог бы сразу пачкой из нескольких, если это предусмотрено твоим ботом

Comment on lines +70 to +83
if update.object.body == "Регистрация!":
await self.command_registery(update)
if update.object.body == "Загрузить фотографии!" or this_chat.state_photo:
if not this_chat.state_in_game:
this_chat.state_photo = True
await self.command_download_photo(update, this_chat)
else:
await self.app.store.vk_api.send_message(
Message(
chat_id=update.object.chat_id,
text=f"Нельзя загружать фотографии во время игры!",
)
)
if update.object.body == "Начать игру!":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Огромную эту простыню, можно свести к

strategies: dict[str, func] = {}
strategy = strategiescmd
и каждую функцию сценария отдельно вынести

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

код схематичный, главное суть

Comment on lines +321 to +331
await self.app.store.vk_api.send_message(
Message(chat_id=update.object.chat_id, text="Оставшиеся пользователи:")
)
for i in this_chat.users:
await self.app.store.vk_api.send_message(
Message(chat_id=update.object.chat_id, text=f"{i[0]}")
)
this_chat.reset_values()
self.storage[update.object.chat_id][1] = False
await self.app.store.vk_api.send_message(
Message(chat_id=update.object.chat_id, text=f"Игра остановлена!")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

посчитай количество запросов по сути если игроков много
что делать, если их 100?

кажется, что ждать 1 отправку за другой - плохое решение

Comment on lines +324 to +327
for i in this_chat.users:
await self.app.store.vk_api.send_message(
Message(chat_id=update.object.chat_id, text=f"{i[0]}")
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

синхронный код получается

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants