Exemple #1
0
def button_pin(bot: octobot.OctoBot, context: octobot.Context):
    chat_id, message_id = context.text.split(":")[1:]
    perm_check, missing_perms = octobot.check_permissions(
        chat=chat_id,
        user=context.user.id,
        bot=bot,
        permissions_to_check={"can_pin_messages"})
    if perm_check:
        bot.pin_chat_message(chat_id, message_id, disable_notification=True)
        context.reply(context.localize("Pinned back the old message"))
        msg = context.update.effective_message.text_html + "\n\n" + context.localize(
            'This action was undone by <a href="tg://user?id={admin_id}">{admin}</a>'
        ).format(admin_id=context.user.id,
                 admin=html.escape(context.user.first_name))
        context.edit(msg, parse_mode="HTML")
    else:
        context.reply(
            context.localize(
                "Sorry, you can't execute this command cause you lack following permissions: {}"
            ).format(", ".join(missing_perms)))
Exemple #2
0
def execute_cancel(bot: octobot.OctoBot, context: octobot.Context,
                   func: typing.Callable, reply_text: str):
    tgt_id, chat_id = context.text.split(":")[1:]
    perm_check, missing_perms = octobot.check_permissions(
        chat=chat_id,
        user=context.user.id,
        bot=bot,
        permissions_to_check={"can_restrict_members"})
    if perm_check:
        if tgt_id.isdigit():
            func(chat_id=chat_id, user_id=tgt_id)
            context.reply(reply_text)
            msg = context.update.effective_message.text_html + "\n\n" + context.localize(
                'This action was undone by <a href="tg://user?id={admin_id}">{admin}</a>'
            ).format(admin_id=context.user.id,
                     admin=html.escape(context.user.first_name))
            context.edit(msg, parse_mode="HTML")
        else:
            context.reply(context.localize("Invalid ID passed"))
    else:
        context.reply(
            context.localize(
                "Sorry, you can't execute this command cause you lack following permissions: {}"
            ).format(", ".join(missing_perms)))