Skip to content

Commit

Permalink
Merge pull request #8 from tsukishima1321/main
Browse files Browse the repository at this point in the history
修复了在新版satori适配器下获取不到群成员信息的问题、戳一戳消息被视为群成员的问题
  • Loading branch information
idranme authored Aug 10, 2024
2 parents 849ce4c + 2014b37 commit ca61165
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 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)) 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, ...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)) 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,22 +81,41 @@ 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 }) => {
if (!session.guildId) {
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) }
Expand Down

0 comments on commit ca61165

Please sign in to comment.