wechaty-web-panel 1.2.10 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/cjs/src/common/index.js +8 -2
- package/dist/cjs/src/handlers/on-message.js +2 -1
- package/dist/cjs/src/package-json.d.ts +3 -2
- package/dist/cjs/src/package-json.js +9 -4
- package/dist/cjs/src/proxy/chatgpt.d.ts +1 -1
- package/dist/cjs/src/proxy/chatgpt.js +49 -26
- package/dist/esm/src/common/index.js +8 -2
- package/dist/esm/src/handlers/on-message.js +2 -1
- package/dist/esm/src/package-json.d.ts +3 -2
- package/dist/esm/src/package-json.js +9 -4
- package/dist/esm/src/proxy/chatgpt.d.ts +1 -1
- package/dist/esm/src/proxy/chatgpt.js +49 -26
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -164,7 +164,10 @@ async function roomSay(room, contact, msg) {
|
|
|
164
164
|
const config = await (0, configDb_js_1.allConfig)();
|
|
165
165
|
const { role } = config.userInfo;
|
|
166
166
|
if (msg.id && role === 'vip') {
|
|
167
|
-
|
|
167
|
+
const res = await (0, aibotk_js_1.getMaterial)(msg.id);
|
|
168
|
+
if (res.id) {
|
|
169
|
+
msg = res;
|
|
170
|
+
}
|
|
168
171
|
}
|
|
169
172
|
try {
|
|
170
173
|
if (msg.type === 1 && msg.content) {
|
|
@@ -226,7 +229,10 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
226
229
|
const config = await (0, configDb_js_1.allConfig)();
|
|
227
230
|
const { role } = config.userInfo;
|
|
228
231
|
if (msg.id && role === 'vip') {
|
|
229
|
-
|
|
232
|
+
const res = await (0, aibotk_js_1.getMaterial)(msg.id);
|
|
233
|
+
if (res.id) {
|
|
234
|
+
msg = res;
|
|
235
|
+
}
|
|
230
236
|
}
|
|
231
237
|
try {
|
|
232
238
|
if (msg.type === 1 && msg.content) {
|
|
@@ -115,8 +115,9 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
115
115
|
content = msg.text();
|
|
116
116
|
console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content}`);
|
|
117
117
|
const mentionSelf = await msg.mentionSelf();
|
|
118
|
+
const metionList = await msg.mentionList();
|
|
118
119
|
const receiverName = receiver?.name();
|
|
119
|
-
content = content.replace(receiverName, "").trim();
|
|
120
|
+
content = content.replace('@' + receiverName, "").replace(/@[^,,::\s@]+/g, "").trim();
|
|
120
121
|
// 检测是否需要这条消息
|
|
121
122
|
const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages);
|
|
122
123
|
if (isIgnore)
|
|
@@ -51,16 +51,17 @@ export namespace packageJson {
|
|
|
51
51
|
}
|
|
52
52
|
const dependencies: {
|
|
53
53
|
axios: string;
|
|
54
|
-
chatgpt: string;
|
|
55
54
|
ix: string;
|
|
56
55
|
jsonwebtoken: string;
|
|
57
56
|
mqtt: string;
|
|
58
57
|
mustache: string;
|
|
59
58
|
nedb: string;
|
|
60
59
|
"node-schedule": string;
|
|
61
|
-
|
|
60
|
+
openai: string;
|
|
62
61
|
puppeteer: string;
|
|
63
62
|
"qrcode-terminal": string;
|
|
63
|
+
remark: string;
|
|
64
|
+
"strip-markdown": string;
|
|
64
65
|
superagent: string;
|
|
65
66
|
};
|
|
66
67
|
namespace publishConfig {
|
|
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
exports.packageJson = {
|
|
8
8
|
"name": "wechaty-web-panel",
|
|
9
|
-
"version": "1.2.
|
|
9
|
+
"version": "1.2.12",
|
|
10
10
|
"description": "",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -34,7 +34,11 @@ exports.packageJson = {
|
|
|
34
34
|
"Wechaty",
|
|
35
35
|
"wechatEveryDay",
|
|
36
36
|
"wechaty",
|
|
37
|
-
"wechaty-plugin"
|
|
37
|
+
"wechaty-plugin",
|
|
38
|
+
"chatGPT",
|
|
39
|
+
"openai",
|
|
40
|
+
"chatBot",
|
|
41
|
+
"openGPT"
|
|
38
42
|
],
|
|
39
43
|
"author": {
|
|
40
44
|
"name": "Leo_chen",
|
|
@@ -65,16 +69,17 @@ exports.packageJson = {
|
|
|
65
69
|
},
|
|
66
70
|
"dependencies": {
|
|
67
71
|
"axios": "^0.27.2",
|
|
68
|
-
"chatgpt": "^1.4.0",
|
|
69
72
|
"ix": "^4.5.2",
|
|
70
73
|
"jsonwebtoken": "^8.5.1",
|
|
71
74
|
"mqtt": "^4.2.6",
|
|
72
75
|
"mustache": "^4.2.0",
|
|
73
76
|
"nedb": "^1.8.0",
|
|
74
77
|
"node-schedule": "^1.3.2",
|
|
75
|
-
"
|
|
78
|
+
"openai": "^3.1.0",
|
|
76
79
|
"puppeteer": "^13.3.2",
|
|
77
80
|
"qrcode-terminal": "^0.12.0",
|
|
81
|
+
"remark": "^14.0.2",
|
|
82
|
+
"strip-markdown": "^5.0.0",
|
|
78
83
|
"superagent": "^5.2.2"
|
|
79
84
|
},
|
|
80
85
|
"publishConfig": {
|
|
@@ -4,36 +4,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.geGPTReply = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const remark_1 = require("remark");
|
|
8
|
+
const strip_markdown_1 = __importDefault(require("strip-markdown"));
|
|
9
|
+
const openai_1 = require("openai");
|
|
9
10
|
const configDb_js_1 = require("../db/configDb.js");
|
|
11
|
+
let openai = null;
|
|
12
|
+
function markdownToText(markdown) {
|
|
13
|
+
return (0, remark_1.remark)()
|
|
14
|
+
.use(strip_markdown_1.default)
|
|
15
|
+
.processSync(markdown || '')
|
|
16
|
+
.toString();
|
|
17
|
+
}
|
|
10
18
|
async function geGPTReply(content) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
try {
|
|
20
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
21
|
+
if (!config.gpttoken) {
|
|
22
|
+
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
23
|
+
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
24
|
+
}
|
|
25
|
+
if (!openai) {
|
|
26
|
+
let configuration = new openai_1.Configuration({
|
|
27
|
+
apiKey: config.gpttoken,
|
|
28
|
+
});
|
|
29
|
+
openai = new openai_1.OpenAIApi(configuration);
|
|
30
|
+
}
|
|
31
|
+
let response = await openai.createCompletion({
|
|
32
|
+
model: 'text-davinci-003',
|
|
33
|
+
prompt: content,
|
|
34
|
+
temperature: 0.9,
|
|
35
|
+
max_tokens: 2000,
|
|
36
|
+
top_p: 1,
|
|
37
|
+
frequency_penalty: 0.0,
|
|
38
|
+
presence_penalty: 0.6,
|
|
39
|
+
stop: [' Human:', ' AI:'],
|
|
40
|
+
});
|
|
41
|
+
response = markdownToText(response.data.choices[0].text);
|
|
42
|
+
let replys = [];
|
|
43
|
+
let message = response;
|
|
44
|
+
while (message.length > 500) {
|
|
45
|
+
replys.push(message.slice(0, 500));
|
|
46
|
+
message = message.slice(500);
|
|
47
|
+
}
|
|
48
|
+
replys.push(message);
|
|
49
|
+
replys = replys.map(item => {
|
|
50
|
+
return {
|
|
51
|
+
type: 1,
|
|
52
|
+
content: item
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
return replys;
|
|
15
56
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const threeMinutesMs = 3 * 60 * 1000;
|
|
19
|
-
const response = await (0, p_timeout_1.default)(api.sendMessage(content), {
|
|
20
|
-
milliseconds: threeMinutesMs,
|
|
21
|
-
message: 'ChatGPT返回超时了,用的人太多,太火爆了,等会再试吧'
|
|
22
|
-
});
|
|
23
|
-
let replys = [];
|
|
24
|
-
let message = response;
|
|
25
|
-
while (message.length > 500) {
|
|
26
|
-
replys.push(message.slice(0, 500));
|
|
27
|
-
message = message.slice(500);
|
|
57
|
+
catch (e) {
|
|
58
|
+
return [{ type: 1, content: '现在询问我的人太多了,请稍后询问' }];
|
|
28
59
|
}
|
|
29
|
-
replys.push(message);
|
|
30
|
-
replys = replys.map(item => {
|
|
31
|
-
return {
|
|
32
|
-
type: 1,
|
|
33
|
-
content: item
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
return replys;
|
|
37
60
|
}
|
|
38
61
|
exports.geGPTReply = geGPTReply;
|
|
39
62
|
exports.default = {
|
|
@@ -156,7 +156,10 @@ async function roomSay(room, contact, msg) {
|
|
|
156
156
|
const config = await allConfig();
|
|
157
157
|
const { role } = config.userInfo;
|
|
158
158
|
if (msg.id && role === 'vip') {
|
|
159
|
-
|
|
159
|
+
const res = await getMaterial(msg.id);
|
|
160
|
+
if (res.id) {
|
|
161
|
+
msg = res;
|
|
162
|
+
}
|
|
160
163
|
}
|
|
161
164
|
try {
|
|
162
165
|
if (msg.type === 1 && msg.content) {
|
|
@@ -217,7 +220,10 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
217
220
|
const config = await allConfig();
|
|
218
221
|
const { role } = config.userInfo;
|
|
219
222
|
if (msg.id && role === 'vip') {
|
|
220
|
-
|
|
223
|
+
const res = await getMaterial(msg.id);
|
|
224
|
+
if (res.id) {
|
|
225
|
+
msg = res;
|
|
226
|
+
}
|
|
221
227
|
}
|
|
222
228
|
try {
|
|
223
229
|
if (msg.type === 1 && msg.content) {
|
|
@@ -113,8 +113,9 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
113
113
|
content = msg.text();
|
|
114
114
|
console.log(`群名: ${roomName} 发消息人: ${contactName} 内容: ${content}`);
|
|
115
115
|
const mentionSelf = await msg.mentionSelf();
|
|
116
|
+
const metionList = await msg.mentionList();
|
|
116
117
|
const receiverName = receiver?.name();
|
|
117
|
-
content = content.replace(receiverName, "").trim();
|
|
118
|
+
content = content.replace('@' + receiverName, "").replace(/@[^,,::\s@]+/g, "").trim();
|
|
118
119
|
// 检测是否需要这条消息
|
|
119
120
|
const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages);
|
|
120
121
|
if (isIgnore)
|
|
@@ -51,16 +51,17 @@ export namespace packageJson {
|
|
|
51
51
|
}
|
|
52
52
|
const dependencies: {
|
|
53
53
|
axios: string;
|
|
54
|
-
chatgpt: string;
|
|
55
54
|
ix: string;
|
|
56
55
|
jsonwebtoken: string;
|
|
57
56
|
mqtt: string;
|
|
58
57
|
mustache: string;
|
|
59
58
|
nedb: string;
|
|
60
59
|
"node-schedule": string;
|
|
61
|
-
|
|
60
|
+
openai: string;
|
|
62
61
|
puppeteer: string;
|
|
63
62
|
"qrcode-terminal": string;
|
|
63
|
+
remark: string;
|
|
64
|
+
"strip-markdown": string;
|
|
64
65
|
superagent: string;
|
|
65
66
|
};
|
|
66
67
|
namespace publishConfig {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const packageJson = {
|
|
5
5
|
"name": "wechaty-web-panel",
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.12",
|
|
7
7
|
"description": "",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
@@ -31,7 +31,11 @@ export const packageJson = {
|
|
|
31
31
|
"Wechaty",
|
|
32
32
|
"wechatEveryDay",
|
|
33
33
|
"wechaty",
|
|
34
|
-
"wechaty-plugin"
|
|
34
|
+
"wechaty-plugin",
|
|
35
|
+
"chatGPT",
|
|
36
|
+
"openai",
|
|
37
|
+
"chatBot",
|
|
38
|
+
"openGPT"
|
|
35
39
|
],
|
|
36
40
|
"author": {
|
|
37
41
|
"name": "Leo_chen",
|
|
@@ -62,16 +66,17 @@ export const packageJson = {
|
|
|
62
66
|
},
|
|
63
67
|
"dependencies": {
|
|
64
68
|
"axios": "^0.27.2",
|
|
65
|
-
"chatgpt": "^1.4.0",
|
|
66
69
|
"ix": "^4.5.2",
|
|
67
70
|
"jsonwebtoken": "^8.5.1",
|
|
68
71
|
"mqtt": "^4.2.6",
|
|
69
72
|
"mustache": "^4.2.0",
|
|
70
73
|
"nedb": "^1.8.0",
|
|
71
74
|
"node-schedule": "^1.3.2",
|
|
72
|
-
"
|
|
75
|
+
"openai": "^3.1.0",
|
|
73
76
|
"puppeteer": "^13.3.2",
|
|
74
77
|
"qrcode-terminal": "^0.12.0",
|
|
78
|
+
"remark": "^14.0.2",
|
|
79
|
+
"strip-markdown": "^5.0.0",
|
|
75
80
|
"superagent": "^5.2.2"
|
|
76
81
|
},
|
|
77
82
|
"publishConfig": {
|
|
@@ -1,33 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { remark } from 'remark';
|
|
2
|
+
import stripMarkdown from 'strip-markdown';
|
|
3
|
+
import { Configuration, OpenAIApi } from 'openai';
|
|
3
4
|
import { allConfig } from "../db/configDb.js";
|
|
5
|
+
let openai = null;
|
|
6
|
+
function markdownToText(markdown) {
|
|
7
|
+
return remark()
|
|
8
|
+
.use(stripMarkdown)
|
|
9
|
+
.processSync(markdown || '')
|
|
10
|
+
.toString();
|
|
11
|
+
}
|
|
4
12
|
async function geGPTReply(content) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
try {
|
|
14
|
+
const config = await allConfig();
|
|
15
|
+
if (!config.gpttoken) {
|
|
16
|
+
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
17
|
+
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
18
|
+
}
|
|
19
|
+
if (!openai) {
|
|
20
|
+
let configuration = new Configuration({
|
|
21
|
+
apiKey: config.gpttoken,
|
|
22
|
+
});
|
|
23
|
+
openai = new OpenAIApi(configuration);
|
|
24
|
+
}
|
|
25
|
+
let response = await openai.createCompletion({
|
|
26
|
+
model: 'text-davinci-003',
|
|
27
|
+
prompt: content,
|
|
28
|
+
temperature: 0.9,
|
|
29
|
+
max_tokens: 2000,
|
|
30
|
+
top_p: 1,
|
|
31
|
+
frequency_penalty: 0.0,
|
|
32
|
+
presence_penalty: 0.6,
|
|
33
|
+
stop: [' Human:', ' AI:'],
|
|
34
|
+
});
|
|
35
|
+
response = markdownToText(response.data.choices[0].text);
|
|
36
|
+
let replys = [];
|
|
37
|
+
let message = response;
|
|
38
|
+
while (message.length > 500) {
|
|
39
|
+
replys.push(message.slice(0, 500));
|
|
40
|
+
message = message.slice(500);
|
|
41
|
+
}
|
|
42
|
+
replys.push(message);
|
|
43
|
+
replys = replys.map(item => {
|
|
44
|
+
return {
|
|
45
|
+
type: 1,
|
|
46
|
+
content: item
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
return replys;
|
|
9
50
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const threeMinutesMs = 3 * 60 * 1000;
|
|
13
|
-
const response = await pTimeout(api.sendMessage(content), {
|
|
14
|
-
milliseconds: threeMinutesMs,
|
|
15
|
-
message: 'ChatGPT返回超时了,用的人太多,太火爆了,等会再试吧'
|
|
16
|
-
});
|
|
17
|
-
let replys = [];
|
|
18
|
-
let message = response;
|
|
19
|
-
while (message.length > 500) {
|
|
20
|
-
replys.push(message.slice(0, 500));
|
|
21
|
-
message = message.slice(500);
|
|
51
|
+
catch (e) {
|
|
52
|
+
return [{ type: 1, content: '现在询问我的人太多了,请稍后询问' }];
|
|
22
53
|
}
|
|
23
|
-
replys.push(message);
|
|
24
|
-
replys = replys.map(item => {
|
|
25
|
-
return {
|
|
26
|
-
type: 1,
|
|
27
|
-
content: item
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
return replys;
|
|
31
54
|
}
|
|
32
55
|
export { geGPTReply };
|
|
33
56
|
export default {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechaty-web-panel",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,7 +28,11 @@
|
|
|
28
28
|
"Wechaty",
|
|
29
29
|
"wechatEveryDay",
|
|
30
30
|
"wechaty",
|
|
31
|
-
"wechaty-plugin"
|
|
31
|
+
"wechaty-plugin",
|
|
32
|
+
"chatGPT",
|
|
33
|
+
"openai",
|
|
34
|
+
"chatBot",
|
|
35
|
+
"openGPT"
|
|
32
36
|
],
|
|
33
37
|
"author": {
|
|
34
38
|
"name": "Leo_chen",
|
|
@@ -59,16 +63,17 @@
|
|
|
59
63
|
},
|
|
60
64
|
"dependencies": {
|
|
61
65
|
"axios": "^0.27.2",
|
|
62
|
-
"chatgpt": "^1.4.0",
|
|
63
66
|
"ix": "^4.5.2",
|
|
64
67
|
"jsonwebtoken": "^8.5.1",
|
|
65
68
|
"mqtt": "^4.2.6",
|
|
66
69
|
"mustache": "^4.2.0",
|
|
67
70
|
"nedb": "^1.8.0",
|
|
68
71
|
"node-schedule": "^1.3.2",
|
|
69
|
-
"
|
|
72
|
+
"openai": "^3.1.0",
|
|
70
73
|
"puppeteer": "^13.3.2",
|
|
71
74
|
"qrcode-terminal": "^0.12.0",
|
|
75
|
+
"remark": "^14.0.2",
|
|
76
|
+
"strip-markdown": "^5.0.0",
|
|
72
77
|
"superagent": "^5.2.2"
|
|
73
78
|
},
|
|
74
79
|
"publishConfig": {
|