karin-plugin-teamspeak 1.5.4 → 1.5.6

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 CHANGED
@@ -13,3 +13,43 @@ karin 下的 [teamspeak](https://www.teamspeak.com/zh-CN/) 插件,使用 ts
13
13
  2. 运行 `npx karin .`
14
14
  3. 在 karin web 界面的插件页签中配置该插件
15
15
  4. 保存配置后查看命令行是否成功连接服务器
16
+
17
+ # 功能
18
+
19
+ 1. 监听 ts 服务器用户进入离开事件,在配置的群聊里发送用户进出提示 如:`xxx进入ts`、`xxx离开ts`
20
+ 2. 在群聊或私聊发送`人数`时,发送当前服务器内有人在的频道的人数和进入时长 如:
21
+ ```
22
+ ====服务器名====
23
+ 仅展示有人的频道
24
+ 当前频道内共有4人
25
+ ======
26
+ 聊天听歌等待区
27
+ - BOT (29005287:9)
28
+ - xxx (0:4)
29
+ ======
30
+ fps2
31
+ - xxx (0:31)
32
+ ======
33
+ fps3
34
+ - xxx (96:31)
35
+ ======
36
+ ```
37
+ 3. 可以通过调用接口 `/api/teamspeak/getAllUserList` 来获取当前服务器内所有频道内人数和进入时长包括没人在的频道,返回的数据格式为:
38
+
39
+ ```json
40
+ {
41
+ "name": "配置内的服务器名或host",
42
+ "res": "
43
+ {
44
+ 频道1:[{
45
+ nickName:'xxx', //昵称
46
+ lastconnected: 'YYYY-MM-DD HH:mm:ss', //上次连接进来的时间
47
+ connectTime:'', //已经连接的时间 - 单位分:秒
48
+ },{},...],
49
+ 频道2:[{}],
50
+ 频道3:[{}],
51
+ ...
52
+ }",
53
+ "count": "频道内总人数"
54
+ }
55
+ ```
package/lib/apps/ts3.d.ts CHANGED
@@ -3,7 +3,6 @@ declare class ts3 {
3
3
  teamspeak: undefined | TeamSpeak;
4
4
  connectTimer: number;
5
5
  private isReConnecting;
6
- private reconnectAttempts;
7
6
  init: () => Promise<void>;
8
7
  getAllChannelList: () => Promise<string | undefined>;
9
8
  quitTs: () => Promise<void>;
@@ -12,6 +11,7 @@ declare class ts3 {
12
11
  }
13
12
  declare const teamspeak3: ts3;
14
13
  export declare const getAllUserList: () => Promise<{
14
+ name: string;
15
15
  res: {
16
16
  [name: string]: {
17
17
  nickName: string;
package/lib/apps/ts3.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { QueryProtocol, TeamSpeak } from "ts3-nodejs-library";
2
- import { config, dirPath } from "../utils/index.js";
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";
5
5
  import express from "node-karin/express";
@@ -10,11 +10,9 @@ class ts3 {
10
10
  teamspeak;
11
11
  connectTimer = 0;
12
12
  isReConnecting = false;
13
- reconnectAttempts = 0;
14
13
  //初始化 如果已经有连接了就关闭连接重新连接
15
14
  init = async () => {
16
15
  const TS = config();
17
- this.reconnectAttempts = 0;
18
16
  this.isReConnecting = false;
19
17
  disNotifyNameList = [TS.NICKNAME, ...TS.DIS_NOTIFY_NAME_LIST];
20
18
  logger.info(loggerHex(" ===== ts3 ===== ") + "开始连接ts3服务器...");
@@ -141,14 +139,10 @@ class ts3 {
141
139
  if (!this.teamspeak || this.isReConnecting)
142
140
  return;
143
141
  this.isReConnecting = true;
144
- logger.info(loggerHex(" ===== ts3 ===== ") +
145
- "重连中... 尝试次数: " +
146
- this.reconnectAttempts +
147
- "次");
142
+ logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
148
143
  try {
149
144
  await this.teamspeak.reconnect(TS.RECONNECT_TIMER, 1000);
150
145
  logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
151
- this.reconnectAttempts = 0; // 重连成功后重置重连次数
152
146
  }
153
147
  catch (e) {
154
148
  logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
@@ -168,7 +162,9 @@ export const getAllUserList = async () => {
168
162
  if (teamspeak3.teamspeak) {
169
163
  let count = 0;
170
164
  const res = {};
171
- const channelList = await teamspeak3.teamspeak.channelList(); //所有频道
165
+ const channelList = await teamspeak3.teamspeak.channelList().catch(() => {
166
+ return [];
167
+ }); //所有频道
172
168
  for (let index = 0; index < channelList.length; index++) {
173
169
  const channel = channelList[index]; //频道
174
170
  const allClient = await channel.getClients(); //在当前频道的人
@@ -188,6 +184,7 @@ export const getAllUserList = async () => {
188
184
  });
189
185
  }
190
186
  return {
187
+ name: config().SERVER_NAME || config().HOST,
191
188
  res,
192
189
  count,
193
190
  };
@@ -203,10 +200,4 @@ router.get("/getAllUserList", async (req, res) => {
203
200
  });
204
201
  //将路由挂载到express实例中
205
202
  app.use("/api/teamspeak", router);
206
- //将静态资源挂载到express实例中 - 供外部单页应用网页部署时使用
207
- app.use("/teamspeak", express.static(dirPath + "/resources/static"));
208
- //供外部单页应用网页部署时使用 可用 ip:port/ts3 访问部署的网页
209
- app.get("/teamspeak", (req, res) => {
210
- res.sendFile(dirPath + "/resources/static/index.html");
211
- });
212
203
  export default teamspeak3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karin-plugin-teamspeak",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "karin 的 teamspeak 插件",
5
5
  "homepage": "https://github.com/jacksixth/karin-plugin-teamspeak3",
6
6
  "bugs": {