Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
优化cookie获取方式
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoXinYo committed May 29, 2023
1 parent f35d30c commit 3482aea
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions module/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@
import config
import asyncio
import uuid
import json

CHAT_BOT = {}

BARD_COOKIE = auxiliary.getCookie('./cookie/bard.json', ['__Secure-1PSID'])
with open('./cookie/bing.json', 'r') as file:
BING_COOKIE = json.load(file)
ERNIE_COOKIE = auxiliary.getCookie('./cookie/ernie.json', ['BAIDUID', 'BDUSS_BFESS'])

def generateChatBot(type_: str) -> Union[tuple, None]:
global CHAT_BOT
token = str(uuid.uuid4())
if type_ == 'Bard':
chatBot = Bard.Chatbot(auxiliary.getCookie('./cookie/bard.json', ['__Secure-1PSID'])['__Secure-1PSID'], proxy=config.PROXY)
chatBot = Bard.Chatbot(BARD_COOKIE['__Secure-1PSID'], proxy={
'http': config.PROXY,
'https': config.PROXY
} if config.PROXY else None)
elif type_ == 'Bing':
chatBot = EdgeGPT.Chatbot(proxy=config.PROXY, cookie_path='./cookie/bing.json')
chatBot = EdgeGPT.Chatbot(proxy=config.PROXY, cookies=BING_COOKIE)
elif type_ == 'ChatGPT':
chatBot = revChatGPT.V3.Chatbot(config.CHATGPT_KEY, proxy=config.PROXY)
elif type_ == 'Ernie':
cookie = auxiliary.getCookie('./cookie/ernie.json', ['BAIDUID', 'BDUSS_BFESS'])
chatBot = easy_ernie.FastErnie(cookie['BAIDUID'], cookie['BDUSS_BFESS'])
chatBot = easy_ernie.FastErnie(ERNIE_COOKIE['BAIDUID'], ERNIE_COOKIE['BDUSS_BFESS'])
else:
return None
CHAT_BOT[token] = {}
Expand All @@ -37,10 +45,10 @@ def getChatBot(token: str) -> Union[dict, None]:
global CHAT_BOT
if token in CHAT_BOT:
CHAT_BOT[token]['useTimeStamp'] = auxiliary.getTimeStamp()
return CHAT_BOT[token]
return CHAT_BOT[token]['chatBot']
return None

async def checkChatBot() -> None:
async def checkChatBot(loop=True) -> None:
global CHAT_BOT
while True:
for token in CHAT_BOT.copy():
Expand All @@ -51,4 +59,7 @@ async def checkChatBot() -> None:
elif chatBot['type'] == 'Ernie':
chatBot['chatBot'].close()
del chatBot
await asyncio.sleep(60)
if loop:
await asyncio.sleep(60)
else:
break

0 comments on commit 3482aea

Please sign in to comment.