Example #1
0
def setlog(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    if chat.type == chat.CHANNEL:
        message.reply_text(tld(chat.id, "log_channel_fwd_cmd"))

    elif message.forward_from_chat:
        sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
        try:
            message.delete()
        except BadRequest as excp:
            if excp.message != "Message to delete not found":
                LOGGER.exception(
                    "Error deleting message in log channel. Should work anyway though."
                )

        try:
            bot.send_message(
                message.forward_from_chat.id,
                tld(chat.id,
                    "log_channel_chn_curr_conf").format(chat.title
                                                        or chat.first_name))
        except Unauthorized as excp:
            if excp.message == "Forbidden: bot is not a member of the channel chat":
                bot.send_message(chat.id,
                                 tld(chat.id, "log_channel_link_success"))
            else:
                LOGGER.exception("ERROR in setting the log channel.")

        bot.send_message(chat.id, tld(chat.id, "log_channel_link_success"))

    else:
        message.reply_text(tld(chat.id, "log_channel_invalid_message"),
                           ParseMode.MARKDOWN)
Example #2
0
    def setlog(update, context):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!"
                ))

        elif message.forward_from_chat:
            sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception(
                        "Error deleting message in log channel. Should work anyway though."
                    )

            try:
                context.bot.send_message(
                    message.forward_from_chat.id,
                    tl(
                        update.effective_message,
                        "Saluran ini telah ditetapkan sebagai saluran log untuk {}."
                    ).format(chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    context.bot.send_message(
                        chat.id,
                        tl(
                            update.effective_message,
                            "Gagal menyetel saluran log!\nSaya mungkin bukan admin di channel tersebut."
                        ))
                    sql.stop_chat_logging(chat.id)
                    return
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            context.bot.send_message(
                chat.id,
                tl(update.effective_message, "Berhasil mengatur saluran log!"))

        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Langkah-langkah untuk mengatur saluran log adalah:\n"
                    " - tambahkan bot ke saluran yang diinginkan\n"
                    " - Kirimkan /setlog ke saluran\n"
                    " - Teruskan /setlog ke grup\n"))
Example #3
0
    def setlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            message.reply_text(
                tld(
                    chat.id,
                    "Now, forward the /setlog to the group you want to tie this channel to!"
                ))

        elif message.forward_from_chat:
            sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception(
                        "Error deleting message in log channel. Should work anyway though."
                    )

            try:
                bot.send_message(
                    message.forward_from_chat.id,
                    tld(
                        chat.id,
                        "This channel has been set as the log channel for {}."
                    ).format(chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    bot.send_message(
                        chat.id, tld(chat.id, "Successfully set log channel!"))
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            bot.send_message(chat.id,
                             tld(chat.id, "Successfully set log channel!"))

        else:
            message.reply_text(
                tld(
                    chat.id, "*The steps to set a log channel are:*\n"
                    " • add bot to the desired channel\n"
                    " • send /setlog to the channel\n"
                    " • forward the /setlog to the group\n"),
                ParseMode.MARKDOWN)