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
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
def transmission(update, context): if not config["enable"]: context.bot.send_message( chat_id=update.effective_message.chat_id, text=transcript["Transmission"]["NotEnabled"], ) return ConversationHandler.END if not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=transcript["Authorize"]) return TSL_NORMAL if not checkAdmin(update): context.bot.send_message( chat_id=update.effective_message.chat_id, text=transcript["NotAdmin"], ) return TSL_NORMAL keyboard = [[ InlineKeyboardButton('\U0001F40C ' + transcript["Transmission"]["TSL"], callback_data=TSL_LIMIT), InlineKeyboardButton('\U0001F406 ' + transcript["Transmission"]["Normal"], callback_data=TSL_NORMAL), ]] markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(transcript["Transmission"]["Speed"], reply_markup=markup) return TSL_NORMAL
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
def startSerieMovie(update: Update, context): if not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")) return SERIE_MOVIE_AUTHENTICATED if update.message is not None: reply = update.message.text.lower() elif update.callback_query is not None: reply = update.callback_query.data.lower() else: return SERIE_MOVIE_AUTHENTICATED if reply[1:] in [ i18n.t("addarr.Serie").lower(), i18n.t("addarr.Movie").lower(), ]: logger.debug( f"User issued {reply} command, so setting user_data[choice] accordingly" ) context.user_data.update({ "choice": i18n.t("addarr.Serie") if reply[1:] == i18n.t("addarr.Serie").lower() else i18n.t("addarr.Movie") }) elif reply == i18n.t("addarr.New").lower(): logger.debug("User issued New command, so clearing user_data") clearUserData(context) context.bot.send_message(chat_id=update.effective_message.chat_id, text='\U0001F3F7 ' + i18n.t("addarr.Title")) return SERIE_MOVIE_AUTHENTICATED
def startSerieMovie(update: Update, context): if not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=transcript["Authorize"]) return SERIE_MOVIE_AUTHENTICATED if update.message is not None: reply = update.message.text.lower() elif update.callback_query is not None: reply = update.callback_query.data.lower() else: return SERIE_MOVIE_AUTHENTICATED if reply[1:] in [ transcript["Serie"].lower(), transcript["Movie"].lower(), ]: logger.debug( f"User issued {reply} command, so setting user_data[choice] accordingly" ) context.user_data.update({ "choice": transcript["Serie"] if reply[1:] == transcript["Serie"].lower() else transcript["Movie"] }) elif reply == transcript["New"].lower(): logger.debug("User issued New command, so clearing user_data") clearUserData(context) context.bot.send_message(chat_id=update.effective_message.chat_id, text='\U0001F3F7 ' + transcript["Title"]) return SERIE_MOVIE_AUTHENTICATED
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
def stop(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 not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")) return SERIE_MOVIE_AUTHENTICATED clearUserData(context) context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.End")) return ConversationHandler.END
def sabnzbd(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 not config["enable"]: context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Sabnzbd.NotEnabled"), ) return ConversationHandler.END if not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")) return SABNZBD_SPEED_LIMIT_100 if config["onlyAdmin"] and not checkAllowed(update, "admin"): context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.NotAdmin"), ) return SABNZBD_SPEED_LIMIT_100 keyboard = [[ InlineKeyboardButton('\U0001F40C ' + i18n.t("addarr.Sabnzbd.Limit25"), callback_data=SABNZBD_SPEED_LIMIT_25), InlineKeyboardButton('\U0001F40E ' + i18n.t("addarr.Sabnzbd.Limit50"), callback_data=SABNZBD_SPEED_LIMIT_50), InlineKeyboardButton('\U0001F406 ' + i18n.t("addarr.Sabnzbd.Limit100"), callback_data=SABNZBD_SPEED_LIMIT_100), ]] markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(i18n.t("addarr.Sabnzbd.Speed"), reply_markup=markup) return SABNZBD_SPEED_LIMIT_100
def startSerieMovie(update: 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 not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")) return SERIE_MOVIE_AUTHENTICATED if update.message is not None: reply = update.message.text.lower() elif update.callback_query is not None: reply = update.callback_query.data.lower() else: return SERIE_MOVIE_AUTHENTICATED if reply[1:] in [ i18n.t("addarr.Series").lower(), i18n.t("addarr.Movie").lower(), ]: logger.debug( f"User issued {reply} command, so setting user_data[choice] accordingly" ) context.user_data.update({ "choice": i18n.t("addarr.Series") if reply[1:] == i18n.t("addarr.Series").lower() else i18n.t("addarr.Movie") }) elif reply == i18n.t("addarr.New").lower(): logger.debug("User issued New command, so clearing user_data") clearUserData(context) msg = context.bot.send_message(chat_id=update.effective_message.chat_id, text='\U0001F3F7 ' + i18n.t("addarr.Title")) return SERIE_MOVIE_AUTHENTICATED
def transmission(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 not config["enable"]: context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Transmission.NotEnabled"), ) return ConversationHandler.END if not checkId(update): context.bot.send_message(chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize")) return TSL_NORMAL if config["onlyAdmin"] and not checkAllowed(update, "admin"): context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.NotAdmin"), ) return TSL_NORMAL keyboard = [[ InlineKeyboardButton('\U0001F40C ' + i18n.t("addarr.Transmission.TSL"), callback_data=TSL_LIMIT), InlineKeyboardButton('\U0001F406 ' + i18n.t("addarr.Transmission.Normal"), callback_data=TSL_NORMAL), ]] markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(i18n.t("addarr.Transmission.Speed"), reply_markup=markup) return TSL_NORMAL
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
def transmission(update, context): if not config["enable"]: context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Transmission.NotEnabled"), ) return ConversationHandler.END if not checkId(update): context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.Authorize") ) return TSL_NORMAL if not checkAdmin(update): context.bot.send_message( chat_id=update.effective_message.chat_id, text=i18n.t("addarr.NotAdmin"), ) return TSL_NORMAL keyboard = [[ InlineKeyboardButton( '\U0001F40C '+i18n.t("addarr.Transmission.TSL"), callback_data=TSL_LIMIT ), InlineKeyboardButton( '\U0001F406 '+i18n.t("addarr.Transmission.Normal"), callback_data=TSL_NORMAL ), ]] markup = InlineKeyboardMarkup(keyboard) update.message.reply_text( i18n.t("addarr.Transmission.Speed"), reply_markup=markup ) return TSL_NORMAL
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