karin-plugin-teamspeak 1.4.1 → 1.5.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/README.md +8 -6
- package/lib/apps/ts3.d.ts +10 -0
- package/lib/apps/ts3.js +64 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# karin-plugin-teamspeak3
|
|
2
2
|
|
|
3
|
-
karin 下的 [teamspeak](https://www.teamspeak.com/zh-CN/) 插件,使用ts开发。
|
|
3
|
+
karin 下的 [teamspeak](https://www.teamspeak.com/zh-CN/) 插件,使用 ts 开发。
|
|
4
4
|
需要搭配 [karin](https://karin.fun/) 使用。
|
|
5
|
-
在用户进入离开ts服务器时在群里发送用户进出提示
|
|
6
|
-
也会响应QQ群或私聊的 `人数` 命令发送当前服务器内有人在的频道的人数和进入时长
|
|
5
|
+
在用户进入离开 ts 服务器时在群里发送用户进出提示
|
|
6
|
+
也会响应 QQ 群或私聊的 `人数` 命令发送当前服务器内有人在的频道的人数和进入时长
|
|
7
7
|
|
|
8
8
|
# 使用方法
|
|
9
9
|
|
|
10
10
|
1. 安装该插件
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
- `包管理器` 可以通过 `pnpm add karin-plugin-teamspeak@latest -w` 安装
|
|
12
|
+
- `使用编译产物` 可以 clone 该仓库的 build 分支 `git clone --depth=1 -b build https://github.com/jacksixth/karin-plugin-teamspeak3.git ./plugins/karin-plugin-teamspeak/`,然后通过运行 `pnpm install --filter=karin-plugin-teamspeak` 安装
|
|
13
|
+
2. 运行 `npx karin .`
|
|
14
|
+
3. 在 karin web 界面的插件页签中配置该插件
|
|
15
|
+
4. 保存配置后查看命令行是否成功连接服务器
|
package/lib/apps/ts3.d.ts
CHANGED
|
@@ -8,4 +8,14 @@ declare class ts3 {
|
|
|
8
8
|
reconnectTs: () => Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
declare const teamspeak3: ts3;
|
|
11
|
+
export declare const getAllUserList: () => Promise<{
|
|
12
|
+
res: {
|
|
13
|
+
[name: string]: {
|
|
14
|
+
nickName: string;
|
|
15
|
+
lastconnected: string;
|
|
16
|
+
connectTime: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
count: number;
|
|
20
|
+
} | null | undefined>;
|
|
11
21
|
export default teamspeak3;
|
package/lib/apps/ts3.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { QueryProtocol, TeamSpeak } from "ts3-nodejs-library";
|
|
2
|
-
import { config } from "../utils/index.js";
|
|
3
|
-
import karin, { logger, segment } from "node-karin";
|
|
2
|
+
import { config, dirPath } from "../utils/index.js";
|
|
3
|
+
import karin, { logger, segment, app } from "node-karin";
|
|
4
4
|
import moment from "node-karin/moment";
|
|
5
|
-
|
|
5
|
+
import express from "node-karin/express";
|
|
6
|
+
const loggerHex = logger.chalk.hex("#90CAF9");
|
|
7
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "初始化ts3插件");
|
|
6
8
|
let disNotifyNameList = [];
|
|
7
9
|
class ts3 {
|
|
8
10
|
teamspeak;
|
|
@@ -12,7 +14,7 @@ class ts3 {
|
|
|
12
14
|
const TS = config();
|
|
13
15
|
//fix ReferenceError: Cannot access 'config' before initialization
|
|
14
16
|
disNotifyNameList = [TS.NICKNAME, ...TS.DIS_NOTIFY_NAME_LIST];
|
|
15
|
-
logger.info("开始连接ts3服务器...");
|
|
17
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "开始连接ts3服务器...");
|
|
16
18
|
if (this.teamspeak) {
|
|
17
19
|
await this.teamspeak.quit();
|
|
18
20
|
this.teamspeak = undefined;
|
|
@@ -27,43 +29,43 @@ class ts3 {
|
|
|
27
29
|
nickname: TS.NICKNAME,
|
|
28
30
|
});
|
|
29
31
|
_teamspeak.on("ready", async () => {
|
|
30
|
-
logger.info("ts3连接成功");
|
|
32
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "ts3连接成功");
|
|
31
33
|
this.teamspeak = _teamspeak;
|
|
32
34
|
});
|
|
33
35
|
_teamspeak.on("close", (e) => {
|
|
34
|
-
logger.error("ts3连接断开", e);
|
|
36
|
+
logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接断开", e);
|
|
35
37
|
if (this.teamspeak) {
|
|
36
|
-
logger.info("重连中...");
|
|
38
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
|
|
37
39
|
this.teamspeak
|
|
38
40
|
.reconnect(TS.RECONNECT_TIMER, 1000)
|
|
39
41
|
.catch((e) => {
|
|
40
|
-
logger.error("连接TS3失败", e);
|
|
42
|
+
logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
|
|
41
43
|
})
|
|
42
44
|
.then(() => {
|
|
43
|
-
logger.info("重连成功");
|
|
45
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
49
|
_teamspeak.on("error", (err) => {
|
|
48
|
-
logger.error("ts3连接出错", err);
|
|
50
|
+
logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接出错", err);
|
|
49
51
|
if (this.teamspeak) {
|
|
50
|
-
logger.info("重连中...");
|
|
52
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
|
|
51
53
|
this.teamspeak
|
|
52
54
|
.reconnect(TS.RECONNECT_TIMER, 1000)
|
|
53
55
|
.catch((e) => {
|
|
54
|
-
logger.error("连接TS3失败", e);
|
|
56
|
+
logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
|
|
55
57
|
})
|
|
56
58
|
.then(() => {
|
|
57
|
-
logger.info("重连成功");
|
|
59
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
63
|
_teamspeak.on("clientconnect", (e) => {
|
|
62
64
|
if (!disNotifyNameList.includes(e.client.nickname)) {
|
|
63
|
-
logger.info(e.client.nickname + "进入ts");
|
|
65
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + e.client.nickname + "进入ts");
|
|
64
66
|
const msg = segment.text(e.client.nickname + "进入ts");
|
|
65
|
-
const qq =
|
|
66
|
-
|
|
67
|
+
const qq = TS.BOT_SELF_ID;
|
|
68
|
+
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
67
69
|
const contact = karin.contact("group", groupNo + "");
|
|
68
70
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
69
71
|
});
|
|
@@ -72,9 +74,9 @@ class ts3 {
|
|
|
72
74
|
_teamspeak.on("clientdisconnect", (e) => {
|
|
73
75
|
if (e.client) {
|
|
74
76
|
if (!disNotifyNameList.includes(e.client.nickname)) {
|
|
75
|
-
logger.info(e.client.nickname + "离开ts");
|
|
77
|
+
logger.info(loggerHex(" ===== ts3 ===== ") + e.client.nickname + "离开ts");
|
|
76
78
|
const msg = segment.text(e.client.nickname + "离开ts");
|
|
77
|
-
|
|
79
|
+
TS.NOTICE_GROUP_NO.forEach((groupNo) => {
|
|
78
80
|
const contact = karin.contact("group", groupNo + "");
|
|
79
81
|
karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
|
|
80
82
|
});
|
|
@@ -82,7 +84,7 @@ class ts3 {
|
|
|
82
84
|
}
|
|
83
85
|
});
|
|
84
86
|
};
|
|
85
|
-
//获取ts3服务器的所有对应频道的人
|
|
87
|
+
//获取ts3服务器的所有对应频道的人 -- 并组装成文字可直接发
|
|
86
88
|
getAllChannelList = async () => {
|
|
87
89
|
if (!this.teamspeak) {
|
|
88
90
|
return;
|
|
@@ -94,10 +96,11 @@ class ts3 {
|
|
|
94
96
|
// } catch (error) {
|
|
95
97
|
// usePuppeteer = false
|
|
96
98
|
// }
|
|
99
|
+
const TS = config();
|
|
97
100
|
const renderList = [];
|
|
98
101
|
renderList.push(usePuppeteer
|
|
99
|
-
? `<h1>${
|
|
100
|
-
: `====${
|
|
102
|
+
? `<h1>${TS.SERVER_NAME || TS.HOST}</h1>`
|
|
103
|
+
: `====${TS.SERVER_NAME || TS.HOST}====`);
|
|
101
104
|
renderList.push(usePuppeteer
|
|
102
105
|
? `<div class="tips">仅展示有人的频道</div>`
|
|
103
106
|
: `仅展示有人的频道 `);
|
|
@@ -155,4 +158,44 @@ setTimeout(() => {
|
|
|
155
158
|
//确保配置文件生成且正确保存
|
|
156
159
|
teamspeak3.init();
|
|
157
160
|
}, 1000);
|
|
161
|
+
//获取ts3服务器内所有频道内在线人数 -- 给接口用
|
|
162
|
+
export const getAllUserList = async () => {
|
|
163
|
+
if (teamspeak3.teamspeak) {
|
|
164
|
+
let count = 0;
|
|
165
|
+
const res = {};
|
|
166
|
+
const channelList = await teamspeak3.teamspeak.channelList(); //所有频道
|
|
167
|
+
for (let index = 0; index < channelList.length; index++) {
|
|
168
|
+
const channel = channelList[index]; //频道
|
|
169
|
+
const allClient = await channel.getClients(); //在当前频道的人
|
|
170
|
+
//排除不显示的人
|
|
171
|
+
const clients = allClient.filter((c) => !disNotifyNameList.includes(c.nickname));
|
|
172
|
+
count += clients.length;
|
|
173
|
+
res[channel.name] = clients.map((c) => {
|
|
174
|
+
const connectTimeSec = moment().diff(moment.unix(c.lastconnected), "second");
|
|
175
|
+
let connectTime = `(${Math.floor(connectTimeSec / 60)}:${Math.floor(connectTimeSec % 60)}) `;
|
|
176
|
+
return {
|
|
177
|
+
nickName: c.nickname, //昵称
|
|
178
|
+
lastconnected: moment
|
|
179
|
+
.unix(c.lastconnected)
|
|
180
|
+
.format("YYYY-MM-DD HH:mm:ss"), //上次连接进来的时间
|
|
181
|
+
connectTime, //已经连接的时间 - 单位秒
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
res,
|
|
186
|
+
count,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const router = express.Router();
|
|
195
|
+
router.get("/getAllUserList", async (req, res) => {
|
|
196
|
+
const result = await getAllUserList();
|
|
197
|
+
res.send(result);
|
|
198
|
+
});
|
|
199
|
+
app.use("/ts3Api", router);
|
|
200
|
+
app.use(express.static(dirPath + "/resources/static"));
|
|
158
201
|
export default teamspeak3;
|