# Path: botlistbot/mdformat.py
# def success(text):
#     return '{} {}'.format(Emoji.WHITE_HEAVY_CHECK_MARK, text, hide_keyboard=True)
# 
# def failure(text):
#     return '{} {}'.format(Emoji.CROSS_MARK, text)
# 
# def action_hint(text):
#     return '💬 {}'.format(text)


from botlistbot.mdformat import success, failure, action_hint
from telegram import Message, constants
from telegram import ParseMode
from telegram import ReplyKeyboardRemove
from telegram.error import BadRequest

class MarkdownFormatter:
    def __init__(self, bot):
        self.bot = bot

    @staticmethod
    def _set_defaults(kwargs):
        if 'disable_web_page_preview' not in kwargs:
            kwargs['disable_web_page_preview'] = True
        if 'parse_mode' not in kwargs:
            kwargs['parse_mode'] = ParseMode.MARKDOWN
        return kwargs

    def send_message(self, chat_id, text: str, **kwargs):
        if len(text) <= constants.MAX_MESSAGE_LENGTH:
            return self.bot.sendMessage(chat_id, text, **self._set_defaults(kwargs))

        parts = []
        while len(text) > 0:
            if len(text) > constants.MAX_MESSAGE_LENGTH:
                part = text[:constants.MAX_MESSAGE_LENGTH]
                first_lnbr = part.rfind('\n')
                parts.append(part[:first_lnbr])
                text = text[first_lnbr:]
            else:
                parts.append(text)
                break

        msg = None
        for part in parts:

# Path: botlistbot/mdformat.py
# def success(text):
#     return '{} {}'.format(Emoji.WHITE_HEAVY_CHECK_MARK, text, hide_keyboard=True)
# 
# def failure(text):
#     return '{} {}'.format(Emoji.CROSS_MARK, text)
# 
# def action_hint(text):
#     return '💬 {}'.format(text)


# Path: botlistbot/lib/markdownformatter.py
from botlistbot.mdformat import success, failure, action_hint
from telegram import Message, constants
from telegram import ParseMode
from telegram import ReplyKeyboardRemove
from telegram.error import BadRequest


class MarkdownFormatter:
    def __init__(self, bot):
        self.bot = bot

    @staticmethod
    def _set_defaults(kwargs):
        if 'disable_web_page_preview' not in kwargs:
            kwargs['disable_web_page_preview'] = True
        if 'parse_mode' not in kwargs:
            kwargs['parse_mode'] = ParseMode.MARKDOWN
        return kwargs

    def send_message(self, chat_id, text: str, **kwargs):
        if len(text) <= constants.MAX_MESSAGE_LENGTH:
            return self.bot.sendMessage(chat_id, text, **self._set_defaults(kwargs))

        parts = []
        while len(text) > 0:
            if len(text) > constants.MAX_MESSAGE_LENGTH:
                part = text[:constants.MAX_MESSAGE_LENGTH]
                first_lnbr = part.rfind('\n')
                parts.append(part[:first_lnbr])
                text = text[first_lnbr:]
            else:
                parts.append(text)
                break

        msg = None
        for part in parts:

            msg = self.bot.sendMessage(chat_id, part, **self._set_defaults(kwargs))