How to use mdformat - 10 common examples

To help you get started, we’ve selected a few mdformat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JosXa / BotListBot / botlistbot / components / botproperties.py View on Github external
def set_text_property(bot, update, chat_data, property_name, to_edit=None):
    uid = util.uid_from_update(update)
    user = User.from_update(update)
    if check_suggestion_limit(bot, update, user):
        return

    if to_edit:
        text = (
            util.escape_markdown(getattr(to_edit, property_name)) + "\n\n" if getattr(to_edit,
                                                                                      property_name) else '')
        text += mdformat.action_hint(
            messages.SET_BOTPROPERTY.format(
                property_name,
                util.escape_markdown(to_edit.username),
                CLEAR_QUERY
            ))
        if property_name == 'description':
            text += ', markdown enabled.'
        update.effective_message.reply_text(text, reply_markup=ForceReply(selective=True),
                                            parse_mode=ParseMode.MARKDOWN)
        chat_data['edit_bot'] = to_edit
    elif update.message:
        value = None
        text = update.message.text

        to_edit = chat_data.get('edit_bot', None)
github JosXa / BotListBot / botlistbot / components / broadcasts.py View on Github external
)
                user_data['broadcast']['mode'] = 'replying'
        # answer and clean
        msg = bot.send_message(cid, "k")
        _delete_multiple_delayed(bot, cid, delayed=[msg.message_id], immediately=[update.message.message_id])

    to_text = "  _to_  "
    text += "Send me the text to broadcast to @BotListChat.\n"
    text += "_You can use the following words and they will replaced:_\n\n"

    text += '\n'.join(['"{}"{}{}'.format(k, to_text, v) for k, v in BROADCAST_REPLACEMENTS.items()])

    # TODO Build text mentioning replacements
    # text += '\n@' + str(update.effective_user.username) + to_text + user.markdown_short

    bot.formatter.send_or_edit(uid, mdformat.action_hint(text), mid)
    return BotStates.BROADCASTING
github JosXa / BotListBot / botlistbot / components / favorites.py View on Github external
from components.basic import main_menu_buttons
    main_menu_markup = ReplyKeyboardMarkup(main_menu_buttons(uid in settings.MODERATORS))

    fav, created = Favorite.add(user=user, item=item)
    if created:
        Statistic.of(user, 'add-favorite', item.username)
        text = mdformat.love("{} added to your {}favorites.".format(fav.bot, '' if callback_alert else '/'))
        if callback_alert:
            update.callback_query.answer(text=text, show_alert=False)
        else:
            msg = util.send_md_message(bot, uid, text, to_edit=mid, reply_markup=main_menu_markup)
            mid = msg.message_id
            util.wait(bot, update)
            send_favorites_list(bot, update, to_edit=mid)
    else:
        text = mdformat.none_action(
            "{} is already a favorite of yours.{}".format(fav.bot, '' if callback_alert else ' /favorites'))
        if callback_alert:
            update.callback_query.answer(text=text, show_alert=False)
        else:
            util.send_md_message(bot, uid, text, reply_markup=main_menu_markup)
    return ConversationHandler.END
github JosXa / BotListBot / botlistbot / components / favorites.py View on Github external
def add_custom(bot, update, username):
    uid = util.uid_from_update(update)
    user = User.from_update(update)
    mid = util.mid_from_update(update)
    from components.basic import main_menu_buttons
    main_menu_markup = ReplyKeyboardMarkup(main_menu_buttons(uid in settings.MODERATORS))

    try:
        fav = Favorite.get(custom_bot=username)
        util.send_or_edit_md_message(
            bot, uid, mdformat.none_action(
                "{} is already a favorite of yours. /favorites".format(fav.custom_bot)),
            to_edit=mid,
            reply_markup=main_menu_markup)
    except Favorite.DoesNotExist:
        fav = Favorite(user=user, custom_bot=username, date_added=datetime.date.today())
        fav.save()
        msg = bot.formatter.send_or_edit(uid,
                                           mdformat.love("{} added to your /favorites.".format(fav.custom_bot)),
                                           to_edit=mid)
        mid = msg.message_id
        util.wait(bot, update)
        send_favorites_list(bot, update, to_edit=mid)
    return ConversationHandler.END
