def send_chat_list(client: Client, user: User, update: Union[Message, CallbackQuery]): chats = AllowedChat.objects.filter(creator=user, status='activated') clean_chats = [] for chat in chats: try: client.resolve_peer(chat.chat_id) clean_chats.append(chat) except ChannelInvalid as exc: logger.info(f'### Error {chat}: {type(exc)}: {exc}') if not clean_chats: text = user.choice_localized(text_name='msg-owner-empty') button_text = user.choice_localized(text_name='btn-owner-add-bot') bot = client.get_me() client.send_message(user.id, text, reply_markup=markup_add_to_chat( bot.username, button_text)) return text = user.choice_localized(text_name='msg-owner') if isinstance(update, Message): update.reply_text(text, reply_markup=markup_chat_list(clean_chats)) if isinstance(update, CallbackQuery): update.message.edit_text(text, reply_markup=markup_chat_list(clean_chats))
def _button_win(app: Client, user: User, dice_msg: Message, event, event_local=None): take_money_btn_text = user.choice_localized(text_name='btn-chat-win') take_money_msg_text = user.choice_localized( text_name='msg-chat-win').format(X=event.summa, coin_ticker=event.coin) if event_local: take_money_msg_text += f' + {event_local.summa} {event_local.coin}' bot = app.get_me() dice_msg.reply(take_money_msg_text, reply_markup=markup_take_money(bot.username, take_money_btn_text))
def handle_missed_notifications(app: Client, user: User): missed_notifies = DiceEvent.objects.filter(user=user, is_win=True, is_notified=False) count = len(missed_notifies) if not count: return missed_notifies.update(is_notified=True) notify_text = user.choice_localized(text_name='msg-notify-missed-rewards') app.send_message(user.id, notify_text, reply_markup=kb_home(user))
def _notify_win(app: Client, user: User, event, event_local=None): local_text = '' if event_local: local_text = f' + {event_local.summa} {event_local.coin}' win_text = user.choice_localized(text_name='msg-chat-win-notify') win_text = win_text.format(X=event.summa, coin=event.coin) + local_text try: app.send_message(user.id, win_text) event.is_notified = True event.save() except RPCError: logger_dice_event.exception( f'### Err sending user ({user}) win notify. Event {event}')