koishi-plugin-18xx 0.0.5 → 0.0.7
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.js +14 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -99,8 +99,19 @@ function command(ctx, config) {
|
|
99
99
|
if (!found) return "";
|
100
100
|
}
|
101
101
|
}, "checkSessionMiddleware");
|
102
|
-
ctx.command("18xx.bind <id>", "绑定账号").usage("id 是个人资料页地址栏 profile 后面的数字").before(checkSessionMiddleware).action(async ({ session }, id) => {
|
102
|
+
ctx.command("18xx.bind <id>", "绑定账号").option("force", "-f", { authority: 4 }).usage("id 是个人资料页地址栏 profile 后面的数字").before(checkSessionMiddleware).action(async ({ session, options }, id) => {
|
103
103
|
if (Number(id)) {
|
104
|
+
if (!options.force) {
|
105
|
+
const profiles = await ctx.database.get(name, { id: Number(id) });
|
106
|
+
if (profiles.length) {
|
107
|
+
if (profiles.length > 1) {
|
108
|
+
logger.error(`${id} 绑定了多个账号`, profiles, session);
|
109
|
+
}
|
110
|
+
if (profiles[0].userId !== session.userId) {
|
111
|
+
return `${id} 已被其他用户绑定`;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
104
115
|
const result = await ctx.database.upsert(name, [
|
105
116
|
{
|
106
117
|
id: Number(id),
|
@@ -207,12 +218,12 @@ async function server(ctx, config) {
|
|
207
218
|
const { text = "" } = ptx.request.body || {};
|
208
219
|
const result = MESSAGE_REGEX.exec(text);
|
209
220
|
if (!result) {
|
210
|
-
logger.error("Webhook格式错误");
|
221
|
+
logger.error("Webhook格式错误", text);
|
211
222
|
return ptx.status = 400;
|
212
223
|
}
|
213
224
|
const [, webhookId, message] = result;
|
214
225
|
if (!Number(webhookId) || !message) {
|
215
|
-
logger.error("Webhook格式错误");
|
226
|
+
logger.error("Webhook格式错误", text);
|
216
227
|
return ptx.status = 400;
|
217
228
|
}
|
218
229
|
const profiles = await ctx.database.get(name, { id: Number(webhookId) });
|