Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix send_all with Redis Error #22

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SUBSCRIPTION_CHANNELS_IDS=-12345678901234,-12345678901235
# Docker settings
BOT_CONTAINER_NAME=bot_container_name
BOT_IMAGE_NAME=botimage_name
BOT_NAME=mybotname

# DB settings
DB_USER=exampleDBUserName
Expand Down
10 changes: 8 additions & 2 deletions tgbot/handlers/admin/send_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ async def _confirm_send(message: types.Message, user: UserTG, state: FSMContext)


async def _ask_to_change_buttons(call: types.CallbackQuery, user: UserTG, state: FSMContext) -> None:
await call.answer()

text = """
Введите <b>ВСЕ</b> кнопки в формате:

Expand Down Expand Up @@ -66,7 +68,7 @@ async def _change_buttons(message: types.Message, user: UserTG, state: FSMContex
if buttons:
keyboard = send_all.broadcast_message_keyboard(buttons)
await user.edit_message_reply_markup(broadcast_message_id, reply_markup=keyboard)
await state.update_data(keyboard=keyboard)
await state.update_data(buttons=buttons)

await SendAllState.waiting_for_confirm.set()

Expand All @@ -81,14 +83,18 @@ async def _cancel(call: types.CallbackQuery, state: FSMContext, user: UserTG) ->


async def _start_broadcast(call: types.CallbackQuery, user: UserTG, state: FSMContext) -> None:
await call.answer()

data = await state.get_data()
broadcast_message_id: int = data.get("broadcast_message_id")
keyboard: types.InlineKeyboardMarkup = data.get("keyboard")
buttons: list[list[str]] | None = data.get("buttons")
keyboard = send_all.broadcast_message_keyboard(buttons) if buttons else None
await state.finish()

users_id = [user_id[0] for user_id in await User.select("id").where(User.is_banned == False).gino.all()]

await user.send_message(f'Рассылка на всех пользователей (<b>{len(users_id)}</b>) началась!')

broadcast_message = await call.bot.forward_message(call.message.chat.id, call.message.chat.id, broadcast_message_id)
await user.delete_message(broadcast_message.message_id)
await MessageBroadcaster(chats=users_id, message=broadcast_message, reply_markup=keyboard).run()
Expand Down