Ejemplo n.º 1
0
def watch_wishlist_inline(chosen_inline_result):
    """
    inline-метод, позволяющий публиковать в чате игры из своего вишлиста
    :param chosen_inline_result: пустая строка
    """
    print('общий инлайнер')
    try:
        with session_scope() as session:
            wishes = Wish.get_all(user_id=chosen_inline_result.from_user.id,
                                  session=session)
            games = [
                Game.get(id=wish.game_id, session=session) for wish in wishes
            ]

            bot.answer_inline_query(
                inline_query_id=chosen_inline_result.id,
                results=[
                    types.InlineQueryResultPhoto(
                        id=game.id,
                        title=game.name,
                        photo_url=game.poster_url,
                        thumb_url=game.poster_url,
                        caption=str(game),
                        parse_mode='MARKDOWN',
                        input_message_content=types.InputMediaPhoto(
                            caption=str(game),
                            parse_mode='MARKDOWN',
                            media=get_image_bytes(game.poster_url)),
                    ) for i, game in enumerate(
                        sorted(games, key=lambda x: x.name))
                ],
                switch_pm_text='Добавить игр?',
                switch_pm_parameter='start')
    except Exception as e:
        print(e)
Ejemplo n.º 2
0
def get_wishlist(message):
    """просто получить вишлист"""
    with session_scope() as session:
        wishlist = Wish.get_all(user_id=message.chat.id, session=session)
        games = [
            Game.get(id=wish.game_id, session=session) for wish in wishlist
        ]
        if games:
            response = '\n'.join([
                f'{i}) {game}'
                for i, game in enumerate(sorted(games, key=lambda x: x.name),
                                         start=1)
            ])
        else:
            response = 'Твой вишлист пуст :('
        bot.send_message(chat_id=message.chat.id,
                         text=response,
                         parse_mode='MARKDOWN')