Ejemplo n.º 1
0
def permanent_pin(update, context):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message

    get_permapin = sql.get_permapin(chat.id)
    if get_permapin and not user.id == context.bot.id:
        try:
            to_del = context.bot.pinChatMessage(chat.id,
                                                get_permapin,
                                                disable_notification=True)
        except BadRequest:
            sql.set_permapin(chat.id, 0)
            if chat.username:
                old_pin = "https://t.me/{}/{}".format(chat.username,
                                                      get_permapin)
            else:
                old_pin = "https://t.me/c/{}/{}".format(
                    str(chat.id)[4:], get_permapin)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "*Permanent pin error:*\nI can't pin messages here!\nMake sure I'm admin and can pin messages.\n\nPermanent pin disabled now, [here is your old pinned message]({})"
                ).format(old_pin),
                parse_mode="markdown")
            return

        if to_del:
            try:
                context.bot.deleteMessage(chat.id, message.message_id + 1)
            except BadRequest:
                print("Permanent pin error: cannot delete pin msg")
Ejemplo n.º 2
0
def permanent_pin(bot: Bot, update: Update):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message

    get_permapin = sql.get_permapin(chat.id)
    if get_permapin and not user.id == bot.id:
        try:
            to_del = bot.pinChatMessage(chat.id,
                                        get_permapin,
                                        disable_notification=True)
        except BadRequest:
            sql.set_permapin(chat.id, 0)
            if chat.username:
                old_pin = "https://t.me/{}/{}".format(chat.username,
                                                      get_permapin)
            else:
                old_pin = "https://t.me/c/{}/{}".format(
                    str(chat.id)[4:], get_permapin)
            message.reply_text(
                "*Permanent pin error:*\nI can't pin messages here!\nMake sure I am an admin and can pin messages.\n\nPin permanently disabled, [old permanent pin message is here]({})"
                .format(old_pin),
                parse_mode="markdown")
            return

        if to_del:
            try:
                bot.deleteMessage(chat.id, message.message_id + 1)
            except BadRequest:
                print("Permanent pin error: cannot delete pin msg")
Ejemplo n.º 3
0
def permanent_pin_set(update, context):
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        if not args:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = tl(update.effective_message,
                            "Permanen pin saat ini di atur: `{}`").format(
                                bool(int(get_permapin)))
            if get_permapin:
                if chat.username:
                    old_pin = "https://t.me/{}/{}".format(
                        chat.username, get_permapin)
                else:
                    old_pin = "https://t.me/c/{}/{}".format(
                        str(chat.id)[4:], get_permapin)
                text_maker += tl(
                    update.effective_message,
                    "\nUntuk menonaktifkan permanen pin: `/permanentpin off`")
                text_maker += tl(
                    update.effective_message,
                    "\n\n[Pesan permanen pin ada disini]({})").format(old_pin)
            send_message(update.effective_message,
                         tl(update.effective_message, text_maker),
                         parse_mode="markdown")
            return ""
        prev_message = args[0]
        if prev_message == "off":
            sql.set_permapin(chat_id, 0)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Permanen pin telah di nonaktifkan!"))
            return
        if "/" in prev_message:
            prev_message = prev_message.split("/")[-1]
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "You can do this command in groups, not PM"))
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        if update.effective_message.reply_to_message:
            prev_message = update.effective_message.reply_to_message.message_id
        elif len(args) >= 1 and args[0] == "off":
            sql.set_permapin(chat.id, 0)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Permanen pin telah di nonaktifkan!"))
            return
        else:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = tl(update.effective_message,
                            "Permanen pin saat ini di atur: `{}`").format(
                                bool(int(get_permapin)))
            if get_permapin:
                if chat.username:
                    old_pin = "https://t.me/{}/{}".format(
                        chat.username, get_permapin)
                else:
                    old_pin = "https://t.me/c/{}/{}".format(
                        str(chat.id)[4:], get_permapin)
                text_maker += tl(
                    update.effective_message,
                    "\nUntuk menonaktifkan permanen pin: `/permanentpin off`")
                text_maker += tl(
                    update.effective_message,
                    "\n\n[Pesan permanen pin ada disini]({})").format(old_pin)
            send_message(update.effective_message,
                         text_maker,
                         parse_mode="markdown")
            return ""

    is_group = chat.type != "private" and chat.type != "channel"

    if prev_message and is_group:
        sql.set_permapin(chat.id, prev_message)
        send_message(
            update.effective_message,
            tl(update.effective_message, "Permanent pin berhasil di atur!"))
        return "<b>{}:</b>" \
            "\n#PERMANENT_PIN" \
            "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))

    return ""
Ejemplo n.º 4
0
def permanent_pin_set(bot: Bot, update: Update, args: List[str]) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        if not args:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = "Permanent pin is currently set: `{}`".format(
                bool(int(get_permapin)))
            if get_permapin:
                if chat.username:
                    old_pin = "https://t.me/{}/{}".format(
                        chat.username, get_permapin)
                else:
                    old_pin = "https://t.me/c/{}/{}".format(
                        str(chat.id)[4:], get_permapin)
                text_maker += "\nTo disable a permanent pin: `/permanentpin off`"
                text_maker += "\n\n[The permanent pin message is here]({})".format(
                    old_pin)
            update.effective_message.reply_text(text_maker,
                                                parse_mode="markdown")
            return ""
        prev_message = args[0]
        if prev_message == "off":
            sql.set_permapin(chat_id, 0)
            update.effective_message.reply_text(
                "The permanent pin has been disabled!")
            return
        if "/" in prev_message:
            prev_message = prev_message.split("/")[-1]
    else:
        if update.effective_message.chat.type == "private":
            update.effective_message.reply_text(
                "You can do this command in the group, not in PM")
            return ""
        chat = update.effective_chat
        chat_id = update.effective_chat.id
        chat_name = update.effective_message.chat.title
        if update.effective_message.reply_to_message:
            prev_message = update.effective_message.reply_to_message.message_id
        elif len(args) >= 1 and args[0] == "off":
            sql.set_permapin(chat.id, 0)
            update.effective_message.reply_text(
                "The permanent pin has been disabled!")
            return
        else:
            get_permapin = sql.get_permapin(chat_id)
            text_maker = "Permanent pin is currently set: `{}`".format(
                bool(int(get_permapin)))
            if get_permapin:
                if chat.username:
                    old_pin = "https://t.me/{}/{}".format(
                        chat.username, get_permapin)
                else:
                    old_pin = "https://t.me/c/{}/{}".format(
                        str(chat.id)[4:], get_permapin)
                text_maker += "\nTo disable the permanent pin: `/permanentpin off`"
                text_maker += "\n\n[The permanent pin message is here]({})".format(
                    old_pin)
            update.effective_message.reply_text(text_maker,
                                                parse_mode="markdown")
            return ""

    is_group = chat.type != "private" and chat.type != "channel"

    if prev_message and is_group:
        sql.set_permapin(chat.id, prev_message)
        update.effective_message.reply_text("Permanent pin successfully set!")
        return "<b>{}:</b>" \
               "\n#PERMANENT_PIN" \
               "\n<b>• Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))

    return ""