Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

Add the possibility to get the number of remaining messages #46

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion poe-api/src/poe.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ def get_bot_names(self):
bot_names[bot_nickname] = bot_obj["displayName"]
return bot_names

def get_remaining_messages(self, chatbot):
url = f'https://poe.com/_next/data/{self.next_data["buildId"]}/{chatbot}.json'
limited_chatbots = ["GPT-4", "Claude+"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to hardcode the bot names, that'll just cause the function to break whenever Poe changes their bots.

if chatbot in limited_chatbots:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to make the request manually when there's already a client.get_bot function for this.

r = request_with_retries(self.session.get, url)
remaining_count = r.json()["pageProps"]["payload"]["chatOfBotDisplayName"]["defaultBotObject"]["messageLimit"]["numMessagesRemaining"]
return remaining_count
else:
raise Exception(f"Chatbot {chatbot} is not limited or doesn't exist.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe don't raise an exception for if the chatbot doesn't have a limit. The numMessagesRemaining value is present on all chatbots anyways, and it'll just be null if there isn't a limit.


def get_channel_data(self, channel=None):
logger.info("Downloading channel data...")
r = request_with_retries(self.session.get, self.settings_url)
Expand Down Expand Up @@ -405,4 +415,4 @@ def purge_conversation(self, chatbot, count=-1):
last_messages = self.get_message_history(chatbot, count=50)[::-1]
logger.info(f"No more messages left to delete.")

load_queries()
load_queries()