karin-plugin-teamspeak 1.10.2 → 1.11.0
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/lib/apps/ts3.d.ts +2 -2
- package/lib/apps/ts3.js +91 -85
- package/package.json +2 -2
package/lib/apps/ts3.d.ts
CHANGED
package/lib/apps/ts3.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryProtocol, TeamSpeak } from "ts3-nodejs-library";
|
|
2
2
|
import { config } from "../utils/index.js";
|
|
3
3
|
import karin, { logger, segment, app } from "node-karin";
|
|
4
4
|
import moment from "node-karin/moment";
|
|
@@ -19,47 +19,47 @@ class ts3 {
|
|
|
19
19
|
if (this.teamspeak) {
|
|
20
20
|
await this.quitTs();
|
|
21
21
|
}
|
|
22
|
-
const _teamspeak = new
|
|
23
|
-
host:
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const _teamspeak = new TeamSpeak({
|
|
23
|
+
host: TS.HOST,
|
|
24
|
+
protocol: QueryProtocol[TS.PROTOCOL],
|
|
25
|
+
queryport: TS.QUERY_PORT,
|
|
26
|
+
serverport: TS.SERVER_PORT,
|
|
27
|
+
username: TS.USERNAME,
|
|
28
|
+
password: TS.PASSWORD,
|
|
29
|
+
nickname: TS.NICKNAME,
|
|
26
30
|
});
|
|
27
|
-
_teamspeak.on("
|
|
31
|
+
_teamspeak.on("ready", async () => {
|
|
28
32
|
if (this.isReConnecting) {
|
|
29
|
-
logger.info(loggerPluginName + "
|
|
33
|
+
logger.info(loggerPluginName + "重连成功");
|
|
30
34
|
}
|
|
31
35
|
else {
|
|
32
36
|
logger.info(loggerPluginName + "ts3连接成功");
|
|
33
37
|
}
|
|
34
38
|
this.isReConnecting = false;
|
|
35
|
-
await _teamspeak.login(TS.USERNAME, TS.PASSWORD);
|
|
36
|
-
await _teamspeak.virtualServers.use(1);
|
|
37
|
-
await _teamspeak.notifications.subscribeAll();
|
|
38
|
-
await _teamspeak.client.setNickname(TS.NICKNAME);
|
|
39
39
|
this.teamspeak = _teamspeak;
|
|
40
40
|
});
|
|
41
|
-
_teamspeak.on("
|
|
42
|
-
logger.error(loggerPluginName + "ts3连接断开");
|
|
41
|
+
_teamspeak.on("close", (e) => {
|
|
42
|
+
logger.error(loggerPluginName + "ts3连接断开", e);
|
|
43
43
|
this.handelReconnect();
|
|
44
44
|
});
|
|
45
|
-
_teamspeak.on("
|
|
45
|
+
_teamspeak.on("error", (err) => {
|
|
46
46
|
logger.error(loggerPluginName + "ts3连接出错", err);
|
|
47
47
|
});
|
|
48
|
-
_teamspeak.on("
|
|
49
|
-
if (
|
|
50
|
-
logger.info(loggerPluginName + e.nickname + "进入ts");
|
|
51
|
-
const msg = segment.text(e.nickname + "进入ts");
|
|
48
|
+
_teamspeak.on("clientconnect", (e) => {
|
|
49
|
+
if (!disNotifyNameList.includes(e.client.nickname)) {
|
|
50
|
+
logger.info(loggerPluginName + e.client.nickname + "进入ts");
|
|
51
|
+
const msg = segment.text(e.client.nickname + "进入ts");
|
|
52
52
|
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
53
53
|
const contact = karin.contact("group", groupNo + "");
|
|
54
54
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
_teamspeak.on("
|
|
59
|
-
if (e.
|
|
60
|
-
if (!disNotifyNameList.includes(e.nickname)) {
|
|
61
|
-
logger.info(loggerPluginName + e.nickname + "离开ts");
|
|
62
|
-
const msg = segment.text(e.nickname + "离开ts");
|
|
58
|
+
_teamspeak.on("clientdisconnect", (e) => {
|
|
59
|
+
if (e.client) {
|
|
60
|
+
if (!disNotifyNameList.includes(e.client.nickname)) {
|
|
61
|
+
logger.info(loggerPluginName + e.client.nickname + "离开ts");
|
|
62
|
+
const msg = segment.text(e.client.nickname + "离开ts");
|
|
63
63
|
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
64
64
|
const contact = karin.contact("group", groupNo + "");
|
|
65
65
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
@@ -68,83 +68,95 @@ class ts3 {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
// 监听用户移动频道事件
|
|
71
|
-
_teamspeak.on("
|
|
71
|
+
_teamspeak.on("clientmoved", (e) => {
|
|
72
72
|
if (TS.ENABLE_CHANNEL_MOVE_NOTIFY === "true" &&
|
|
73
|
-
e.
|
|
74
|
-
e.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
e.client &&
|
|
74
|
+
!disNotifyNameList.includes(e.client.nickname)) {
|
|
75
|
+
logger.info(loggerPluginName +
|
|
76
|
+
e.client.nickname +
|
|
77
|
+
"移动到频道: " +
|
|
78
|
+
e.channel.name);
|
|
79
|
+
const msg = segment.text(e.client.nickname + "移动到频道: " + e.channel.name);
|
|
78
80
|
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
79
81
|
const contact = karin.contact("group", groupNo + "");
|
|
80
82
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
});
|
|
84
|
-
_teamspeak.connect();
|
|
85
86
|
};
|
|
86
87
|
//获取ts3服务器的所有对应频道的人 -- 并组装成文字可直接发
|
|
87
88
|
getAllChannelList = async () => {
|
|
88
89
|
if (!this.teamspeak) {
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
92
|
+
//默认尝试使用渲染器,调用失败则表示未连接渲染器
|
|
93
|
+
let usePuppeteer = false;
|
|
94
|
+
// try {
|
|
95
|
+
// render.App()
|
|
96
|
+
// } catch (error) {
|
|
97
|
+
// usePuppeteer = false
|
|
98
|
+
// }
|
|
91
99
|
const TS = config();
|
|
92
100
|
const renderList = [];
|
|
93
|
-
renderList.push(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
renderList.push(usePuppeteer
|
|
102
|
+
? `<h1>${TS.SERVER_NAME || TS.HOST}</h1>`
|
|
103
|
+
: `====${TS.SERVER_NAME || TS.HOST}====`);
|
|
104
|
+
renderList.push(usePuppeteer
|
|
105
|
+
? `<div class="tips">仅展示有人的频道</div>`
|
|
106
|
+
: `仅展示有人的频道 `);
|
|
107
|
+
if (!usePuppeteer) {
|
|
108
|
+
//不渲染成图片就使用=====分割频道
|
|
109
|
+
renderList.push(`======`);
|
|
110
|
+
}
|
|
111
|
+
const channelList = await this.teamspeak.channelList(); //所有频道
|
|
98
112
|
let count = 0;
|
|
99
|
-
const allClients = await this.teamspeak.clients.fetch(); //所有在线用户
|
|
100
|
-
const allClient = allClients
|
|
101
|
-
.filter((c) => !disNotifyNameList.includes(c.nickname))
|
|
102
|
-
.map((i) => i); //过滤掉不提醒的用户
|
|
103
113
|
for (let index = 0; index < channelList.length; index++) {
|
|
104
114
|
const channel = channelList[index]; //频道
|
|
105
|
-
const
|
|
115
|
+
const allClient = await channel.getClients(); //在当前频道的人
|
|
116
|
+
//排除不显示的人
|
|
117
|
+
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
106
118
|
count += clients.length;
|
|
107
119
|
if (clients.length == 0)
|
|
108
120
|
continue;
|
|
109
|
-
renderList.push(` ${channel.name} `);
|
|
121
|
+
renderList.push(usePuppeteer ? `<ul>${channel.name}` : ` ${channel.name} `);
|
|
110
122
|
for (let index = 0; index < clients.length; index++) {
|
|
111
123
|
const client = clients[index];
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
const connectTimeSec = moment().diff(moment.unix(client.lastconnected), "second");
|
|
125
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
126
|
+
renderList.push(usePuppeteer
|
|
127
|
+
? `<li>${client.nickname} ${connectTime}</li>`
|
|
128
|
+
: `- ${client.nickname} ${connectTime}`);
|
|
129
|
+
}
|
|
130
|
+
if (!usePuppeteer) {
|
|
131
|
+
//不渲染成图片就使用=====分割频道
|
|
132
|
+
renderList.push(`======`);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
renderList.push("</ul>");
|
|
118
136
|
}
|
|
119
|
-
renderList.push(`======`);
|
|
120
137
|
}
|
|
121
|
-
renderList.splice(2, 0,
|
|
122
|
-
|
|
138
|
+
renderList.splice(2, 0, usePuppeteer
|
|
139
|
+
? `<div class="count">当前频道内共有${count}人</div>`
|
|
140
|
+
: `当前频道内共有${count}人`);
|
|
141
|
+
return usePuppeteer ? renderList.join("") : renderList.join("\n");
|
|
123
142
|
};
|
|
124
143
|
//关闭连接
|
|
125
144
|
quitTs = async () => {
|
|
126
145
|
if (this.teamspeak) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.teamspeak = undefined;
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
logger.info(loggerPluginName + "关闭连接失败", error);
|
|
134
|
-
this.teamspeak = undefined;
|
|
135
|
-
}
|
|
146
|
+
this.teamspeak.removeAllListeners();
|
|
147
|
+
this.teamspeak.quit();
|
|
148
|
+
this.teamspeak = undefined;
|
|
136
149
|
}
|
|
137
150
|
};
|
|
138
151
|
//重连逻辑
|
|
139
152
|
async handelReconnect() {
|
|
140
|
-
|
|
153
|
+
const TS = config();
|
|
141
154
|
if (!this.teamspeak || this.isReConnecting)
|
|
142
155
|
return;
|
|
143
156
|
this.isReConnecting = true;
|
|
144
157
|
logger.info(loggerPluginName + "重连中...");
|
|
145
158
|
try {
|
|
146
|
-
this.
|
|
147
|
-
await teamspeak3.init();
|
|
159
|
+
await this.teamspeak.reconnect(TS.RECONNECT_TIMER, 1000);
|
|
148
160
|
}
|
|
149
161
|
catch (e) {
|
|
150
162
|
logger.error(loggerPluginName + "连接TS3失败", e);
|
|
@@ -161,32 +173,26 @@ export const getAllUserList = async () => {
|
|
|
161
173
|
if (teamspeak3.teamspeak) {
|
|
162
174
|
let count = 0;
|
|
163
175
|
const res = {};
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const allClient = allClients
|
|
168
|
-
.filter((c) => !disNotifyNameList.includes(c.nickname))
|
|
169
|
-
.map((i) => i);
|
|
176
|
+
const channelList = await teamspeak3.teamspeak.channelList().catch(() => {
|
|
177
|
+
return [];
|
|
178
|
+
}); //所有频道
|
|
170
179
|
for (let index = 0; index < channelList.length; index++) {
|
|
171
180
|
const channel = channelList[index]; //频道
|
|
172
|
-
const
|
|
181
|
+
const allClient = await channel.getClients(); //在当前频道的人
|
|
182
|
+
//排除不显示的人
|
|
183
|
+
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
173
184
|
count += clients.length;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
.unix(Number(cdb.client_lastconnected))
|
|
186
|
-
.format("YYYY-MM-DD HH:mm:ss"), //上次连接进来的时间
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
185
|
+
res[channel.name] = clients.map((c) => {
|
|
186
|
+
const connectTimeSec = moment().diff(moment.unix(c.lastconnected), "second");
|
|
187
|
+
let connectTime = `${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}`;
|
|
188
|
+
return {
|
|
189
|
+
nickName: c.nickname, //昵称
|
|
190
|
+
lastconnected: moment
|
|
191
|
+
.unix(c.lastconnected)
|
|
192
|
+
.format("YYYY-MM-DD HH:mm:ss"), //上次连接进来的时间
|
|
193
|
+
connectTime, //已经连接的时间 - 单位分:秒
|
|
194
|
+
};
|
|
195
|
+
});
|
|
190
196
|
}
|
|
191
197
|
return {
|
|
192
198
|
name: config().SERVER_NAME || config().HOST,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "karin-plugin-teamspeak",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "karin 的 teamspeak 插件",
|
|
5
5
|
"homepage": "https://github.com/jacksixth/karin-plugin-teamspeak3",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"pr": "node lib/cli/pr.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"
|
|
29
|
+
"ts3-nodejs-library": "^3.5.3"
|
|
30
30
|
},
|
|
31
31
|
"karin": {
|
|
32
32
|
"apps": [
|