koishi-plugin-tmp-application-change 1.0.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/lib/index.d.ts +10 -0
- package/lib/index.js +101 -0
- package/package.json +25 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "tmp-application-change";
|
|
3
|
+
export interface Config {
|
|
4
|
+
token: string;
|
|
5
|
+
allowedGroups: string[];
|
|
6
|
+
checkApiUrl: string;
|
|
7
|
+
approveApiUrl: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const Config: Schema<Config>;
|
|
10
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
name: () => name
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_koishi = require("koishi");
|
|
29
|
+
var import_koishi2 = require("koishi");
|
|
30
|
+
var name = "tmp-application-change";
|
|
31
|
+
var Config = import_koishi.Schema.object({
|
|
32
|
+
token: import_koishi.Schema.string().description("API访问令牌").required(),
|
|
33
|
+
allowedGroups: import_koishi.Schema.array(import_koishi.Schema.string()).description("允许使用指令的群号列表").required(),
|
|
34
|
+
checkApiUrl: import_koishi.Schema.string().description("查询申请状态的API地址").required(),
|
|
35
|
+
approveApiUrl: import_koishi.Schema.string().description("审批申请的API地址").required()
|
|
36
|
+
});
|
|
37
|
+
var logger = new import_koishi2.Logger("tmp-application-change");
|
|
38
|
+
function apply(ctx, config) {
|
|
39
|
+
ctx.middleware((session, next) => {
|
|
40
|
+
if (!config.allowedGroups.includes(session.channelId.toString())) {
|
|
41
|
+
return session.send("此群无权限使用此指令");
|
|
42
|
+
}
|
|
43
|
+
return next();
|
|
44
|
+
});
|
|
45
|
+
ctx.command("vtc-apply <recruitment_id:string> <status:string> [reason:string]", "VTC申请审批", {
|
|
46
|
+
authority: 1
|
|
47
|
+
}).action(async ({ session }, recruitmentId, status, reason) => {
|
|
48
|
+
try {
|
|
49
|
+
if (!recruitmentId || !status) {
|
|
50
|
+
return "请提供完整的参数:recruitment_id 和 status";
|
|
51
|
+
}
|
|
52
|
+
const statusLower = status.toLowerCase();
|
|
53
|
+
if (statusLower !== "同意" && statusLower !== "拒绝") {
|
|
54
|
+
return 'status只能是"同意"或"拒绝"';
|
|
55
|
+
}
|
|
56
|
+
if (statusLower === "拒绝" && !reason) {
|
|
57
|
+
return "拒绝申请时必须说明原因";
|
|
58
|
+
}
|
|
59
|
+
const checkUrl = `${config.checkApiUrl}?token=${config.token}`;
|
|
60
|
+
logger.info(`查询申请状态: ${checkUrl}`);
|
|
61
|
+
const checkResponse = await ctx.http.get(checkUrl);
|
|
62
|
+
logger.info(`查询响应: ${JSON.stringify(checkResponse)}`);
|
|
63
|
+
if (checkResponse.code !== 200) {
|
|
64
|
+
return `查询申请状态失败: ${checkResponse.msg || "未知错误"}`;
|
|
65
|
+
}
|
|
66
|
+
const application = checkResponse.data?.find(
|
|
67
|
+
(app) => app.applicationId === recruitmentId.toString()
|
|
68
|
+
);
|
|
69
|
+
if (!application) {
|
|
70
|
+
return "没有找到该VTC申请";
|
|
71
|
+
}
|
|
72
|
+
if (application.status !== "New") {
|
|
73
|
+
return `该申请已经审核过了,当前状态: ${application.status}`;
|
|
74
|
+
}
|
|
75
|
+
const action = statusLower === "同意" ? "hire" : "decline";
|
|
76
|
+
let approveUrl = `${config.approveApiUrl}?token=${config.token}&recruitment_id=${recruitmentId}&action=${action}`;
|
|
77
|
+
if (statusLower === "拒绝") {
|
|
78
|
+
approveUrl += `&reason=${encodeURIComponent(reason)}`;
|
|
79
|
+
}
|
|
80
|
+
logger.info(`执行审批: ${approveUrl}`);
|
|
81
|
+
const approveResponse = await ctx.http.get(approveUrl);
|
|
82
|
+
logger.info(`审批响应: ${JSON.stringify(approveResponse)}`);
|
|
83
|
+
if (approveResponse.code === 200) {
|
|
84
|
+
const successMsg = statusLower === "同意" ? "同意成功" : "拒绝成功";
|
|
85
|
+
return `${successMsg},申请ID: ${recruitmentId}`;
|
|
86
|
+
} else {
|
|
87
|
+
return `审批失败: ${approveResponse.msg || "未知错误"}`;
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
logger.error("处理VTC申请时发生错误:", error);
|
|
91
|
+
return "处理申请时发生错误,请稍后重试";
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
__name(apply, "apply");
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
Config,
|
|
99
|
+
apply,
|
|
100
|
+
name
|
|
101
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-tmp-application-change",
|
|
3
|
+
"description": "truckersmp中vtc申请审批",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"opwop <slhp1013@qq.com>"
|
|
7
|
+
],
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"typings": "lib/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"scripts": {},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"chatbot",
|
|
18
|
+
"koishi",
|
|
19
|
+
"plugin"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"koishi": "4.18.11"
|
|
24
|
+
}
|
|
25
|
+
}
|