koishi-plugin-bcjh-uidtransfer 0.0.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/lib/index.d.ts +17 -0
- package/lib/index.js +151 -0
- package/package.json +20 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "bcjh-uidtransfer";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export interface Config {
|
|
5
|
+
adminQQ: string[];
|
|
6
|
+
monetaryName: string;
|
|
7
|
+
botId: string;
|
|
8
|
+
showPic: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Config: Schema<Config>;
|
|
11
|
+
declare module 'koishi' {
|
|
12
|
+
interface Context {
|
|
13
|
+
monetary: any;
|
|
14
|
+
database: any;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
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 src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
var import_koishi = require("koishi");
|
|
30
|
+
var name = "bcjh-uidtransfer";
|
|
31
|
+
var inject = ["database", "monetary"];
|
|
32
|
+
var Config = import_koishi.Schema.object({
|
|
33
|
+
adminQQ: import_koishi.Schema.array(String).role("table").description("管理员QQ 可执行添加积分操作"),
|
|
34
|
+
monetaryName: import_koishi.Schema.string().default("货币").description("积分的名字"),
|
|
35
|
+
botId: import_koishi.Schema.string().default("").description("QQ官方机器人的 id (实现头像获取)"),
|
|
36
|
+
showPic: import_koishi.Schema.boolean().default(true).description("是否显示用户头像 (需绑定QQbotId)")
|
|
37
|
+
});
|
|
38
|
+
function apply(ctx, config) {
|
|
39
|
+
const transfer = {
|
|
40
|
+
/** 获取用户自己信息 */
|
|
41
|
+
async getUserInfo(session) {
|
|
42
|
+
const uid = session.user.id;
|
|
43
|
+
const userId = session.userId;
|
|
44
|
+
const channelId = session.channelId;
|
|
45
|
+
const guildId = session.guildId;
|
|
46
|
+
let monetary = 0;
|
|
47
|
+
const [data] = await ctx.database.get("monetary", { uid });
|
|
48
|
+
if (!data) {
|
|
49
|
+
await ctx.monetary.gain(uid, 0);
|
|
50
|
+
} else {
|
|
51
|
+
monetary = data.value;
|
|
52
|
+
}
|
|
53
|
+
const isAdmin = config.adminQQ.includes(session.userId);
|
|
54
|
+
const successMsg = isAdmin ? "获取管理员信息成功!" : "获取用户信息成功!";
|
|
55
|
+
const text = `${successMsg}
|
|
56
|
+
[uid] ${uid}
|
|
57
|
+
[userID] ${userId}
|
|
58
|
+
[频道ID] ${channelId || "-"}
|
|
59
|
+
[群组ID] ${guildId || "-"}
|
|
60
|
+
[平台] ${session.platform || "-"}
|
|
61
|
+
[持有${config.monetaryName}] ${monetary}`;
|
|
62
|
+
let message = "";
|
|
63
|
+
if (config.showPic) {
|
|
64
|
+
message += import_koishi.h.image(`http://q.qlogo.cn/qqapp/${config.botId}/${userId}/640`);
|
|
65
|
+
}
|
|
66
|
+
message += text;
|
|
67
|
+
return message;
|
|
68
|
+
},
|
|
69
|
+
/** 为用户添加积分 */
|
|
70
|
+
async addUserMonetary(uid, num) {
|
|
71
|
+
const [data] = await ctx.database.get("monetary", { uid });
|
|
72
|
+
if (!data) {
|
|
73
|
+
return `[×] 查找目标失败,如若确定该 uid 存在,建议目标发送 /uid 确认并初始化信息。`;
|
|
74
|
+
}
|
|
75
|
+
const monetary = data.value;
|
|
76
|
+
num = Math.ceil(num);
|
|
77
|
+
if (num === 0) {
|
|
78
|
+
return `[×] 请提供一个实际的值,为目标添加积分 0 是无意义的操作噢~`;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
if (num > 0) {
|
|
82
|
+
await ctx.monetary.gain(uid, num);
|
|
83
|
+
return `[√] 操作成功,为目标充值了${num} ${config.monetaryName}。
|
|
84
|
+
当前目标持有 ${monetary + num}`;
|
|
85
|
+
} else {
|
|
86
|
+
await ctx.monetary.cost(uid, Math.abs(num));
|
|
87
|
+
return `[√] 操作成功,为目标扣除了${num} ${config.monetaryName}。
|
|
88
|
+
当前目标持有 ${monetary + num}`;
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
ctx.logger("bcjh-uidtransfer").error(error);
|
|
92
|
+
return `[×] 操作失败,未知错误。请查看日志`;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
/** 查看用户添加积分 (用于管理员确认) */
|
|
96
|
+
async getUserMonetary(uid) {
|
|
97
|
+
const [data] = await ctx.database.get("monetary", { uid });
|
|
98
|
+
const [bindData] = await ctx.database.get("binding", { aid: uid });
|
|
99
|
+
if (!data) {
|
|
100
|
+
return { code: false, msg: `[×] 查找目标失败,如若确定该 uid 存在,建议目标发送 /uid 确认并初始化信息。` };
|
|
101
|
+
} else {
|
|
102
|
+
const monetary = data.value;
|
|
103
|
+
let msg = "";
|
|
104
|
+
if (config.showPic && bindData) {
|
|
105
|
+
msg += import_koishi.h.image(`http://q.qlogo.cn/qqapp/${config.botId}/${bindData.pid}/640`);
|
|
106
|
+
}
|
|
107
|
+
msg += `[?] 确认目标信息为:
|
|
108
|
+
[uid] ${data.uid}
|
|
109
|
+
[userID] ${bindData?.pid || "-"}
|
|
110
|
+
[持有${config.monetaryName}] ${monetary}
|
|
111
|
+
|
|
112
|
+
是否对其进行操作?(20秒内回复 "是" 则进行操作)`;
|
|
113
|
+
return { code: true, msg };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ctx.command("UID", "查看个人标识符及积分信息").alias("uid").userFields(["id"]).action(async ({ session }) => {
|
|
118
|
+
return await transfer.getUserInfo(session);
|
|
119
|
+
});
|
|
120
|
+
ctx.command("添加积分 <uid:number> <num:number>").action(async ({ session }, uid, num) => {
|
|
121
|
+
if (!config.adminQQ.includes(session.userId)) {
|
|
122
|
+
return `[×] 您不是管理员,无权操作该指令...`;
|
|
123
|
+
}
|
|
124
|
+
if (!uid || !num) {
|
|
125
|
+
return `[×] 请填写完整参数,示例:/添加积分 目标uid 充值的金额 (可以为负数)`;
|
|
126
|
+
}
|
|
127
|
+
const result = await transfer.getUserMonetary(uid);
|
|
128
|
+
if (!result.code) {
|
|
129
|
+
return result.msg;
|
|
130
|
+
}
|
|
131
|
+
await session.send(result.msg);
|
|
132
|
+
const type = await session.prompt(2e4);
|
|
133
|
+
if (type === void 0) {
|
|
134
|
+
session.send(`[×] 操作超时,退出积分处理操作...`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (type !== "是") {
|
|
138
|
+
session.send(`[×] 操作取消,退出积分处理操作...`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
return await transfer.addUserMonetary(uid, num);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
__name(apply, "apply");
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
Config,
|
|
148
|
+
apply,
|
|
149
|
+
inject,
|
|
150
|
+
name
|
|
151
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-bcjh-uidtransfer",
|
|
3
|
+
"description": "自用bcjh-uidtransfer",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"chatbot",
|
|
14
|
+
"koishi",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"koishi": "4.18.11"
|
|
19
|
+
}
|
|
20
|
+
}
|