Skip to content

Commit

Permalink
bingai: use rookiepy instead of browser_cookie3
Browse files Browse the repository at this point in the history
  • Loading branch information
xhcoding committed Oct 20, 2023
1 parent 8647a6b commit 3cea1ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ There are two ways to get the browser's cookie, you can choose any convenient me

**** Option one

If you have a Python environment, run =pip3 install browser_cookie3= to install =browser_cookie3=, then open the terminal and execute the following code:
If you have a Python environment, run =pip3 install rookiepy= to install =rookiepy=, then open the terminal and execute the following code:


#+begin_src sh
python -c "import browser_cookie3;list(map(lambda c: print('{} {} {} {} {} {}'.format(c.name, c.value, c.expires,c.domain, c.secure, c.path)), filter(lambda c: c.domain in ('.bing.com', 'www.bing.com'), browser_cookie3.edge(domain_name='bing.com'))))"
python -c "import rookiepy;list(map(lambda c: print('{} {} {} {} {} {}'.format(c['name'], c['value'], c['expires'], c['domain'], c['path'], c['secure'])), filter(lambda c: c['domain'] in ('.bing.com'), rookiepy.edge(['.bing.com']))))"
#+end_src

If you can see the output and there is a =_U= field in the output, then you can log in successfully with this method.
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.org
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ emacs-aichat 获取浏览器的 cookie 登录 Bing Chat ,所以你需要先在

**** 方式一

如果你有 Python 环境,运行 =pip3 install browser_cookie3= 安装 =browser_cookie3= ,
如果你有 Python 环境,运行 =pip3 install rookiepy= 安装 =rookiepy= ,
然后打开终端,执行下面的代码:

#+begin_src sh
python -c "import browser_cookie3;list(map(lambda c: print('{} {} {} {} {} {}'.format(c.name, c.value, c.expires,c.domain, c.secure, c.path)), filter(lambda c: c.domain in ('.bing.com', 'www.bing.com'), browser_cookie3.edge(domain_name='bing.com'))))"
python -c "import rookiepy;list(map(lambda c: print('{} {} {} {} {} {}'.format(c['name'], c['value'], c['expires'], c['domain'], c['path'], c['secure'])), filter(lambda c: c['domain'] in ('.bing.com'), rookiepy.edge(['.bing.com']))))"
#+end_src

如果你能够看到输出,并且输出中有 =_U= 字段,那么你能够用这种方式登录成功。
Expand Down
2 changes: 1 addition & 1 deletion aichat-bingai.el
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ to the websocket protocol.
(when-let* ((host-cookies
(seq-find (lambda (host)
(string= (car host) aichat-bingai--domain))
(append url-cookie-secure-storage)))
(append url-cookie-secure-storage url-cookie-storage)))
(user (seq-find
(lambda (cookie)
(string= (aref cookie 1) "_U"))
Expand Down
19 changes: 9 additions & 10 deletions aichat-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
(const :tag "url" url)))

(defcustom aichat-browser-name 'edge
"Browser used by browser_cookie3."
"Browser used by rookiepy."
:group 'aichat-bingai
:type '(radio
(const :tag "Chrome" chrome)
Expand Down Expand Up @@ -262,8 +262,8 @@ Returns stdout on success, otherwise returns nil."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Cookie utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(async-defun aichat--check-deps ()
"Check if browser_cookie3 is installed."
(when-let ((installed (await (aichat-shell-command "python -c \"import browser_cookie3\""))))
"Check if rookiepy is installed."
(when-let ((installed (await (aichat-shell-command "python -c \"import rookiepy\""))))
t))

(defun aichat-get-cookies-from-file (filename)
Expand All @@ -289,16 +289,15 @@ Returns stdout on success, otherwise returns nil."

(defun aichat--make-get-cookies-command(domain browser-name)
"Make shell command with `domain' and `browser-name'."
(format
"python -c \"import browser_cookie3;list(map(lambda c: print('{} {} {} {} {} {}'.format(c.name, c.value, c.expires, c.domain, c.path, c.secure)), filter(lambda c: c.domain in ('%s'), browser_cookie3.%s(domain_name='%s'))))\""
domain
browser-name
domain))
(format "python -c \"import rookiepy;list(map(lambda c: print('{} {} {} {} {} {}'.format(c['name'], c['value'], c['expires'], c['domain'], c['path'], c['secure'])), filter(lambda c: c['domain'] in ('%s'), rookiepy.%s(['%s']))))\""
domain
browser-name
domain))

(async-defun aichat-get-cookies-from-shell (domain browser-name)
"Get cookies from shell command with browser_cookie3."
"Get cookies from shell command with rookiepy."
(if (not (await (aichat--check-deps)))
(message "Please install browser_cookie3 by `pip3 install browser_cookie3`")
(message "Please install rookiepy by `pip3 install rookiepy`")
(when-let ((stdout (await
(aichat-shell-command
(aichat--make-get-cookies-command domain browser-name)))))
Expand Down

0 comments on commit 3cea1ff

Please sign in to comment.