Esempio n. 1
0
def changeSpeedTransmission(update, context):
    if not checkId(update):
        if (authentication(
                update,
                context) == "added"):  # To also stop the beginning command
            return ConversationHandler.END

    choice = update.callback_query.data
    command = f"transmission-remote {config['host']}"
    if config["authentication"]:
        command += (" --auth " + config["username"] + ":" + config["password"])

    message = None
    if choice == TSL_NORMAL:
        command += ' --no-alt-speed'
        message = transcript["Transmission"]["ChangedToNormal"]
    elif choice == TSL_LIMIT:
        command += ' --alt-speed'
        message = transcript["Transmission"]["ChangedToTSL"],

    os.system(command)

    context.bot.send_message(
        chat_id=update.effective_message.chat_id,
        text=message,
    )
    return ConversationHandler.END
Esempio n. 2
0
def changeSpeedSabnzbd(update, context):
    if not checkId(update):
        if (authentication(
                update,
                context) == "added"):  # To also stop the beginning command
            return ConversationHandler.END

    choice = update.callback_query.data

    url = generateApiQuery("sabnzbd", "", {
        'output': 'json',
        'mode': 'config',
        'name': 'speedlimit',
        'value': choice
    })

    req = requests.get(url)
    message = None
    if req.status_code == 200:
        if choice == SABNZBD_SPEED_LIMIT_100:
            message = i18n.t("addarr.Sabnzbd.ChangedTo100")
        elif choice == SABNZBD_SPEED_LIMIT_50:
            message = i18n.t("addarr.Sabnzbd.ChangedTo50")
        elif choice == SABNZBD_SPEED_LIMIT_25:
            message = i18n.t("addarr.Sabnzbd.ChangedTo25")

    else:
        message = i18n.t("addarr.Sabnzbd.Error")

    context.bot.send_message(
        chat_id=update.effective_message.chat_id,
        text=message,
    )

    return ConversationHandler.END
Esempio n. 3
0
def allMovies(update, context):
    if not checkId(update):
        if (
            authentication(update, context) == "added"
        ):  # To also stop the beginning command
            return ConversationHandler.END
    else:

        result = radarr.all_movies()
        content = format_long_list_message(result)

        if isinstance(content, str):
            context.bot.send_message(
                chat_id=update.effective_message.chat_id,
                text=content,
            )
        else:
            # print every substring
            for subString in content:
                context.bot.send_message(
                    chat_id=update.effective_message.chat_id,
                    text=subString,
                )

        return ConversationHandler.END
Esempio n. 4
0
def choiceSerieMovie(update, context):
    if not checkId(update):
        if (
            authentication(update, context) == "added"
        ):  # To also stop the beginning command
            return ConversationHandler.END
    elif update.message.text.lower() == "/stop".lower() or update.message.text.lower() == "stop".lower():
        return stop(update, context)
    else:
        if update.message is not None:
            reply = update.message.text
        elif update.callback_query is not None:
            reply = update.callback_query.data
        else:
            return SERIE_MOVIE_AUTHENTICATED

        if reply.lower() not in [
            i18n.t("addarr.Series").lower(),
            i18n.t("addarr.Movie").lower(),
        ]:
            logger.debug(
                f"User entered a title {reply}"
            )
            context.user_data["title"] = reply

        if context.user_data.get("choice") in [
            i18n.t("addarr.Series"),
            i18n.t("addarr.Movie"),
        ]:
            logger.debug(
                f"user_data[choice] is {context.user_data['choice']}, skipping step of selecting movie/series"
            )
            return searchSerieMovie(update, context)
        else:
            keyboard = [
                [
                    InlineKeyboardButton(
                        '\U0001F3AC '+i18n.t("addarr.Movie"),
                        callback_data=i18n.t("addarr.Movie")
                    ),
                    InlineKeyboardButton(
                        '\U0001F4FA '+i18n.t("addarr.Series"),
                        callback_data=i18n.t("addarr.Series")
                    ),
                ],
                [ InlineKeyboardButton(
                        '\U0001F50D '+i18n.t("addarr.New"),
                        callback_data=i18n.t("addarr.New")
                    ),
                ]
            ]
            markup = InlineKeyboardMarkup(keyboard)
            update.message.reply_text(i18n.t("addarr.What is this?"), reply_markup=markup)
            return READ_CHOICE
Esempio n. 5
0
def allMovies(update, context):
    if config.get("enableAllowlist") and not checkAllowed(update, "regular"):
        #When using this mode, bot will remain silent if user is not in the allowlist.txt
        logger.info(
            "Allowlist is enabled, but userID isn't added into 'allowlist.txt'. So bot stays silent"
        )
        return ConversationHandler.END

    if radarr.config.get("adminRestrictions") and not checkAllowed(
            update, "admin"):
        context.bot.send_message(
            chat_id=update.effective_message.chat_id,
            text=i18n.t("addarr.NotAdmin"),
        )
        return ConversationHandler.END

    if not checkId(update):
        if (authentication(
                update,
                context) == "added"):  # To also stop the beginning command
            return ConversationHandler.END
    else:
        result = radarr.all_movies()
        content = format_long_list_message(result)

        if isinstance(content, str):
            context.bot.send_message(
                chat_id=update.effective_message.chat_id,
                text=content,
            )
        else:
            # print every substring
            for subString in content:
                context.bot.send_message(
                    chat_id=update.effective_message.chat_id,
                    text=subString,
                )
        return ConversationHandler.END
Esempio n. 6
0
def allSeries(update, context):
    if not checkId(update):
        if (
            authentication(update, context) == "added"
        ):  # To also stop the beginning command
            return ConversationHandler.END
    else:
        result = sonarr.allSeries()
        string = ""
        for serie in result:
            string += "• " \
            + serie["title"] \
            + " (" \
            + str(serie["year"]) \
            + ")" \
            + "\n" \
            + "        status: " \
            + serie["status"] \
            + "\n" \
            + "        monitored: " \
            + str(serie["monitored"]).lower() \
            + "\n"
        
        #max length of a message is 4096 chars
        if len(string) <= 4096:
            context.bot.send_message(
                chat_id=update.effective_message.chat_id,
                text=string,
            )
        #split string if longer then 4096 chars
        else: 
            neededSplits = math.ceil(len(string) / 4096)
            positionNewLine = []
            index = 0
            while index < len(string): #Get positions of newline, so that the split will happen after a newline
                i = string.find("\n", index)
                if i == -1:
                    return positionNewLine
                positionNewLine.append(i)
                index+=1

            #split string at newline closest to maxlength
            stringParts = []
            lastSplit = timesSplit = 0
            i = 4096
            while i > 0 and len(string)>4096: 
                if timesSplit < neededSplits:
                    if i+lastSplit in positionNewLine:
                        stringParts.append(string[0:i])
                        string = string[i+1:]
                        timesSplit+=1
                        lastSplit = i
                        i = 4096
                i-=1
            stringParts.append(string)

            #print every substring
            for subString in stringParts:
                context.bot.send_message(
                chat_id=update.effective_message.chat_id,
                text=subString,
            )
        return ConversationHandler.END