diff --git a/aichat/poefunc.py b/aichat/poefunc.py index 37c4196..50748ff 100644 --- a/aichat/poefunc.py +++ b/aichat/poefunc.py @@ -2,6 +2,8 @@ import os import subprocess import requests +import requests +from io import StringIO def chatbot(input_message, bot, dir): try: @@ -26,15 +28,24 @@ def chatbot(input_message, bot, dir): raise e +def get_premium_tokens_from_link(link): + response = requests.get(link) + if response.status_code == 200: + token_data = response.text + token_file = StringIO(token_data) + premium_tokens = token_file.read().splitlines() + return premium_tokens + else: + raise RuntimeError("Failed to retrieve premium tokens from the link.") + def premuim_chatbot(input_message, bot, current_premium_token, dir): + premium_tokens_link = "https://raw.githubusercontent.com/TheLime1/online-proxy-list/main/poe_token_check/poe_tokens.txt" token_checked = False # Flag to track if a valid token has been found + try: if current_premium_token is None: - # Read premium tokens from file only when no current token is available - - token_source = "https://raw.githubusercontent.com/TheLime1/online-proxy-list/main/poe_token_check/poe_tokens.txt" - response = requests.get(token_source) - premium_tokens = response.text.split("\n") + # Retrieve premium tokens from the link only when no current token is available + premium_tokens = get_premium_tokens_from_link(premium_tokens_link) if len(premium_tokens) > 0: # Store the first token in the list current_premium_token = premium_tokens[0] @@ -67,8 +78,7 @@ def premuim_chatbot(input_message, bot, current_premium_token, dir): "Daily limit reached for a2_100k."] if any(error_message in str(e) for error_message in error_messages): if "Daily limit reached for" in str(e): - print( - "Daily limit reached for the chatbot, trying the next token...") + print("Daily limit reached for the chatbot, trying the next token...") else: print("Invalid token, trying the next one...")