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() 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 allSeries(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 sonarr.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 = sonarr.allSeries() 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 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