github JosXa / BotListBot / botlistbot / components / broadcasts.py View on Github external
msg = bot.formatter.send_or_edit(recipient, text, to_edit=mid)
    else:
        msg = util.send_md_message(bot, recipient, text)

    # Post actions
    buttons = [
        InlineKeyboardButton(captions.PIN,
                             callback_data=util.callback_for_action('pin_message', {'mid': msg.message_id})),
        InlineKeyboardButton('Add "Thank You" counter',
                             callback_data=util.callback_for_action('add_thank_you',
                                                                    {'cid': recipient, 'mid': msg.message_id})),
    ]
    reply_markup = InlineKeyboardMarkup(util.build_menu(buttons, 1))
    mid = util.mid_from_update(update)
    action_taken = "edited" if mode == 'editing' else "broadcasted"
    bot.formatter.send_or_edit(uid, mdformat.success("Message {}.".format(action_taken)), mid, reply_markup=reply_markup)
github JosXa / BotListBot / botlistbot / components / favorites.py View on Github external
def add_favorite(bot, update, item: Bot, callback_alert=None):
    user = User.from_update(update)
    uid = util.uid_from_update(update)
    mid = util.mid_from_update(update)
    from components.basic import main_menu_buttons
    main_menu_markup = ReplyKeyboardMarkup(main_menu_buttons(uid in settings.MODERATORS))

    fav, created = Favorite.add(user=user, item=item)
    if created:
        Statistic.of(user, 'add-favorite', item.username)
        text = mdformat.love("{} added to your {}favorites.".format(fav.bot, '' if callback_alert else '/'))
        if callback_alert:
            update.callback_query.answer(text=text, show_alert=False)
        else:
            msg = util.send_md_message(bot, uid, text, to_edit=mid, reply_markup=main_menu_markup)
            mid = msg.message_id
            util.wait(bot, update)
            send_favorites_list(bot, update, to_edit=mid)
    else:
        text = mdformat.none_action(
            "{} is already a favorite of yours.{}".format(fav.bot, '' if callback_alert else ' /favorites'))
        if callback_alert:
            update.callback_query.answer(text=text, show_alert=False)
        else:
            util.send_md_message(bot, uid, text, reply_markup=main_menu_markup)
    return ConversationHandler.END
github JosXa / BotListBot / botlistbot / components / favorites.py View on Github external
mid = util.mid_from_update(update)
    from components.basic import main_menu_buttons
    main_menu_markup = ReplyKeyboardMarkup(main_menu_buttons(uid in settings.MODERATORS))

    try:
        fav = Favorite.get(custom_bot=username)
        util.send_or_edit_md_message(
            bot, uid, mdformat.none_action(
                "{} is already a favorite of yours. /favorites".format(fav.custom_bot)),
            to_edit=mid,
            reply_markup=main_menu_markup)
    except Favorite.DoesNotExist:
        fav = Favorite(user=user, custom_bot=username, date_added=datetime.date.today())
        fav.save()
        msg = bot.formatter.send_or_edit(uid,
                                           mdformat.love("{} added to your /favorites.".format(fav.custom_bot)),
                                           to_edit=mid)
        mid = msg.message_id
        util.wait(bot, update)
        send_favorites_list(bot, update, to_edit=mid)
    return ConversationHandler.END
github JosXa / BotListBot / botlistbot / lib / markdownformatter.py View on Github external
def send_action_hint(self, chat_id, text: str, **kwargs):
        if text[-1] == '.':
            text = text[0:-1]
        return self.bot.sendMessage(
            chat_id,
            action_hint(text),
            **self._set_defaults(kwargs))
github JosXa / BotListBot / botlistbot / components / admin.py View on Github external
def prepare_transmission(bot, update, chat_data):
    chat_id = util.uid_from_update(update)
    pending_update(bot, update)
    text = mdformat.action_hint("Notify subscribers about this update?")
    reply_markup = InlineKeyboardMarkup(
        [
            [
                InlineKeyboardButton(
                    "☑ Notifications",
                    callback_data=util.callback_for_action(
                        CallbackActions.SEND_BOTLIST, {"silent": False}
                    ),
                ),
                InlineKeyboardButton(
                    "Silent",
                    callback_data=util.callback_for_action(
                        CallbackActions.SEND_BOTLIST, {"silent": True}
                    ),
                ),
            ],
github JosXa / BotListBot / botlistbot / components / basic.py View on Github external
def main_menu(bot, update):
    chat_id = update.effective_chat.id
    is_admin = chat_id in settings.MODERATORS
    reply_markup = (
        ReplyKeyboardMarkup(
            main_menu_buttons(is_admin), resize_keyboard=True, one_time_keyboard=True
        )
        if util.is_private_message(update)
        else ReplyKeyboardRemove()
    )

    bot.sendMessage(
        chat_id,
        mdformat.action_hint("What would you like to do?"),
        reply_markup=reply_markup,
    )

mdformat

CommonMark compliant Markdown formatter

MIT
Latest version published 26 days ago

Package Health Score

78 / 100
Full package analysis

Similar packages