示例#1
0
    def stop_user(self, message: Message):
        """
        Make the subscriber inactive.
        """

        logger.show_msg(message)
        database = Database()
        database.stop_following(message.chat.id)
        self.typing(1, message)
        self.bot.send_message(chat_id=message.chat.id,
                              text="Прощайте.\n"
                              "Надеемся, вы вернётесь 😌")
示例#2
0
    def show_about(self, message: Message):
        """
        Send a message to the user with information about the author.
        """

        logger.show_msg(message)
        self.typing(1, message)
        self.bot.send_message(
            chat_id=message.chat.id,
            parse_mode='Markdown',
            text="`Я являюсь небольшим пет-проектом для трекинга скидок 🤖\n"
            "Хотите увидеть внутренности?\n"
            "Ваша воля, господин!`\n"
            "https://github.com/ars-kalinichenko/BookSalesBot")
示例#3
0
    def start_user(self, message: Message):
        """
        Send a welcome message to the user and makes his status active.
        """

        logger.show_msg(message)
        database = Database()
        database.start_following(message.chat.id)
        self.typing(1, message)
        self.bot.send_message(
            chat_id=message.from_user.id,
            parse_mode='Markdown',
            text="Привет, я помогу тебе отслеживать скидки на книги!\n"
            "Хочешь добавить книгу?\n"
            "Просто отправь `ссылку` на неё.")
示例#4
0
    def show_help(self, message: Message):
        """
        Send a message to the user with prompts.
        """

        logger.show_msg(message)
        self.typing(2, message)
        self.bot.send_message(
            chat_id=message.chat.id,
            text=
            "Я, как чистокровный робот, помогу тебе не сойти с ума в мире книжных скидок 🤖\n"
            "*нет, я не уничтожу мир 🙄*\n\n"
            "Если ты хочешь включить активный режим, то добавь новую книгу или отправь /start\n"
            "Если же ты хочешь выключить активный режим и впредь не получать сообщений, "
            "отправь /stop\n"
            "Хочешь посмотреть свои подписки или удалить книгу? Нажимай /list\n"
            "Хочешь посмотреть на код или кинуть донат? Тебе сюда /about")
示例#5
0
    def show_list(self, message: Message):
        """
        Show a list of subscriptions from the database, attaching a delete button.

        If the user does not exist or the list is empty,
         then the message that the list is empty is displayed.
        If the image does not exist, only text is sent.
        """

        logger.show_msg(message)
        database = Database()
        parser = ParserManager()
        markup = InlineKeyboardMarkup()
        markup.add(
            InlineKeyboardButton(text="Удалить", callback_data="delete_book"))

        subscriptions = database.get_subscriptions(message.chat.id)

        if subscriptions == [None] or not subscriptions:
            self.typing(0.3, message)
            self.bot.send_message(message.chat.id, "Кажется, ничего нет 🤕")

        else:
            for subscription in database.get_subscriptions(message.chat.id):
                detail_book = parser.parsing_book(subscription)
                image_path = f"images/{detail_book['image_name']}"
                self.uploading_photo(0.2, message)

                if os.path.exists(image_path):
                    reply_msg = self.bot.send_photo(
                        chat_id=message.chat.id,
                        photo=open(f"images/{detail_book['image_name']}",
                                   'rb'),
                        caption=
                        f"{detail_book['title']} ({detail_book['price']}р.)",
                        reply_markup=markup)
                else:
                    reply_msg = self.bot.send_message(
                        chat_id=message.chat.id,
                        text=
                        f"{detail_book['title']} ({detail_book['price']}р.)",
                        reply_markup=markup)

                self.book_to_delete[reply_msg.message_id] = detail_book
示例#6
0
    def adding_book(self, message: Message):
        """
        Respond to a message asking to add, and then
         asks the user to add a book to the subscription using the buttons.

        If the link is not valid, then a message is sent asking
         to enter the correct link and the error is logged
        If the image does not exist, only text is sent.
        """

        logger.show_msg(message)
        markup = InlineKeyboardMarkup()
        markup.add(InlineKeyboardButton(text="Да", callback_data="add_link"))
        markup.add(
            InlineKeyboardButton(text="Нет", callback_data="no_add_link"))
        parser = ParserManager()

        try:
            link = message.text.strip()
            book = parser.parsing_book(link)
            image_path = f"images/{book['image_name']}"
            case_rub = f'рубл{detail.ruble_cases[book["price"] % 100]}'

            if os.path.exists(image_path):
                self.uploading_photo(0.5, message)
                reply_msg = self.bot.send_photo(
                    message.chat.id,
                    photo=open(image_path, 'rb'),
                    caption='Вы уверены, что хотите добавить:\n'
                    f'"{book["title"]}" за {book["price"]} {case_rub}?',
                    reply_markup=markup)

                logger.show_caption_photo(reply_msg)
            else:
                reply_msg = self.bot.send_message(
                    message.chat.id,
                    text='Вы уверены, что хотите добавить:\n'
                    f'"{book["title"]}" за {book["price"]} {case_rub}?',
                    reply_markup=markup)
                logger.show_msg(reply_msg)
            self.book_to_add[reply_msg.message_id] = book

        except:
            self.typing(1, message)
            error_msg = self.bot.send_message(message.chat.id,
                                              "Введите правильную ссылку!")
            logger.show_msg(error_msg)