2022-07-23 20:32:10 +00:00
|
|
|
|
// #老婆
|
|
|
|
|
import lodash from 'lodash'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
import { Common } from '#miao'
|
|
|
|
|
import { Character, MysApi, Player } from '#miao.models'
|
2023-02-13 19:47:22 +00:00
|
|
|
|
import Avatar from './AvatarCard.js'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
const relationMap = {
|
|
|
|
|
wife: {
|
2023-03-27 20:04:09 +00:00
|
|
|
|
keyword: '老婆,媳妇,妻子,娘子,宝贝'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 0
|
|
|
|
|
},
|
|
|
|
|
husband: {
|
2023-03-27 20:04:09 +00:00
|
|
|
|
keyword: '老公,丈夫,夫君,郎君,死鬼'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 1
|
|
|
|
|
},
|
|
|
|
|
gf: {
|
2023-03-27 20:04:09 +00:00
|
|
|
|
keyword: '女朋友,女友,女神,女王,女票'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 0
|
|
|
|
|
},
|
|
|
|
|
bf: {
|
2023-03-27 20:04:09 +00:00
|
|
|
|
keyword: '男朋友,男友,男神,男票'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 1
|
|
|
|
|
},
|
|
|
|
|
daughter: {
|
2023-03-27 20:04:09 +00:00
|
|
|
|
keyword: '女儿,闺女,小宝贝'.split(','),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
type: 2
|
|
|
|
|
},
|
|
|
|
|
son: {
|
2023-03-27 20:04:09 +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)
|
2023-02-13 19:47:22 +00:00
|
|
|
|
const wifeReg = `^#?\\s*(${relation.join('|')})\\s*(设置|选择|指定|列表|查询|列表|是|是谁|照片|相片|图片|写真|图像)?\\s*([^\\d]*)\\s*(\\d*)$`
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
async function getAvatarList (player, type) {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
await player.refreshMysDetail()
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let list = []
|
|
|
|
|
player.forEachAvatar((avatar) => {
|
|
|
|
|
if (type !== false) {
|
2023-02-17 20:42:05 +00:00
|
|
|
|
if (!avatar.char.checkWifeType(type)) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.push(avatar)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (list.length <= 0) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let sortKey = 'level,fetter,weapon_level,rarity,weapon_rarity,cons,weapon_affix_level'
|
|
|
|
|
list = lodash.orderBy(list, sortKey, lodash.repeat('desc,', sortKey.length).split(','))
|
|
|
|
|
return list
|
|
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
|
|
|
|
|
|
const Wife = {
|
|
|
|
|
reg: wifeReg,
|
|
|
|
|
async render (e) {
|
|
|
|
|
let msg = e.msg || ''
|
|
|
|
|
if (!msg && !e.isPoke) return false
|
|
|
|
|
|
|
|
|
|
if (e.isPoke) {
|
|
|
|
|
if (!Common.cfg('avatarPoke')) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-02-13 20:43:14 +00:00
|
|
|
|
} else if (!Common.cfg('avatarCard')) {
|
2023-02-13 19:47:22 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let msgRet = (new RegExp(wifeReg)).exec(msg)
|
|
|
|
|
if (e.isPoke) {
|
|
|
|
|
msgRet = []
|
|
|
|
|
} else if (!msgRet) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let target = msgRet[1]
|
|
|
|
|
let action = msgRet[2] || '卡片'
|
|
|
|
|
let actionParam = msgRet[3] || ''
|
|
|
|
|
|
|
|
|
|
if (!'设置,选择,挑选,指定'.split(',').includes(action) && actionParam) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let targetCfg = lodash.find(relationMap, (cfg, key) => {
|
|
|
|
|
cfg.key = key
|
|
|
|
|
return cfg.keyword.includes(target)
|
|
|
|
|
})
|
|
|
|
|
if (!targetCfg && !e.isPoke) return true
|
|
|
|
|
|
|
|
|
|
let avatarList = []
|
|
|
|
|
let avatar = {}
|
|
|
|
|
let wifeList = []
|
|
|
|
|
|
|
|
|
|
let mys = await MysApi.init(e)
|
|
|
|
|
if (!mys || !mys.uid) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let player = Player.create(e)
|
|
|
|
|
let selfUser = mys.selfUser
|
|
|
|
|
let isSelf = true
|
|
|
|
|
let renderType = (action === '卡片' ? 'card' : 'photo')
|
|
|
|
|
let addRet = []
|
|
|
|
|
switch (action) {
|
|
|
|
|
case '照片':
|
|
|
|
|
case '相片':
|
|
|
|
|
case '图片':
|
|
|
|
|
case '写真':
|
2024-02-04 01:27:34 +00:00
|
|
|
|
case '卡片':
|
2023-02-13 19:47:22 +00:00
|
|
|
|
// 展示老婆卡片
|
|
|
|
|
// 如果选择过,则进行展示
|
|
|
|
|
if (!e.isPoke) {
|
|
|
|
|
wifeList = await selfUser.getCfg(`wife.${targetCfg.key}`, [])
|
|
|
|
|
// 存在设置
|
|
|
|
|
if (wifeList && wifeList.length > 0 && isSelf && !e.isPoke) {
|
|
|
|
|
if (wifeList[0] === '随机') {
|
|
|
|
|
// 如果选择为全部,则从列表中随机选择一个
|
|
|
|
|
avatarList = await getAvatarList(player, targetCfg.type, mys)
|
|
|
|
|
let avatar = lodash.sample(avatarList)
|
|
|
|
|
return Avatar.renderAvatar(e, avatar, renderType)
|
|
|
|
|
} else {
|
|
|
|
|
// 如果指定过,则展示指定角色
|
|
|
|
|
return Avatar.renderAvatar(e, lodash.sample(wifeList), renderType)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果未指定过,则从列表中排序并随机选择
|
|
|
|
|
avatarList = await getAvatarList(player, e.isPoke ? false : targetCfg.type, mys)
|
|
|
|
|
if (avatarList && avatarList.length > 0) {
|
|
|
|
|
avatar = lodash.sample(avatarList)
|
|
|
|
|
return await Avatar.renderAvatar(e, avatar, renderType)
|
|
|
|
|
}
|
|
|
|
|
e.reply('在当前米游社公开展示的角色中未能找到适合展示的角色..')
|
|
|
|
|
return true
|
|
|
|
|
case '设置':
|
|
|
|
|
case '选择':
|
|
|
|
|
case '挑选':
|
|
|
|
|
case '指定':
|
|
|
|
|
if (!isSelf) {
|
|
|
|
|
e.reply('只能指定自己的哦~')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
// 选择老婆
|
|
|
|
|
actionParam = actionParam.replace(/(,|、|;|;)/g, ',')
|
|
|
|
|
wifeList = actionParam.split(',')
|
|
|
|
|
if (lodash.intersection(['全部', '任意', '随机', '全都要'], wifeList).length > 0) {
|
|
|
|
|
addRet = ['随机']
|
|
|
|
|
} else {
|
|
|
|
|
wifeList = lodash.map(wifeList, (name) => {
|
|
|
|
|
let char = Character.get(name)
|
|
|
|
|
if (char && char.checkWifeType(targetCfg.type)) {
|
|
|
|
|
return char.name
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
wifeList = lodash.filter(lodash.uniq(wifeList), (d) => !!d)
|
|
|
|
|
addRet = wifeList
|
|
|
|
|
if (addRet.length === 0) {
|
|
|
|
|
e.reply(`在可选的${targetCfg.keyword[0]}列表中未能找到 ${actionParam} ~`)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await selfUser.setCfg(`wife.${targetCfg.key}`, addRet)
|
|
|
|
|
e.reply(`${targetCfg.keyword[0]}已经设置:${addRet.join(',')}`)
|
|
|
|
|
return true
|
|
|
|
|
case '列表':
|
|
|
|
|
case '是':
|
|
|
|
|
case '是谁':
|
|
|
|
|
// 查看当前选择老婆
|
|
|
|
|
if (!isSelf) {
|
|
|
|
|
e.reply('只能查看自己的哦~')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
wifeList = await selfUser.getCfg(`wife.${targetCfg.key}`, [])
|
|
|
|
|
if (wifeList && wifeList.length > 0) {
|
|
|
|
|
e.reply(`你的${targetCfg.keyword[0]}是:${wifeList.join(',')}`)
|
|
|
|
|
} else {
|
|
|
|
|
e.reply(`尚未设置,回复#${targetCfg.keyword[0]}设置+角色名 来设置,如果设置多位请用逗号间隔`)
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
},
|
|
|
|
|
async poke (e) {
|
|
|
|
|
return await Wife.render(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Wife
|