From d20678fbc8ba77d259a0c0b352019c4a47fb63ee Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 3 Aug 2024 03:26:22 +0800 Subject: [PATCH] 1.7.0 --- package.json | 2 +- readme.md | 8 +++- src/index.ts | 97 +++++++++++++++++++++++++++++++++++++------ src/locales/zh-CN.yml | 13 +++++- 4 files changed, 102 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 719a312..818e47d 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/readme.md b/readme.md index 8f46a6e..ca910af 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,12 @@ 娶群友!来寻找你今日的群友老婆吧! -## 可选功能 +## 可选的 +### 特性 * 避免用户抽中他人的老婆 * 只让用户抽中活跃的群友 -* 强娶 \ No newline at end of file + +### 指令 +* 强娶 +* 求婚 \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index a53cf30..5acf660 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,24 +18,30 @@ export interface Config { onlyActiveUser: boolean activeDays: number forceMarry: boolean + propose: boolean excludeUsers: { uid: string note?: string }[] } -export const Config: Schema = 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 = 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')) @@ -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 @@ -193,4 +199,69 @@ export function apply(ctx: Context, cfg: Config) { }) }) } + + if (cfg.propose) { + ctx.command('propose ') + .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) + }) + } + }) + } } \ No newline at end of file diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml index 75d3830..867c00b 100644 --- a/src/locales/zh-CN.yml +++ b/src/locales/zh-CN.yml @@ -1,7 +1,6 @@ avoidNtr: 是否避免用户抽中他人的老婆 onlyActiveUser: 是否只让用户抽中活跃的群友 activeDays: 活跃天数最小值 (onlyActiveUser 判断活跃的标准) -forceMarry: 是否启用强娶指令 excludeUsers: $description: 排除的用户 $value: @@ -21,4 +20,14 @@ commands: no-target: '{quote}强娶谁呀~' already-marriage: '{quote}你已经娶了老婆,今天别再娶啦!' members-too-few: 能娶的群友没有这位,或许可以先把对方骗出来聊天?! - target-self: '{quote}娶自己干嘛!' \ No newline at end of file + 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}
群友「{name}」向你求婚,那么...你愿意嫁给ta吗?在{time}内发送【{agree}】或者【{reject}】,回应对方哦!' \ No newline at end of file