karin-plugin-teamspeak 1.5.6 → 1.5.8

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
@@ -36,20 +36,19 @@ karin 下的 [teamspeak](https://www.teamspeak.com/zh-CN/) 插件,使用 ts
36
36
  ```
37
37
  3. 可以通过调用接口 `/api/teamspeak/getAllUserList` 来获取当前服务器内所有频道内人数和进入时长包括没人在的频道,返回的数据格式为:
38
38
 
39
- ```json
39
+ ```
40
40
  {
41
- "name": "配置内的服务器名或host",
42
- "res": "
43
- {
41
+ name: "配置内的服务器名或host",
42
+ res: {
44
43
  频道1:[{
45
- nickName:'xxx', //昵称
46
- lastconnected: 'YYYY-MM-DD HH:mm:ss', //上次连接进来的时间
47
- connectTime:'', //已经连接的时间 - 单位分:秒
44
+ nickName:"xxx", //昵称
45
+ lastconnected: "YYYY-MM-DD HH:mm:ss", //上次连接进来的时间
46
+ connectTime:"", //已经连接的时间 - 单位分:秒
48
47
  },{},...],
49
48
  频道2:[{}],
50
49
  频道3:[{}],
51
50
  ...
52
- }",
53
- "count": "频道内总人数"
51
+ },
52
+ count: "频道内总人数"
54
53
  }
55
54
  ```
@@ -1,6 +1,7 @@
1
1
  import { dirPath } from "../utils/index.js";
2
2
  import { karin, render, common, segment, logger } from "node-karin";
3
3
  import teamspeak3 from "./ts3.js";
4
+ const loggerPluginName = logger.chalk.hex("#90CAF9")(" ===== ts3 ===== ");
4
5
  /**
5
6
  * 渲染ts3服务器内存在用户的列表
6
7
  * 触发指令: 人数
@@ -50,7 +51,7 @@ export const image = karin.command(/^#?人数$/, async (e) => {
50
51
  }
51
52
  }
52
53
  catch (error) {
53
- logger.error(error);
54
+ logger.error(loggerPluginName, error);
54
55
  await e.reply(JSON.stringify(error));
55
56
  return true;
56
57
  }
package/lib/apps/ts3.js CHANGED
@@ -3,8 +3,8 @@ 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";
6
- const loggerHex = logger.chalk.hex("#90CAF9");
7
- logger.info(loggerHex(" ===== ts3 ===== ") + "初始化ts3插件");
6
+ const loggerPluginName = logger.chalk.hex("#90CAF9")(" ===== ts3 ===== ");
7
+ logger.info(loggerPluginName + "初始化ts3插件");
8
8
  let disNotifyNameList = [];
9
9
  class ts3 {
10
10
  teamspeak;
@@ -15,10 +15,9 @@ class ts3 {
15
15
  const TS = config();
16
16
  this.isReConnecting = false;
17
17
  disNotifyNameList = [TS.NICKNAME, ...TS.DIS_NOTIFY_NAME_LIST];
18
- logger.info(loggerHex(" ===== ts3 ===== ") + "开始连接ts3服务器...");
18
+ logger.info(loggerPluginName + "开始连接ts3服务器...");
19
19
  if (this.teamspeak) {
20
- await this.teamspeak.quit();
21
- this.teamspeak = undefined;
20
+ await this.quitTs();
22
21
  }
23
22
  const _teamspeak = new TeamSpeak({
24
23
  host: TS.HOST,
@@ -30,22 +29,21 @@ class ts3 {
30
29
  nickname: TS.NICKNAME,
31
30
  });
32
31
  _teamspeak.on("ready", async () => {
33
- logger.info(loggerHex(" ===== ts3 ===== ") + "ts3连接成功");
32
+ logger.info(loggerPluginName + "ts3连接成功");
34
33
  this.teamspeak = _teamspeak;
35
34
  });
36
35
  _teamspeak.on("close", (e) => {
37
- logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接断开", e);
36
+ logger.error(loggerPluginName + "ts3连接断开", e);
38
37
  this.handelReconnect();
39
38
  });
40
39
  _teamspeak.on("error", (err) => {
41
- logger.error(loggerHex(" ===== ts3 ===== ") + "ts3连接出错", err);
40
+ logger.error(loggerPluginName + "ts3连接出错", err);
42
41
  this.handelReconnect();
43
42
  });
44
43
  _teamspeak.on("clientconnect", (e) => {
45
44
  if (!disNotifyNameList.includes(e.client.nickname)) {
46
- logger.info(loggerHex(" ===== ts3 ===== ") + e.client.nickname + "进入ts");
45
+ logger.info(loggerPluginName + e.client.nickname + "进入ts");
47
46
  const msg = segment.text(e.client.nickname + "进入ts");
48
- const qq = TS.BOT_SELF_ID;
49
47
  TS.NOTICE_GROUP_NO.forEach((groupNo) => {
50
48
  const contact = karin.contact("group", groupNo + "");
51
49
  karin.sendMsg(karin.getBotAll()[1].account.selfId, contact, msg);
@@ -55,7 +53,7 @@ class ts3 {
55
53
  _teamspeak.on("clientdisconnect", (e) => {
56
54
  if (e.client) {
57
55
  if (!disNotifyNameList.includes(e.client.nickname)) {
58
- logger.info(loggerHex(" ===== ts3 ===== ") + e.client.nickname + "离开ts");
56
+ logger.info(loggerPluginName + e.client.nickname + "离开ts");
59
57
  const msg = segment.text(e.client.nickname + "离开ts");
60
58
  TS.NOTICE_GROUP_NO.forEach((groupNo) => {
61
59
  const contact = karin.contact("group", groupNo + "");
@@ -124,7 +122,9 @@ class ts3 {
124
122
  //关闭连接
125
123
  quitTs = async () => {
126
124
  if (this.teamspeak) {
125
+ this.teamspeak.removeAllListeners();
127
126
  this.teamspeak.quit();
127
+ this.teamspeak = undefined;
128
128
  }
129
129
  };
130
130
  //重新连接
@@ -132,6 +132,9 @@ class ts3 {
132
132
  if (this.teamspeak) {
133
133
  this.teamspeak.reconnect(config().RECONNECT_TIMER, 1000);
134
134
  }
135
+ else {
136
+ this.init();
137
+ }
135
138
  };
136
139
  //重连逻辑
137
140
  async handelReconnect() {
@@ -139,13 +142,13 @@ class ts3 {
139
142
  if (!this.teamspeak || this.isReConnecting)
140
143
  return;
141
144
  this.isReConnecting = true;
142
- logger.info(loggerHex(" ===== ts3 ===== ") + "重连中...");
145
+ logger.info(loggerPluginName + "重连中...");
143
146
  try {
144
147
  await this.teamspeak.reconnect(TS.RECONNECT_TIMER, 1000);
145
- logger.info(loggerHex(" ===== ts3 ===== ") + "重连成功");
148
+ logger.info(loggerPluginName + "重连成功");
146
149
  }
147
150
  catch (e) {
148
- logger.error(loggerHex(" ===== ts3 ===== ") + "连接TS3失败", e);
151
+ logger.error(loggerPluginName + "连接TS3失败", e);
149
152
  }
150
153
  finally {
151
154
  this.isReConnecting = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karin-plugin-teamspeak",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "karin 的 teamspeak 插件",
5
5
  "homepage": "https://github.com/jacksixth/karin-plugin-teamspeak3",
6
6
  "bugs": {