Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 31, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from FriendlyUser March 31, 2023 20:44
with open(path) as f:
queries[path.stem] = f.read()
queries[path.stem] = Path(path).read_text()
Copy link
Author

Choose a reason for hiding this comment

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

Function load_queries refactored with the following changes:

  • Simplify basic file reads with pathlib (path-read)

Comment on lines -88 to +95

r = request_with_retries(self.session.get, self.home_url)
json_regex = r'<script id="__NEXT_DATA__" type="application\/json">(.+?)</script>'
json_text = re.search(json_regex, r.text).group(1)
json_text = re.search(json_regex, r.text)[1]
next_data = json.loads(json_text)

self.formkey = next_data["props"]["formkey"]
self.viewer = next_data["props"]["pageProps"]["payload"]["viewer"]

Copy link
Author

Choose a reason for hiding this comment

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

Function Client.get_next_data refactored with the following changes:

Comment on lines -101 to +113
if not "availableBots" in viewer:
if "availableBots" not in viewer:
raise RuntimeError("Invalid token.")
bot_list = viewer["availableBots"]

bots = {}
for bot in bot_list:
url = f'https://poe.com/_next/data/{self.next_data["buildId"]}/{bot["displayName"].lower()}.json'
logger.info("Downloading "+url)
logger.info(f"Downloading {url}")

r = request_with_retries(self.session.get, url)

chat_data = r.json()["pageProps"]["payload"]["chatOfBotDisplayName"]
bots[chat_data["defaultBotObject"]["nickname"]] = chat_data

Copy link
Author

Choose a reason for hiding this comment

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

Function Client.get_bots refactored with the following changes:

Comment on lines -136 to +135
return f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates'+query
return f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates{query}'
Copy link
Author

Choose a reason for hiding this comment

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

Function Client.get_websocket_url refactored with the following changes:

Comment on lines -143 to +148
if data["data"] == None:
if data["data"] is None:
logger.warn(f'{query_name} returned an error: {data["errors"][0]["message"]} | Retrying ({i+1}/20)')
time.sleep(2)
continue

return r.json()

Copy link
Author

Choose a reason for hiding this comment

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

Function Client.send_query refactored with the following changes:

Comment on lines -216 to +215
#indicate that the response id is tied to the human message id
elif key != "pending" and value == None and message["state"] != "complete":
elif key != "pending" and value is None and message["state"] != "complete":
Copy link
Author

Choose a reason for hiding this comment

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

Function Client.on_message refactored with the following changes:

This removes the following comments ( why? ):

#indicate that the response id is tied to the human message id

Comment on lines -297 to +295
if not type(message_ids) is list:
if type(message_ids) is not list:
Copy link
Author

Choose a reason for hiding this comment

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

Function Client.delete_message refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -306 to +304
last_messages = self.get_message_history(chatbot, count=50)[::-1]
while last_messages:
while last_messages := self.get_message_history(chatbot, count=50)[::-1]:
Copy link
Author

Choose a reason for hiding this comment

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

Function Client.purge_conversation refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants