karin-plugin-teamspeak 1.9.1 → 1.10.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 +84 -91
- 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 { Query } from "teamspeak.js";
|
|
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
|
-
|
|
26
|
-
serverport: TS.SERVER_PORT,
|
|
27
|
-
username: TS.USERNAME,
|
|
28
|
-
password: TS.PASSWORD,
|
|
29
|
-
nickname: TS.NICKNAME,
|
|
22
|
+
const _teamspeak = new Query({
|
|
23
|
+
host: "jacksixth.top",
|
|
24
|
+
port: 10011,
|
|
25
|
+
protocol: TS.PROTOCOL == "SSH" ? "ssh" : "tcp",
|
|
30
26
|
});
|
|
31
|
-
_teamspeak.on("
|
|
27
|
+
_teamspeak.on("Ready", async () => {
|
|
32
28
|
if (this.isReConnecting) {
|
|
33
|
-
logger.info(loggerPluginName + "重连成功");
|
|
29
|
+
logger.info(loggerPluginName + "ts3重连成功");
|
|
34
30
|
}
|
|
35
31
|
else {
|
|
36
32
|
logger.info(loggerPluginName + "ts3连接成功");
|
|
37
33
|
}
|
|
38
34
|
this.isReConnecting = false;
|
|
35
|
+
await _teamspeak.login(TS.USERNAME, TS.PASSWORD);
|
|
36
|
+
await _teamspeak.virtualServers.use({ port: TS.QUERY_PORT });
|
|
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", () => {
|
|
42
|
+
logger.error(loggerPluginName + "ts3连接断开");
|
|
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 (!disNotifyNameList.includes(e.
|
|
50
|
-
logger.info(loggerPluginName + e.
|
|
51
|
-
const msg = segment.text(e.
|
|
48
|
+
_teamspeak.on("ClientEnterView", (e) => {
|
|
49
|
+
if (e.nickname && !disNotifyNameList.includes(e.nickname)) {
|
|
50
|
+
logger.info(loggerPluginName + e.nickname + "进入ts");
|
|
51
|
+
const msg = segment.text(e.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.
|
|
61
|
-
logger.info(loggerPluginName + e.
|
|
62
|
-
const msg = segment.text(e.
|
|
58
|
+
_teamspeak.on("ClientLeaveView", (e) => {
|
|
59
|
+
if (e.nickname) {
|
|
60
|
+
if (!disNotifyNameList.includes(e.nickname)) {
|
|
61
|
+
logger.info(loggerPluginName + e.nickname + "离开ts");
|
|
62
|
+
const msg = segment.text(e.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,15 +68,13 @@ class ts3 {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
// 监听用户移动频道事件
|
|
71
|
-
_teamspeak.on("
|
|
71
|
+
_teamspeak.on("ClientMove", (e) => {
|
|
72
72
|
if (TS.ENABLE_CHANNEL_MOVE_NOTIFY === "true" &&
|
|
73
|
-
e.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
e.channel.name);
|
|
79
|
-
const msg = segment.text(e.client.nickname + "移动到频道: " + e.channel.name);
|
|
73
|
+
e.nickname &&
|
|
74
|
+
e.channel &&
|
|
75
|
+
!disNotifyNameList.includes(e.nickname)) {
|
|
76
|
+
logger.info(loggerPluginName + e.nickname + "移动到频道: " + e.channel.name);
|
|
77
|
+
const msg = segment.text(e.nickname + "移动到频道: " + e.channel.name);
|
|
80
78
|
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
81
79
|
const contact = karin.contact("group", groupNo + "");
|
|
82
80
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
@@ -89,74 +87,63 @@ class ts3 {
|
|
|
89
87
|
if (!this.teamspeak) {
|
|
90
88
|
return;
|
|
91
89
|
}
|
|
92
|
-
//默认尝试使用渲染器,调用失败则表示未连接渲染器
|
|
93
|
-
let usePuppeteer = false;
|
|
94
|
-
// try {
|
|
95
|
-
// render.App()
|
|
96
|
-
// } catch (error) {
|
|
97
|
-
// usePuppeteer = false
|
|
98
|
-
// }
|
|
99
90
|
const TS = config();
|
|
100
91
|
const renderList = [];
|
|
101
|
-
renderList.push(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: `仅展示有人的频道 `);
|
|
107
|
-
if (!usePuppeteer) {
|
|
108
|
-
//不渲染成图片就使用=====分割频道
|
|
109
|
-
renderList.push(`======`);
|
|
110
|
-
}
|
|
111
|
-
const channelList = await this.teamspeak.channelList(); //所有频道
|
|
92
|
+
renderList.push(`====${TS.SERVER_NAME || TS.HOST}====`);
|
|
93
|
+
renderList.push(`仅展示有人的频道 `);
|
|
94
|
+
renderList.push(`======`);
|
|
95
|
+
const channels = await this.teamspeak.channels.fetch(); //所有频道
|
|
96
|
+
const channelList = channels.map((i) => i);
|
|
112
97
|
let count = 0;
|
|
98
|
+
const allClients = await this.teamspeak.clients.fetch(); //所有在线用户
|
|
99
|
+
const allClient = allClients
|
|
100
|
+
.filter((c) => !disNotifyNameList.includes(c.nickname))
|
|
101
|
+
.map((i) => i); //过滤掉不提醒的用户
|
|
113
102
|
for (let index = 0; index < channelList.length; index++) {
|
|
114
103
|
const channel = channelList[index]; //频道
|
|
115
|
-
const
|
|
116
|
-
//排除不显示的人
|
|
117
|
-
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
104
|
+
const clients = allClient.filter((c) => c.channelId == channel.id); //频道内所有用户
|
|
118
105
|
count += clients.length;
|
|
119
106
|
if (clients.length == 0)
|
|
120
107
|
continue;
|
|
121
|
-
renderList.push(
|
|
108
|
+
renderList.push(` ${channel.name} `);
|
|
122
109
|
for (let index = 0; index < clients.length; index++) {
|
|
123
110
|
const client = clients[index];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!usePuppeteer) {
|
|
131
|
-
//不渲染成图片就使用=====分割频道
|
|
132
|
-
renderList.push(`======`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
renderList.push("</ul>");
|
|
111
|
+
if (client.databaseId) {
|
|
112
|
+
const cdb = await this.teamspeak.getRawClientDatabaseProperties(client.databaseId);
|
|
113
|
+
const connectTimeSec = moment().diff(moment.unix(Number(cdb.client_lastconnected)), "second");
|
|
114
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
115
|
+
renderList.push(`- ${client.nickname} ${connectTime}`);
|
|
116
|
+
}
|
|
136
117
|
}
|
|
118
|
+
renderList.push(`======`);
|
|
137
119
|
}
|
|
138
|
-
renderList.splice(2, 0,
|
|
139
|
-
|
|
140
|
-
: `当前频道内共有${count}人`);
|
|
141
|
-
return usePuppeteer ? renderList.join("") : renderList.join("\n");
|
|
120
|
+
renderList.splice(2, 0, `当前频道内共有${count}人`);
|
|
121
|
+
return renderList.join("\n");
|
|
142
122
|
};
|
|
143
123
|
//关闭连接
|
|
144
124
|
quitTs = async () => {
|
|
145
125
|
if (this.teamspeak) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
126
|
+
try {
|
|
127
|
+
this.teamspeak.removeAllListeners();
|
|
128
|
+
this.teamspeak.destroy();
|
|
129
|
+
this.teamspeak = undefined;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
logger.info(loggerPluginName + "关闭连接失败", error);
|
|
133
|
+
this.teamspeak = undefined;
|
|
134
|
+
}
|
|
149
135
|
}
|
|
150
136
|
};
|
|
151
137
|
//重连逻辑
|
|
152
138
|
async handelReconnect() {
|
|
153
|
-
|
|
139
|
+
//没走过重连
|
|
154
140
|
if (!this.teamspeak || this.isReConnecting)
|
|
155
141
|
return;
|
|
156
142
|
this.isReConnecting = true;
|
|
157
143
|
logger.info(loggerPluginName + "重连中...");
|
|
158
144
|
try {
|
|
159
|
-
|
|
145
|
+
this.quitTs();
|
|
146
|
+
await teamspeak3.init();
|
|
160
147
|
}
|
|
161
148
|
catch (e) {
|
|
162
149
|
logger.error(loggerPluginName + "连接TS3失败", e);
|
|
@@ -173,26 +160,32 @@ export const getAllUserList = async () => {
|
|
|
173
160
|
if (teamspeak3.teamspeak) {
|
|
174
161
|
let count = 0;
|
|
175
162
|
const res = {};
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
const channels = await teamspeak3.teamspeak.channels.fetch(); //所有频道
|
|
164
|
+
const channelList = channels.map((i) => i);
|
|
165
|
+
const allClients = await teamspeak3.teamspeak.clients.fetch();
|
|
166
|
+
const allClient = allClients
|
|
167
|
+
.filter((c) => !disNotifyNameList.includes(c.nickname))
|
|
168
|
+
.map((i) => i);
|
|
179
169
|
for (let index = 0; index < channelList.length; index++) {
|
|
180
170
|
const channel = channelList[index]; //频道
|
|
181
|
-
const
|
|
182
|
-
//排除不显示的人
|
|
183
|
-
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
171
|
+
const clients = allClient.filter((c) => c.channelId == channel.id);
|
|
184
172
|
count += clients.length;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
173
|
+
if (channel.name) {
|
|
174
|
+
res[channel.name] = [];
|
|
175
|
+
for (let index = 0; index < clients.length; index++) {
|
|
176
|
+
const client = clients[index];
|
|
177
|
+
const cdb = await teamspeak3.teamspeak.getRawClientDatabaseProperties(client.databaseId);
|
|
178
|
+
const connectTimeSec = moment().diff(moment.unix(Number(cdb.client_lastconnected)), "second");
|
|
179
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
180
|
+
res[channel.name].push({
|
|
181
|
+
nickName: client.nickname,
|
|
182
|
+
connectTime,
|
|
183
|
+
lastconnected: moment
|
|
184
|
+
.unix(Number(cdb.client_lastconnected))
|
|
185
|
+
.format("YYYY-MM-DD HH:mm:ss"), //上次连接进来的时间
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
196
189
|
}
|
|
197
190
|
return {
|
|
198
191
|
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.10.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
|
+
"teamspeak.js": "^1.11.2"
|
|
30
30
|
},
|
|
31
31
|
"karin": {
|
|
32
32
|
"apps": [
|