Skip to content

Commit e46bc10

Browse files
committed
refactor: 设置功能, chore: 重新使用未混淆的js
1 parent 3a23328 commit e46bc10

File tree

8 files changed

+223
-149
lines changed

8 files changed

+223
-149
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ Dockerfile
77
docker-compose.yaml
88
img/
99
service/chat/config.js
10-
service/chat/mlyai.js

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"axios": "^0.27.2",
2121
"nodemon": "^2.0.16",
2222
"oicq": "^1.18.1",
23-
"sprintf-js": "^1.1.2",
2423
"ws": "^7.5.3"
2524
},
2625
"devDependencies": {

service/auth.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const adminConfig = [['chat', 'lc'], // ['voice', 0]
2+
]
3+
const CHAT = 'chat'
4+
const VOICE = 'voice'
5+
const chatMap = new Map()
6+
const voiceMap = new Map()
7+
const globalMap = new Map(adminConfig)
8+
const adminNumberList = [
9+
// yql
10+
1251958108,
11+
// syy
12+
2779066456,
13+
// zzx
14+
1353736793
15+
// todo
16+
]
17+
18+
function isAdmin(userId) {
19+
return adminNumberList.includes(userId)
20+
}
21+
22+
function isGlobalChatOpen() {
23+
return globalMap.get(CHAT) !== undefined
24+
}
25+
26+
function isGlobalVoiceOpen() {
27+
return globalMap.get(VOICE) !== undefined
28+
}
29+
30+
function isUserChatOpen(userId) {
31+
if (globalMap.get(CHAT) === undefined) {
32+
return false
33+
}
34+
return chatMap.get(userId) !== undefined;
35+
}
36+
37+
function isUserVoiceOpen(userId) {
38+
if (globalMap.get(VOICE) === undefined) {
39+
return false
40+
}
41+
return voiceMap.get(userId) !== undefined;
42+
}
43+
44+
function setUserChatState(userId, state) {
45+
if (state === 0 || state === undefined) {
46+
chatMap.delete(userId)
47+
} else {
48+
chatMap.set(userId, 'lc')
49+
}
50+
}
51+
52+
function setUserVoiceState(userId, state) {
53+
if (state === 0 || state === undefined) {
54+
voiceMap.delete(userId)
55+
} else {
56+
voiceMap.set(userId, 'lc')
57+
}
58+
}
59+
60+
function setGlobalState(name, state) {
61+
if (state === undefined || state === 0 || state === '0') {
62+
globalMap.delete(name)
63+
} else {
64+
globalMap.set(name, 'lc')
65+
}
66+
}
67+
68+
module.exports = {
69+
isUserChatOpen,
70+
isUserVoiceOpen,
71+
setUserChatState,
72+
setUserVoiceState,
73+
setGlobalState,
74+
isGlobalChatOpen,
75+
isGlobalVoiceOpen,
76+
isAdmin
77+
}

service/chat/mlyai.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const axios = require("axios");
2+
const fileServer = 'https://files.molicloud.com/'
3+
const apiServer = 'https://api.mlyai.com/reply'
4+
const config = {
5+
"apiKey": "go3pgk66gfi38usq",
6+
"apiSecret": "quw1mu9q"
7+
}
8+
9+
function chat(message) {
10+
11+
return new Promise((resolve, reject) => {
12+
let payload = {
13+
"content": message.content,
14+
"type": message.type,
15+
"from": message.from,
16+
"fromName": message.fromName,
17+
"to": message.to,
18+
"toName": message.toName
19+
}
20+
// console.debug(payload)
21+
axios({
22+
method: 'post',
23+
url: apiServer,
24+
data: JSON.stringify(payload),
25+
headers: {
26+
'Api-Key': config.apiKey,
27+
'Api-Secret': config.apiSecret,
28+
'Content-Type': 'application/json'
29+
}
30+
}).then(res => {
31+
// console.debug(res.data)
32+
if (res.data.code !== '00000') {
33+
resolve("休息一下吧")
34+
return
35+
}
36+
resolve(res.data.data)
37+
}).catch(e => {
38+
console.log(e)
39+
resolve("休息一下吧")
40+
})
41+
})
42+
}
43+
44+
function getAbsoluteUrl(url) {
45+
return fileServer + url
46+
}
47+
48+
function getPlayLoad(type, msg, data, content) {
49+
return {
50+
"content": content !== undefined ? content : msg.data.text,
51+
"type": type == null ? 2 : type,
52+
"from": data.sender.user_id,
53+
"fromName": data.sender.card,
54+
"to": data.group_id,
55+
"toName": data.group_name,
56+
}
57+
}
58+
59+
// let test = {
60+
// "content": "你好",
61+
// "type": "1",
62+
// "from": "1",
63+
// "fromName": "test"
64+
// }
65+
//
66+
// chat(test).then(res => {
67+
// console.log(res)
68+
// })
69+
70+
module.exports = {chat, getAbsoluteUrl, getPlayLoad}

service/chat/mlyai2.js

-1
This file was deleted.

0 commit comments

Comments
 (0)