Skip to content

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

Open
olred wants to merge 1 commit into
devfrom
dev2
Open

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

Conversation

@olred

@olred olred commented Mar 1, 2023

Copy link
Copy Markdown
Owner

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/manager.py
self.time_end = {}
self.storage = {}

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/manager.py
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",
),
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/manager.py
)
)
for update in updates:
if update.object.chat_id not in self.active_chats.keys():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/poller.py
@@ -0,0 +1,25 @@
import asyncio
from asyncio import Task

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/manager.py
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}",
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Comment thread app/store/bot/manager.py
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 == "Начать игру!":

Copy link
Copy Markdown

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
и каждую функцию сценария отдельно вынести

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread app/store/bot/manager.py
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"Игра остановлена!")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Comment thread app/store/bot/manager.py
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]}")
)

Copy link
Copy Markdown

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