Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
Custom captcha solver
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Cheong committed Dec 10, 2022
1 parent 04b1156 commit a054c4e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="revChatGPT",
version="0.0.34",
version="0.0.34.1",
license="GNU General Public License v2.0",
author="Antonio Cheong",
author_email="acheong@student.dalat.org",
Expand All @@ -15,7 +15,7 @@
install_requires=[
"requests",
"httpx[http2]",
"OpenAIAuth>=0.0.5",
"OpenAIAuth>=0.0.6",
],
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
30 changes: 29 additions & 1 deletion src/revChatGPT/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def main():
else:
debug = False
print("Logging in...")
chatbot = Chatbot(config, debug=debug)
chatbot = Chatbot(config, debug=debug,
captcha_solver=CaptchaSolver)
else:
print("Please create and populate config.json to continue")
exit()
Expand Down Expand Up @@ -131,3 +132,30 @@ def main():

if __name__ == "__main__":
main()


class CaptchaSolver:
"""
Captcha solver
"""
@staticmethod
def solve_captcha(raw_svg):
"""
Solves the captcha
:param raw_svg: The raw SVG
:type raw_svg: :obj:`str`
:return: The solution
:rtype: :obj:`str`
"""
# Get the SVG
svg = raw_svg
# Save the SVG
with open("captcha.svg", "w") as f:
print("Captcha saved to captcha.svg")
f.write(svg)
# Get input
solution = input("Please solve the captcha: ")
# Return the solution
return solution
6 changes: 4 additions & 2 deletions src/revChatGPT/revChatGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ class Chatbot:
conversation_id_prev: str
parent_id_prev: str
request_timeout: int
captcha_solver: any

def __init__(self, config, conversation_id=None, parent_id=None, debug=False, refresh=True, request_timeout=100):
def __init__(self, config, conversation_id=None, parent_id=None, debug=False, refresh=True, request_timeout=100, captcha_solver=None):
self.debugger = Debugger(debug)
self.debug = debug
self.config = config
self.conversation_id = conversation_id
self.parent_id = parent_id if parent_id else generate_uuid()
self.base_url = "https://chat.openai.com/"
self.request_timeout = request_timeout
self.captcha_solver = captcha_solver
if ("session_token" in config or ("email" in config and "password" in config)) and refresh:
self.refresh_session()
if "Authorization" in config:
Expand Down Expand Up @@ -332,7 +334,7 @@ def login(self, email: str, password: str) -> None:
self.debugger.log("Logging in...")
proxy = self.config.get("proxy")
auth = OpenAIAuth(email, password, bool(
proxy), proxy, debug=self.debug)
proxy), proxy, debug=self.debug, use_captcha=True, captcha_solver=self.captcha_solver)
try:
auth.begin()
except Exception as exc:
Expand Down

0 comments on commit a054c4e

Please sign in to comment.