Skip to content

Commit

Permalink
1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Aug 12, 2024
1 parent ca61165 commit 8371cf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
35 changes: 11 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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 }) => {
Expand All @@ -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) }
Expand Down

0 comments on commit 8371cf3

Please sign in to comment.