koishi-plugin-common
Advanced tools
Comparing version 4.1.1 to 4.1.2
@@ -232,2 +232,8 @@ var __create = Object.create; | ||
} | ||
async function bind(user, platform, userId) { | ||
await ctx.database.removeUser(platform, userId); | ||
ctx.app._userCache[platform].set(userId, user); | ||
user[platform] = userId; | ||
await user._update(); | ||
} | ||
ctx.command("user/bind", "绑定到账号", {authority: 0}).action(({session}) => { | ||
@@ -244,5 +250,4 @@ const token = generate(session, +(session.subtype === "group")); | ||
const user = await sess.observeUser([session.platform]); | ||
user[session.platform] = session.userId; | ||
delete tokens[session.content]; | ||
await user._update(); | ||
await bind(user, session.platform, session.userId); | ||
return session.send((0, import_koishi_utils.template)("bind.success")); | ||
@@ -260,4 +265,3 @@ } else { | ||
} else { | ||
user[data[0]] = data[1]; | ||
await user._update(); | ||
await bind(user, data[0], data[1]); | ||
return session.send((0, import_koishi_utils.template)("bind.success")); | ||
@@ -338,7 +342,7 @@ } | ||
}); | ||
ctx.command("channel/switch <command...>", "启用和禁用功能", {authority: 3}).channelFields(["disable"]).userFields(["authority"]).adminChannel(({session, target: {disable}}, ...names) => { | ||
ctx.command("channel/switch <command...>", "启用和禁用功能", {authority: 3}).channelFields(["disable"]).userFields(["authority"]).adminChannel(async ({session, target}, ...names) => { | ||
if (!names.length) { | ||
if (!disable.length) | ||
if (!target.disable.length) | ||
return (0, import_koishi_utils.template)("switch.none"); | ||
return (0, import_koishi_utils.template)("switch.list", disable.join(", ")); | ||
return (0, import_koishi_utils.template)("switch.list", target.disable.join(", ")); | ||
} | ||
@@ -352,10 +356,13 @@ names = (0, import_koishi_utils.deduplicate)(names); | ||
return (0, import_koishi_utils.template)("switch.forbidden", forbidden.join(", ")); | ||
for (const name2 of names) { | ||
const index = disable.indexOf(name2); | ||
if (index >= 0) { | ||
disable.splice(index); | ||
} else { | ||
disable.push(name2); | ||
} | ||
} | ||
const add = (0, import_koishi_utils.difference)(names, target.disable); | ||
const remove = (0, import_koishi_utils.intersection)(names, target.disable); | ||
const preserve = (0, import_koishi_utils.difference)(target.disable, names); | ||
const output = []; | ||
if (add.length) | ||
output.push(`禁用 ${add.join(", ")} 功能`); | ||
if (remove.length) | ||
output.push(`启用 ${remove.join(", ")} 功能`); | ||
target.disable = [...preserve, ...add]; | ||
await target._update(); | ||
return `已${output.join(",")}。`; | ||
}); | ||
@@ -362,0 +369,0 @@ ctx.command("channel.flag [-s|-S] [...flags]", "标记信息", {authority: 3}).channelFields(["flag"]).option("list", "-l 标记列表").option("set", "-s 添加标记", {authority: 4}).option("unset", "-S 删除标记", {authority: 4}).adminChannel(flagAction.bind(null, import_koishi_core.Channel.Flag)); |
{ | ||
"name": "koishi-plugin-common", | ||
"description": "Common plugins for Koishi", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"main": "dist/index.js", | ||
@@ -33,3 +33,3 @@ "typings": "dist/index.d.ts", | ||
"peerDependencies": { | ||
"koishi-core": "^3.1.1", | ||
"koishi-core": "^3.2.0", | ||
"koishi-utils": "^4.0.1" | ||
@@ -36,0 +36,0 @@ }, |
Sorry, the diff of this file is not supported yet
88314
858