karin-plugin-teamspeak 1.2.2 → 1.3.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/config/config/config.d.ts +16 -0
- package/config/config/config.json +18 -0
- package/lib/apps/command.js +4 -4
- package/lib/apps/ts3.d.ts +2 -0
- package/lib/apps/ts3.js +14 -2
- package/lib/utils/config.d.ts +2 -0
- package/lib/utils/config.js +4 -2
- package/lib/web.config.d.ts +12 -0
- package/lib/web.config.js +124 -0
- package/package.json +5 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// 定义 config.json 的类型
|
|
2
|
+
export interface Config {
|
|
3
|
+
BOT_SELF_ID: number //当前机器人的QQ号
|
|
4
|
+
//ts的连接信息
|
|
5
|
+
HOST: string //ts3服务器地址
|
|
6
|
+
PROTOCOL: "RAW" | "SSH" //ts3服务器协议 RAW 或是 SSH 一般默认RAW不用改
|
|
7
|
+
QUERY_PORT: number //ts3服务器查询端口
|
|
8
|
+
SERVER_PORT: number //ts3服务器语音端口
|
|
9
|
+
USERNAME: string //ts3服务器admin账号 创建时出现的那个
|
|
10
|
+
PASSWORD: string //ts3服务器admin密码 创建时出现的那个
|
|
11
|
+
NICKNAME: string //连接到ts3服务器使用的用户名 -- 不会显式出现在ts3服务器中可通过查询api查看到
|
|
12
|
+
NOTICE_GROUP_NO: number[] //通知用户进出ts3的群号 可多个
|
|
13
|
+
RECONNECT_TIMER: number //断线重连次数 -1表示将不断尝试
|
|
14
|
+
DIS_NOTIFY_NAME_LIST: string[] //不提醒的昵称列表 可多个 默认不提醒当前加入ts的机器人
|
|
15
|
+
SERVER_NAME: string //展示的服务器名
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"BOT_SELF_ID": 1111111,
|
|
3
|
+
"HOST": "127.0.0.1",
|
|
4
|
+
"PROTOCOL": "RAW",
|
|
5
|
+
"QUERY_PORT": 10011,
|
|
6
|
+
"SERVER_PORT": 9987,
|
|
7
|
+
"USERNAME": "serveradmin",
|
|
8
|
+
"PASSWORD": "abc",
|
|
9
|
+
"NICKNAME": "TESTBOT",
|
|
10
|
+
"NOTICE_GROUP_NO": [
|
|
11
|
+
233333
|
|
12
|
+
],
|
|
13
|
+
"RECONNECT_TIMER": 5,
|
|
14
|
+
"DIS_NOTIFY_NAME_LIST": [
|
|
15
|
+
"TESTBOT"
|
|
16
|
+
],
|
|
17
|
+
"SERVER_NAME": "xxxxxxx"
|
|
18
|
+
}
|
package/lib/apps/command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
4
|
/**
|
|
@@ -7,9 +7,9 @@ import teamspeak3 from "./ts3.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export const image = karin.command(/^#?人数$/, async (e) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
//默认尝试使用渲染器,调用失败则表示未连接将使用文字形式发送服务器人数
|
|
11
|
+
let usePuppeteer = true;
|
|
11
12
|
try {
|
|
12
|
-
//尝试调用渲染器,调用失败则表示未连接
|
|
13
13
|
render.App();
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
@@ -61,7 +61,7 @@ export const image = karin.command(/^#?人数$/, async (e) => {
|
|
|
61
61
|
/** 插件触发是否打印触发日志 */
|
|
62
62
|
log: true,
|
|
63
63
|
/** 插件名称 */
|
|
64
|
-
name: "显示
|
|
64
|
+
name: "显示ts服务器内人数",
|
|
65
65
|
/** 谁可以触发这个插件 'all' | 'master' | 'admin' | 'group.owner' | 'group.admin' */
|
|
66
66
|
permission: "all",
|
|
67
67
|
});
|
package/lib/apps/ts3.d.ts
CHANGED
package/lib/apps/ts3.js
CHANGED
|
@@ -85,9 +85,9 @@ class ts3 {
|
|
|
85
85
|
if (!this.teamspeak) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
//默认尝试使用渲染器,调用失败则表示未连接渲染器
|
|
89
|
+
let usePuppeteer = true;
|
|
89
90
|
try {
|
|
90
|
-
//尝试调用渲染器,调用失败则表示未连接渲染器
|
|
91
91
|
render.App();
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
@@ -136,6 +136,18 @@ class ts3 {
|
|
|
136
136
|
: `当前频道内共有${count}人`);
|
|
137
137
|
return usePuppeteer ? renderList.join("") : renderList.join("\n");
|
|
138
138
|
};
|
|
139
|
+
//关闭连接
|
|
140
|
+
quitTs = async () => {
|
|
141
|
+
if (this.teamspeak) {
|
|
142
|
+
this.teamspeak.quit();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
//重新连接
|
|
146
|
+
reconnectTs = async () => {
|
|
147
|
+
if (this.teamspeak) {
|
|
148
|
+
this.teamspeak.reconnect(config().RECONNECT_TIMER, 1000);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
139
151
|
}
|
|
140
152
|
const teamspeak3 = new ts3();
|
|
141
153
|
teamspeak3.init();
|
package/lib/utils/config.d.ts
CHANGED
package/lib/utils/config.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { dirPath, basename } from "../utils/index.js";
|
|
2
2
|
import { watch, logger, basePath, filesByExt, copyConfigSync, requireFileSync, } from "node-karin";
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
import teamspeak3 from "../apps/ts3.js";
|
|
4
|
+
export const dir = `${basePath}/${basename}`;
|
|
5
|
+
export const dirConfig = `${dir}/config`;
|
|
5
6
|
const defDir = `${dirPath}/config`;
|
|
6
7
|
const defConfig = `${defDir}/config`;
|
|
7
8
|
/**
|
|
@@ -28,5 +29,6 @@ setTimeout(() => {
|
|
|
28
29
|
list.forEach((file) => watch(file, (old, now) => {
|
|
29
30
|
logger.info("旧数据:", old);
|
|
30
31
|
logger.info("新数据:", now);
|
|
32
|
+
teamspeak3.init();
|
|
31
33
|
}));
|
|
32
34
|
}, 2000);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Config } from "config/config/config";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
info: {};
|
|
4
|
+
/** 动态渲染的组件 */
|
|
5
|
+
components: () => (import("node-karin").InputProps | import("node-karin").InputGroupProps | import("node-karin").RadioGroupProps)[];
|
|
6
|
+
/** 前端点击保存之后调用的方法 */
|
|
7
|
+
save: (config: Config) => {
|
|
8
|
+
success: boolean;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { components, logger, writeJsonSync } from "node-karin";
|
|
2
|
+
import { config, dirConfig } from "./utils/index.js";
|
|
3
|
+
const defConfig = config();
|
|
4
|
+
export default {
|
|
5
|
+
info: {
|
|
6
|
+
// 插件信息配置
|
|
7
|
+
},
|
|
8
|
+
/** 动态渲染的组件 */
|
|
9
|
+
components: () => [
|
|
10
|
+
components.input.string("HOST", {
|
|
11
|
+
label: "teamspeak 服务器地址(不带端口)",
|
|
12
|
+
defaultValue: defConfig.HOST,
|
|
13
|
+
variant: "underlined",
|
|
14
|
+
placeholder: "请输入服务器地址",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
regex: /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/,
|
|
18
|
+
error: "请输入正确的IP地址",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
}),
|
|
22
|
+
components.input.string("SERVER_NAME", {
|
|
23
|
+
label: "展示的服务器名(不填写则显示服务器地址)",
|
|
24
|
+
placeholder: "请输入展示的服务器名",
|
|
25
|
+
defaultValue: defConfig.SERVER_NAME,
|
|
26
|
+
variant: "underlined",
|
|
27
|
+
isRequired: false,
|
|
28
|
+
}),
|
|
29
|
+
components.radio.group("PROTOCOL", {
|
|
30
|
+
defaultValue: defConfig.PROTOCOL,
|
|
31
|
+
label: "teamspeak 服务器查询 (一般使用默认的RAW即可)",
|
|
32
|
+
size: "sm",
|
|
33
|
+
orientation: "horizontal",
|
|
34
|
+
radio: [
|
|
35
|
+
{
|
|
36
|
+
componentType: "radio",
|
|
37
|
+
key: "PROTOCOL_RAW",
|
|
38
|
+
value: "RAW",
|
|
39
|
+
label: "RAW",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
componentType: "radio",
|
|
43
|
+
key: "PROTOCOL_SSH",
|
|
44
|
+
value: "SSH",
|
|
45
|
+
label: "SSH",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
components.input.number("QUERY_PORT", {
|
|
50
|
+
label: "teamspeak 服务器查询端口 (一般使用默认 10011 即可)",
|
|
51
|
+
type: "number",
|
|
52
|
+
placeholder: "请输入服务器查询端口",
|
|
53
|
+
variant: "underlined",
|
|
54
|
+
defaultValue: defConfig.QUERY_PORT + "",
|
|
55
|
+
rules: [{ min: 1, max: 65535 }],
|
|
56
|
+
}),
|
|
57
|
+
components.input.number("SERVER_PORT", {
|
|
58
|
+
label: "teamspeak 服务器语音端口 (一般使用默认 9987 即可)",
|
|
59
|
+
defaultValue: defConfig.SERVER_PORT + "",
|
|
60
|
+
placeholder: "请输入服务器语音端口",
|
|
61
|
+
variant: "underlined",
|
|
62
|
+
rules: [{ min: 1, max: 65535 }],
|
|
63
|
+
}),
|
|
64
|
+
components.input.number("RECONNECT_TIMER", {
|
|
65
|
+
label: "teamspeak 连接断开后重连次数 (-1表示将不断尝试)",
|
|
66
|
+
defaultValue: defConfig.RECONNECT_TIMER + "",
|
|
67
|
+
placeholder: "请输入重连次数",
|
|
68
|
+
variant: "underlined",
|
|
69
|
+
rules: [{ min: -1 }],
|
|
70
|
+
}),
|
|
71
|
+
components.input.string("USERNAME", {
|
|
72
|
+
label: "teamspeak 管理员用户名 (建服时出现的,没修改时默认是 serveradmin )",
|
|
73
|
+
defaultValue: defConfig.USERNAME,
|
|
74
|
+
placeholder: "请输入管理员用户名",
|
|
75
|
+
variant: "underlined",
|
|
76
|
+
}),
|
|
77
|
+
components.input.string("PASSWORD", {
|
|
78
|
+
label: "teamspeak 管理员密码 (建服时出现的,每个服务器都不一样)",
|
|
79
|
+
defaultValue: defConfig.PASSWORD,
|
|
80
|
+
type: "password",
|
|
81
|
+
placeholder: "请输入管理员密码",
|
|
82
|
+
variant: "underlined",
|
|
83
|
+
}),
|
|
84
|
+
components.input.string("NICKNAME", {
|
|
85
|
+
label: "插件连接进服务器时使用的昵称 (默认为TSBOT,···客户端看不到该用户···) ",
|
|
86
|
+
placeholder: "请输入连接昵称",
|
|
87
|
+
defaultValue: defConfig.NICKNAME,
|
|
88
|
+
variant: "underlined",
|
|
89
|
+
}),
|
|
90
|
+
components.input.group("NOTICE_GROUP_NO", {
|
|
91
|
+
label: "通知用户进出ts3的群号 可多个",
|
|
92
|
+
template: {
|
|
93
|
+
componentType: "input",
|
|
94
|
+
key: "NOTICE_GROUP_NO",
|
|
95
|
+
type: "number",
|
|
96
|
+
variant: "faded",
|
|
97
|
+
placeholder: "请输入群号",
|
|
98
|
+
},
|
|
99
|
+
data: [...defConfig.NOTICE_GROUP_NO.map((i) => i + "")],
|
|
100
|
+
}),
|
|
101
|
+
components.input.group("DIS_NOTIFY_NAME_LIST", {
|
|
102
|
+
label: "不提醒的昵称列表 可多个 (不会提醒当前机器人,无需添加当前机器人昵称)",
|
|
103
|
+
template: {
|
|
104
|
+
componentType: "input",
|
|
105
|
+
key: "DIS_NOTIFY_NAME",
|
|
106
|
+
type: "text",
|
|
107
|
+
variant: "faded",
|
|
108
|
+
placeholder: "请输入昵称",
|
|
109
|
+
},
|
|
110
|
+
data: [...defConfig.DIS_NOTIFY_NAME_LIST],
|
|
111
|
+
}),
|
|
112
|
+
],
|
|
113
|
+
/** 前端点击保存之后调用的方法 */
|
|
114
|
+
save: (config) => {
|
|
115
|
+
Object.assign(defConfig, config);
|
|
116
|
+
writeJsonSync(`${dirConfig}/config.json`, config);
|
|
117
|
+
logger.info("保存的配置:", config);
|
|
118
|
+
// 在这里处理保存逻辑
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
message: "保存成功",
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "karin-plugin-teamspeak",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "karin 的 teamspeak3 插件",
|
|
5
5
|
"homepage": "https://github.com/jacksixth/karin-plugin-teamspeak3",
|
|
6
6
|
"bugs": {
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"static": [
|
|
30
30
|
"resources"
|
|
31
31
|
],
|
|
32
|
+
"web": "./lib/web.config.js",
|
|
33
|
+
"ts-web": "./src/web.config.ts",
|
|
32
34
|
"files": [
|
|
33
35
|
"config",
|
|
34
36
|
"data",
|
|
@@ -45,8 +47,8 @@
|
|
|
45
47
|
"files": [
|
|
46
48
|
"/lib/**/*.js",
|
|
47
49
|
"/lib/**/*.d.ts",
|
|
48
|
-
"/config/*.json",
|
|
49
|
-
"/config/*.d.ts",
|
|
50
|
+
"/config/config/*.json",
|
|
51
|
+
"/config/config/*.d.ts",
|
|
50
52
|
"resources",
|
|
51
53
|
"LICENSE",
|
|
52
54
|
"package.json",
|