Conversation
| @@ -1,3 +1,113 @@ | |||
| # User-specific stuff | |||
| .idea/**/workspace.xml | |||
| text=f"Нельзя загружать фотографии во время игры!", | ||
| ) | ||
| ) | ||
| if update.object.body == "Начать игру!": |
There was a problem hiding this comment.
Весь текст точно нужно вынести в отдельный модуль с const-ми
| self.time_end = {} | ||
| self.storage = {} | ||
|
|
||
| async def handle_updates(self, updates: list[Update]): |
There was a problem hiding this comment.
100 строк - это очень много для 1 функции
| 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", | ||
| ), | ||
| ) | ||
| ) |
There was a problem hiding this comment.
не совсем понятно, причем тут это, когда по сообщениям проходим
| ) | ||
| ) | ||
| for update in updates: | ||
| if update.object.chat_id not in self.active_chats.keys(): |
There was a problem hiding this comment.
не очень хорошо, чтобы наш бот был statefull. Иначе мы не сможем его масштабировать
Например, если я захочу 3 таких приложения запустить, чтобы больше чатов мочь обработать
| @@ -0,0 +1,25 @@ | |||
| import asyncio | |||
| from asyncio import Task | |||
There was a problem hiding this comment.
кажется где то я это уже видел
| await self.app.store.vk_api.send_message( | ||
| Message( | ||
| chat_id=update.object.chat_id, | ||
| text=f"Последний победитель: {this_chat.last_winner}", | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Жесткий копипаст этой строки
There was a problem hiding this comment.
у тебя на самом деле просто текст меняется
- ты сообщения отправляешь 1 за другим, а мог бы сразу пачкой из нескольких, если это предусмотрено твоим ботом
| 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 == "Начать игру!": |
There was a problem hiding this comment.
Огромную эту простыню, можно свести к
strategies: dict[str, func] = {}
strategy = strategiescmd
и каждую функцию сценария отдельно вынести
There was a problem hiding this comment.
код схематичный, главное суть
| 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"Игра остановлена!") |
There was a problem hiding this comment.
посчитай количество запросов по сути если игроков много
что делать, если их 100?
кажется, что ждать 1 отправку за другой - плохое решение
| 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]}") | ||
| ) |

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