Skip to content

Commit

Permalink
1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Sep 9, 2024
1 parent bbc93bb commit 79e6f21
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 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.3",
"version": "1.8.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
73 changes: 44 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,37 +239,52 @@ export function apply(ctx: Context, cfg: Config) {
const selectedId = selected.user.id
const [name, avatar] = getMemberInfo(selected, selectedId)

await session.send(session.text('.request', {
targetAt: h.at(selected.user.id),
targetAvatar: h.image(avatar),
name: session.username,
agree: '我愿意',
reject: '我拒绝',
time: '90'
}))

const targetSession = session.bot.session({
...session.event,
member: selected,
user: selected.user
})
const reply = await targetSession.prompt(session => {
return h.select(session.elements, 'text').join('').trim()
}, { timeout: 90 * Time.second })

if (reply === '我愿意') {
const maxAge = getMaxAge()
await ctx.cache.set(`waifu_marriages_${gid}`, session.userId, selectedId, maxAge)
await ctx.cache.set(`waifu_marriages_${gid}`, selectedId, session.userId, maxAge)
return session.text('.success', {
quote: h.quote(session.messageId),
name
await session.send(
session.text('.request', {
targetAt: h.at(selected.user.id),
targetAvatar: h.image(avatar),
name: session.username,
agree: '我愿意',
reject: '我拒绝',
time: '90'
})
} else if (reply === '我拒绝') {
return session.text('.failure', {
quote: h.quote(session.messageId)
)

let timeoutId: NodeJS.Timeout
const sourceMessageId = session.messageId
const sourceUserId = session.userId

const dispose = ctx.platform(session.platform)
.user(selected.user.id)
.guild(session.guildId)
.on('message-created', async ({ elements, text, send }) => {
const reply = h.select(elements, 'text').join('').trim()
if (reply === '我愿意') {
dispose()
clearTimeout(timeoutId)
const maxAge = getMaxAge()
await ctx.cache.set(`waifu_marriages_${gid}`, sourceUserId, selectedId, maxAge)
await ctx.cache.set(`waifu_marriages_${gid}`, selectedId, sourceUserId, maxAge)
await send(
text('commands.propose.messages.success', {
quote: h.quote(sourceMessageId),
name
})
)
} else if (reply === '我拒绝') {
dispose()
clearTimeout(timeoutId)
await send(
text('commands.propose.messages.failure', {
quote: h.quote(sourceMessageId)
})
)
}
})
}

timeoutId = setTimeout(() => {
dispose()
}, 90 * Time.second)
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ commands:
description: 和群友离婚
messages:
not-married: '{quote}你还是只单身狗,不能离婚!'
divorcement: '{quote}你已经离婚, 江湖有缘再相见~'
divorcement: '{quote}你已经离婚江湖有缘再相见~'

0 comments on commit 79e6f21

Please sign in to comment.