2022-07-23 20:32:10 +00:00
|
|
|
|
// #老婆
|
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import { Cfg } from '../../components/index.js'
|
2022-09-20 11:50:27 +00:00
|
|
|
|
import { Character, MysApi } from '../../models/index.js'
|
2022-07-23 20:32:10 +00:00
|
|
|
|
import { getAvatarList, renderAvatar } from './avatar-card.js'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
const relationMap = {
|
|
|
|
|
wife: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '老婆,媳妇,妻子,娘子'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 0
|
|
|
|
|
},
|
|
|
|
|
husband: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '老公,丈夫,夫君,郎君'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 1
|
|
|
|
|
},
|
|
|
|
|
gf: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '女朋友,女友,女神'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 0
|
|
|
|
|
},
|
|
|
|
|
bf: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '男朋友,男友,男神'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 1
|
|
|
|
|
},
|
|
|
|
|
daughter: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '女儿'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 2
|
|
|
|
|
},
|
|
|
|
|
son: {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
keyword: '儿子'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 3
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
const relation = lodash.flatMap(relationMap, (d) => d.keyword)
|
|
|
|
|
export const wifeReg = `^#?\\s*(${relation.join('|')})\\s*(设置|选择|指定|列表|查询|列表|是|是谁|照片|相片|图片|写真|图像)?\\s*([^\\d]*)\\s*(\\d*)$`
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-09-17 12:46:39 +00:00
|
|
|
|
export async function wife (e) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let msg = e.msg || ''
|
|
|
|
|
if (!msg && !e.isPoke) return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-06 22:12:05 +00:00
|
|
|
|
if (e.isPoke) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (Cfg.isDisable(e, 'char.poke')) {
|
|
|
|
|
return false
|
2022-07-06 22:12:05 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
} else if (Cfg.isDisable(e, 'char.wife')) {
|
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let msgRet = (new RegExp(wifeReg)).exec(msg)
|
2022-07-06 22:12:05 +00:00
|
|
|
|
if (e.isPoke) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
msgRet = []
|
2022-07-06 22:12:05 +00:00
|
|
|
|
} else if (!msgRet) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-07-06 22:12:05 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let target = msgRet[1]
|
|
|
|
|
let action = msgRet[2] || '卡片'
|
|
|
|
|
let actionParam = msgRet[3] || ''
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (!'设置,选择,挑选,指定'.split(',').includes(action) && actionParam) {
|
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let targetCfg = lodash.find(relationMap, (cfg, key) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
cfg.key = key
|
|
|
|
|
return cfg.keyword.includes(target)
|
|
|
|
|
})
|
|
|
|
|
if (!targetCfg && !e.isPoke) return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-30 21:06:00 +00:00
|
|
|
|
let avatarList = []
|
|
|
|
|
let avatar = {}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let wifeList = []
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-09-20 11:50:27 +00:00
|
|
|
|
let mys = await MysApi.init(e)
|
|
|
|
|
if (!mys || !mys.uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-09-20 11:50:27 +00:00
|
|
|
|
let selfUser = mys.selfUser
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let isSelf = true
|
2022-09-17 20:40:15 +00:00
|
|
|
|
let renderType = (action === '卡片' ? 'card' : 'photo')
|
|
|
|
|
let addRet = []
|
2022-06-25 23:45:43 +00:00
|
|
|
|
switch (action) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
case '卡片':
|
|
|
|
|
case '照片':
|
|
|
|
|
case '相片':
|
|
|
|
|
case '图片':
|
|
|
|
|
case '写真':
|
2022-06-25 23:45:43 +00:00
|
|
|
|
// 展示老婆卡片
|
|
|
|
|
// 如果选择过,则进行展示
|
2022-07-06 22:12:05 +00:00
|
|
|
|
if (!e.isPoke) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
wifeList = await selfUser.getCfg(`wife.${targetCfg.key}`, [])
|
2022-07-06 22:12:05 +00:00
|
|
|
|
// 存在设置
|
|
|
|
|
if (wifeList && wifeList.length > 0 && isSelf && !e.isPoke) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (wifeList[0] === '随机') {
|
2022-07-06 22:12:05 +00:00
|
|
|
|
// 如果选择为全部,则从列表中随机选择一个
|
2022-09-20 11:50:27 +00:00
|
|
|
|
avatarList = await getAvatarList(e, targetCfg.type, mys)
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let avatar = lodash.sample(avatarList)
|
2022-08-24 01:07:06 +00:00
|
|
|
|
return renderAvatar(e, avatar, renderType)
|
2022-07-06 22:12:05 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 如果指定过,则展示指定角色
|
2022-08-24 01:07:06 +00:00
|
|
|
|
return renderAvatar(e, lodash.sample(wifeList), renderType)
|
2022-07-06 22:12:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果未指定过,则从列表中排序并随机选择前5个
|
|
|
|
|
if (e.isPoke) {
|
2022-09-20 11:50:27 +00:00
|
|
|
|
avatarList = await getAvatarList(e, false, mys)
|
2022-07-06 22:12:05 +00:00
|
|
|
|
if (avatarList && avatarList.length > 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
avatar = lodash.sample(avatarList)
|
2022-08-24 01:07:06 +00:00
|
|
|
|
return await renderAvatar(e, avatar, renderType)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-20 11:50:27 +00:00
|
|
|
|
avatarList = await getAvatarList(e, targetCfg.type, mys)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (avatarList && avatarList.length > 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
avatar = lodash.sample(avatarList.slice(0, 5))
|
2022-08-24 01:07:06 +00:00
|
|
|
|
return await renderAvatar(e, avatar, renderType)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('在当前米游社公开展示的角色中未能找到适合展示的角色..')
|
|
|
|
|
return true
|
|
|
|
|
case '设置':
|
|
|
|
|
case '选择':
|
|
|
|
|
case '挑选':
|
|
|
|
|
case '指定':
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!isSelf) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('只能指定自己的哦~')
|
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
// 选择老婆
|
2022-07-23 20:32:10 +00:00
|
|
|
|
actionParam = actionParam.replace(/(,|、|;|;)/g, ',')
|
|
|
|
|
wifeList = actionParam.split(',')
|
|
|
|
|
if (lodash.intersection(['全部', '任意', '随机', '全都要'], wifeList).length > 0) {
|
|
|
|
|
addRet = ['随机']
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
wifeList = lodash.map(wifeList, (name) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let char = Character.get(name)
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (char && char.checkWifeType(targetCfg.type)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return char.name
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
})
|
|
|
|
|
wifeList = lodash.filter(lodash.uniq(wifeList), (d) => !!d)
|
|
|
|
|
addRet = wifeList
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (addRet.length === 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`在可选的${targetCfg.keyword[0]}列表中未能找到 ${actionParam} ~`)
|
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
await selfUser.setCfg(`wife.${targetCfg.key}`, addRet)
|
|
|
|
|
e.reply(`${targetCfg.keyword[0]}已经设置:${addRet.join(',')}`)
|
|
|
|
|
return true
|
|
|
|
|
case '列表':
|
|
|
|
|
case '是':
|
|
|
|
|
case '是谁':
|
2022-06-25 23:45:43 +00:00
|
|
|
|
// 查看当前选择老婆
|
|
|
|
|
if (!isSelf) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('只能查看自己的哦~')
|
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
wifeList = await selfUser.getCfg(`wife.${targetCfg.key}`, [])
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (wifeList && wifeList.length > 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`你的${targetCfg.keyword[0]}是:${wifeList.join(',')}`)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
e.reply(`尚未设置,回复#${targetCfg.keyword[0]}设置+角色名 来设置,如果设置多位请用逗号间隔`)
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
break
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-07-06 22:12:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function pokeWife (e, components) {
|
|
|
|
|
return await wife(e, components)
|
|
|
|
|
}
|