karin-plugin-teamspeak 1.9.1 → 1.10.1
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 +85 -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,95 +68,83 @@ 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);
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
});
|
|
84
|
+
_teamspeak.connect();
|
|
86
85
|
};
|
|
87
86
|
//获取ts3服务器的所有对应频道的人 -- 并组装成文字可直接发
|
|
88
87
|
getAllChannelList = async () => {
|
|
89
88
|
if (!this.teamspeak) {
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
|
-
//默认尝试使用渲染器,调用失败则表示未连接渲染器
|
|
93
|
-
let usePuppeteer = false;
|
|
94
|
-
// try {
|
|
95
|
-
// render.App()
|
|
96
|
-
// } catch (error) {
|
|
97
|
-
// usePuppeteer = false
|
|
98
|
-
// }
|
|
99
91
|
const TS = config();
|
|
100
92
|
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(); //所有频道
|
|
93
|
+
renderList.push(`====${TS.SERVER_NAME || TS.HOST}====`);
|
|
94
|
+
renderList.push(`仅展示有人的频道 `);
|
|
95
|
+
renderList.push(`======`);
|
|
96
|
+
const channels = await this.teamspeak.channels.fetch(); //所有频道
|
|
97
|
+
const channelList = channels.map((i) => i);
|
|
112
98
|
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); //过滤掉不提醒的用户
|
|
113
103
|
for (let index = 0; index < channelList.length; index++) {
|
|
114
104
|
const channel = channelList[index]; //频道
|
|
115
|
-
const
|
|
116
|
-
//排除不显示的人
|
|
117
|
-
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
105
|
+
const clients = allClient.filter((c) => c.channelId == channel.id); //频道内所有用户
|
|
118
106
|
count += clients.length;
|
|
119
107
|
if (clients.length == 0)
|
|
120
108
|
continue;
|
|
121
|
-
renderList.push(
|
|
109
|
+
renderList.push(` ${channel.name} `);
|
|
122
110
|
for (let index = 0; index < clients.length; index++) {
|
|
123
111
|
const client = clients[index];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!usePuppeteer) {
|
|
131
|
-
//不渲染成图片就使用=====分割频道
|
|
132
|
-
renderList.push(`======`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
renderList.push("</ul>");
|
|
112
|
+
if (client.databaseId) {
|
|
113
|
+
const cdb = await this.teamspeak.getRawClientDatabaseProperties(client.databaseId);
|
|
114
|
+
const connectTimeSec = moment().diff(moment.unix(Number(cdb.client_lastconnected)), "second");
|
|
115
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
116
|
+
renderList.push(`- ${client.nickname} ${connectTime}`);
|
|
117
|
+
}
|
|
136
118
|
}
|
|
119
|
+
renderList.push(`======`);
|
|
137
120
|
}
|
|
138
|
-
renderList.splice(2, 0,
|
|
139
|
-
|
|
140
|
-
: `当前频道内共有${count}人`);
|
|
141
|
-
return usePuppeteer ? renderList.join("") : renderList.join("\n");
|
|
121
|
+
renderList.splice(2, 0, `当前频道内共有${count}人`);
|
|
122
|
+
return renderList.join("\n");
|
|
142
123
|
};
|
|
143
124
|
//关闭连接
|
|
144
125
|
quitTs = async () => {
|
|
145
126
|
if (this.teamspeak) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
127
|
+
try {
|
|
128
|
+
this.teamspeak.removeAllListeners();
|
|
129
|
+
this.teamspeak.destroy();
|
|
130
|
+
this.teamspeak = undefined;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
logger.info(loggerPluginName + "关闭连接失败", error);
|
|
134
|
+
this.teamspeak = undefined;
|
|
135
|
+
}
|
|
149
136
|
}
|
|
150
137
|
};
|
|
151
138
|
//重连逻辑
|
|
152
139
|
async handelReconnect() {
|
|
153
|
-
|
|
140
|
+
//没走过重连
|
|
154
141
|
if (!this.teamspeak || this.isReConnecting)
|
|
155
142
|
return;
|
|
156
143
|
this.isReConnecting = true;
|
|
157
144
|
logger.info(loggerPluginName + "重连中...");
|
|
158
145
|
try {
|
|
159
|
-
|
|
146
|
+
this.quitTs();
|
|
147
|
+
await teamspeak3.init();
|
|
160
148
|
}
|
|
161
149
|
catch (e) {
|
|
162
150
|
logger.error(loggerPluginName + "连接TS3失败", e);
|
|
@@ -173,26 +161,32 @@ export const getAllUserList = async () => {
|
|
|
173
161
|
if (teamspeak3.teamspeak) {
|
|
174
162
|
let count = 0;
|
|
175
163
|
const res = {};
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
164
|
+
const channels = await teamspeak3.teamspeak.channels.fetch(); //所有频道
|
|
165
|
+
const channelList = channels.map((i) => i);
|
|
166
|
+
const allClients = await teamspeak3.teamspeak.clients.fetch();
|
|
167
|
+
const allClient = allClients
|
|
168
|
+
.filter((c) => !disNotifyNameList.includes(c.nickname))
|
|
169
|
+
.map((i) => i);
|
|
179
170
|
for (let index = 0; index < channelList.length; index++) {
|
|
180
171
|
const channel = channelList[index]; //频道
|
|
181
|
-
const
|
|
182
|
-
//排除不显示的人
|
|
183
|
-
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
172
|
+
const clients = allClient.filter((c) => c.channelId == channel.id);
|
|
184
173
|
count += clients.length;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
174
|
+
if (channel.name) {
|
|
175
|
+
res[channel.name] = [];
|
|
176
|
+
for (let index = 0; index < clients.length; index++) {
|
|
177
|
+
const client = clients[index];
|
|
178
|
+
const cdb = await teamspeak3.teamspeak.getRawClientDatabaseProperties(client.databaseId);
|
|
179
|
+
const connectTimeSec = moment().diff(moment.unix(Number(cdb.client_lastconnected)), "second");
|
|
180
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
181
|
+
res[channel.name].push({
|
|
182
|
+
nickName: client.nickname,
|
|
183
|
+
connectTime,
|
|
184
|
+
lastconnected: moment
|
|
185
|
+
.unix(Number(cdb.client_lastconnected))
|
|
186
|
+
.format("YYYY-MM-DD HH:mm:ss"), //上次连接进来的时间
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
196
190
|
}
|
|
197
191
|
return {
|
|
198
192
|
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.1",
|
|
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": [
|