From 8371cf34c66210ea0d2b89c0399fbc5f6144be49 Mon Sep 17 00:00:00 2001 From: idranme Date: Mon, 12 Aug 2024 17:33:57 +0800 Subject: [PATCH] 1.7.3 --- package.json | 2 +- src/index.ts | 35 +++++++++++------------------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 7c30819..a728961 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-waifu", "description": "Marry with your groupmate", - "version": "1.7.2", + "version": "1.7.3", "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ diff --git a/src/index.ts b/src/index.ts index 8528e72..0018beb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,14 +51,14 @@ export function apply(ctx: Context, cfg: Config) { // sid: platform:selfId ctx.guild().on('message-created', async (session) => { - if (isNullable(session.userId) || session.userId == '0') return + if (isNullable(session.userId) || session.userId === '0') return const member: Universal.GuildMember = { user: session.event.user, ...session.event.member } await ctx.cache.set(`waifu_members_${session.gid}`, session.userId, member, 4 * Time.day) await ctx.cache.set(`waifu_members_active_${session.gid}`, session.userId, '', cfg.activeDays * Time.day) }) ctx.on('guild-member-removed', (session) => { - if (isNullable(session.userId) || session.userId == '0') return + if (isNullable(session.userId) || session.userId === '0') return ctx.cache.delete(`waifu_members_${session.gid}`, session.userId) ctx.cache.delete(`waifu_members_active_${session.gid}`, session.userId) }) @@ -81,26 +81,6 @@ export function apply(ctx: Context, cfg: Config) { return result } - /*ctx.command('waifu_reset_marriages').action(async ({ session }) => { - if (!session.guildId) { - return session.text('.members-too-few') - } - const { gid } = session - ctx.cache.clear(`waifu_marriages_${gid}`) - return session.text('reset_marriages') - }) - - ctx.command('waifu_reset_all').action(async ({ session }) => { - if (!session.guildId) { - return session.text('.members-too-few') - } - const { gid } = session - ctx.cache.clear(`waifu_marriages_${gid}`) - ctx.cache.clear(`waifu_members_${gid}`) - ctx.cache.clear(`waifu_members_active_${gid}`) - return session.text('reset_all') - })*/ - ctx.command('waifu') .alias('marry', '娶群友', '今日老婆') .action(async ({ session }) => { @@ -112,10 +92,17 @@ export function apply(ctx: Context, cfg: Config) { if (target) { let selected: Universal.GuildMember try { - selected = await ctx.cache.get(`waifu_members_${gid}`, target) + selected = await session.bot.getGuildMember(session.guildId, target) } catch { } try { - selected ??= await session.bot.getGuildMember(session.guildId, target) + const member = await ctx.cache.get(`waifu_members_${gid}`, target) + if (!selected) { + selected = member + } else { + selected.nick ??= member.nick + selected.user ??= member.user + selected.user.name ??= member.user.name + } } catch { } try { selected ??= { user: await session.bot.getUser(target) }