Skip to content

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Aug 2, 2024
1 parent 3972ced commit d20678f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 18 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.6.0",
"version": "1.7.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

娶群友!来寻找你今日的群友老婆吧!

## 可选功能
## 可选的

### 特性
* 避免用户抽中他人的老婆
* 只让用户抽中活跃的群友
* 强娶

### 指令
* 强娶
* 求婚
97 changes: 84 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@ export interface Config {
onlyActiveUser: boolean
activeDays: number
forceMarry: boolean
propose: boolean
excludeUsers: {
uid: string
note?: string
}[]
}

export const Config: Schema<Config> = Schema.object({
avoidNtr: Schema.boolean().default(false),
onlyActiveUser: Schema.boolean().default(false),
activeDays: Schema.natural().default(7),
forceMarry: Schema.boolean().default(false),
excludeUsers: Schema.array(Schema.object({
uid: Schema.string().required(),
note: Schema.string()
})).role('table').default([{ uid: 'red:2854196310', note: 'Q群管家' }])
}).i18n({
'zh-CN': require('./locales/zh-CN'),
})
export const Config: Schema<Config> = Schema.intersect([
Schema.object({
avoidNtr: Schema.boolean().default(false),
onlyActiveUser: Schema.boolean().default(false),
activeDays: Schema.natural().default(7),
excludeUsers: Schema.array(Schema.object({
uid: Schema.string().required(),
note: Schema.string()
})).role('table').default([{ uid: 'red:2854196310', note: 'Q群管家' }])
}).i18n({
'zh-CN': require('./locales/zh-CN'),
}),
Schema.object({
forceMarry: Schema.boolean().description('是否启用强娶指令').default(false),
propose: Schema.boolean().description('是否启用求婚指令').experimental().default(false),
}).description('附加指令')
])

export function apply(ctx: Context, cfg: Config) {
ctx.i18n.define('zh-CN', require('./locales/zh-CN'))
Expand Down Expand Up @@ -165,7 +171,7 @@ export function apply(ctx: Context, cfg: Config) {
})
}

const targetId = target.replace(session.platform + ':', '')
const targetId = target.slice(session.platform.length + 1)
if (targetId === session.userId) return session.text('.target-self')
const { gid } = session

Expand Down Expand Up @@ -193,4 +199,69 @@ export function apply(ctx: Context, cfg: Config) {
})
})
}

if (cfg.propose) {
ctx.command('propose <target:user>')
.alias('求婚')
.action(async ({ session }, target) => {
if (!session.guildId) {
return session.text('.members-too-few')
}
if (!target) {
return session.text('.no-target', {
quote: h.quote(session.messageId)
})
}

const targetId = target.slice(session.platform.length + 1)
if (targetId === session.userId) return session.text('.target-self')
const { gid } = session

const marriage = await ctx.cache.get(`waifu_marriages_${gid}`, session.userId)
if (marriage) {
return session.text('.already-marriage', {
quote: h.quote(session.messageId)
})
}

const memberList = await getMemberList(session, gid)
const selected = memberList.find(u => u.user.id == targetId)
if (!selected) return session.text('.members-too-few')

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('')
}, { 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
})
} else if (reply === '我拒绝') {
return session.text('.failure', {
quote: h.quote(session.messageId)
})
}
})
}
}
13 changes: 11 additions & 2 deletions src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
avoidNtr: 是否避免用户抽中他人的老婆
onlyActiveUser: 是否只让用户抽中活跃的群友
activeDays: 活跃天数最小值 (onlyActiveUser 判断活跃的标准)
forceMarry: 是否启用强娶指令
excludeUsers:
$description: 排除的用户
$value:
Expand All @@ -21,4 +20,14 @@ commands:
no-target: '{quote}强娶谁呀~'
already-marriage: '{quote}你已经娶了老婆,今天别再娶啦!'
members-too-few: 能娶的群友没有这位,或许可以先把对方骗出来聊天?!
target-self: '{quote}娶自己干嘛!'
target-self: '{quote}娶自己干嘛!'
propose:
description: 向群友求婚
messages:
success: '{quote}群友「{name}」答应了你,愿意当你今日的对象!'
failure: '{quote}对方拒绝了'
no-target: '{quote}向谁求婚呀~'
already-marriage: '{quote}你已经有对象了,今天别再求婚啦!'
members-too-few: 能求婚的群友没有这位,或许可以先把对方骗出来聊天?!
target-self: '{quote}向自己求婚干嘛!'
request: '{targetAt} {targetAvatar}<br/>群友「{name}」向你求婚,那么...你愿意嫁给ta吗?在{time}内发送【{agree}】或者【{reject}】,回应对方哦!'

0 comments on commit d20678f

Please sign in to comment.