From 5535daa43a276fd893f3be48f2920810269e78e5 Mon Sep 17 00:00:00 2001 From: tsukishima1321 <18001751830@163.com> Date: Fri, 9 Aug 2024 09:23:19 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=9C=A8?= =?UTF-8?q?=E6=96=B0=E7=89=88satori=E9=80=82=E9=85=8D=E5=99=A8=E4=B8=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E7=BE=A4=E6=88=90=E5=91=98?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=81=E6=88=B3?= =?UTF-8?q?=E4=B8=80=E6=88=B3=E6=B6=88=E6=81=AF=E8=A2=AB=E8=A7=86=E4=B8=BA?= =?UTF-8?q?=E7=BE=A4=E6=88=90=E5=91=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 086fd77..2a184fd 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)) return - const member: Universal.GuildMember = session.event.member || { user: session.event.user } - await ctx.cache.set(`waifu_members_${session.gid}`, session.userId, member, 2 * Time.day) + if (isNullable(session.userId) || session.userId == "0") return + const member: Universal.GuildMember = { user: session.event.user,nick: session.event.member.nick } + 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)) 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,6 +81,26 @@ 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 }) => { @@ -88,15 +108,14 @@ export function apply(ctx: Context, cfg: Config) { return session.text('.members-too-few') } const { gid } = session - const target = await ctx.cache.get(`waifu_marriages_${gid}`, session.userId) if (target) { let selected: Universal.GuildMember try { - selected = await session.bot.getGuildMember(session.guildId, target) + selected = await ctx.cache.get(`waifu_members_${gid}`, target) } catch { } try { - selected ??= await ctx.cache.get(`waifu_members_${gid}`, target) + selected ??= await session.bot.getGuildMember(session.guildId, target) } catch { } try { selected ??= { user: await session.bot.getUser(target) } From b1a1d3aa016b3182c3f208be9daefaaeb8cc7b17 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:43:45 +0800 Subject: [PATCH 2/4] Update src/index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2a184fd..bbb53e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,7 +51,7 @@ 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,nick: session.event.member.nick } 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) From eca632a7464254423a3fcc5ad4f9856e4dea1a52 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:43:51 +0800 Subject: [PATCH 3/4] Update src/index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bbb53e4..5701978 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,7 +58,7 @@ export function apply(ctx: Context, cfg: Config) { }) 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) }) From 2014b37f12b0a186d5359b1e0489d62a1ff1bccf Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:43:59 +0800 Subject: [PATCH 4/4] Update src/index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5701978..8528e72 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,7 +52,7 @@ export function apply(ctx: Context, cfg: Config) { ctx.guild().on('message-created', async (session) => { if (isNullable(session.userId) || session.userId == '0') return - const member: Universal.GuildMember = { user: session.event.user,nick: session.event.member.nick } + 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) })