Skip to content

Commit

Permalink
fix: 🐛 Support using session generation on windows systems
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTong committed Dec 8, 2022
1 parent 4406810 commit a827da4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
Expand Down
15 changes: 12 additions & 3 deletions src/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class ChatGPTBot {
return this.cache.get(email);
}
const cmd = `poetry run python3 src/generate_session.py ${email} ${password}`;
const { stdout, stderr, exitCode } = await execa(`sh`, ["-c", cmd]);
const platform = process.platform;
const { stdout, stderr, exitCode } = await execa(platform==="win32"?"powershell":"sh", [platform==="win32"?"/c":"-c", cmd]);
if (exitCode !== 0) {
console.error(stderr);
return "";
Expand Down Expand Up @@ -102,7 +103,7 @@ export class ChatGPTBot {
async getGPTMessage(text: string, talkerId: string): Promise<string> {
const conversation = this.getConversation(talkerId);
try {
return await conversation.sendMessage(text);
return await conversation.sendMessage(text,{timeoutMs: 2 * 60 * 1000});
} catch (e) {
this.resetConversation(talkerId);
console.error(e);
Expand All @@ -127,7 +128,15 @@ export class ChatGPTBot {
}
async onMessage(message: Message) {
const talker = message.talker();
if (talker.self() || message.type() > 10 || talker.name() == "微信团队") {
if (talker.self()
|| message.type() > 10
|| talker.name() == "微信团队"
// 语音(视频)消息
|| message.text().includes("收到一条视频/语音聊天消息,请在手机上查看")
// 红包消息
|| message.text().includes("收到红包,请在手机上查看")
// 位置消息
|| message.text().includes("/cgi-bin/mmwebwx-bin/webwxgetpubliclinkimg")) {
return;
}
const text = message.text();
Expand Down

0 comments on commit a827da4

Please sign in to comment.