miao-plugin/apps/character.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

import { Common, App } from '../components/index.js'
2022-09-16 20:37:09 +00:00
import { Character } from '../models/index.js'
2022-10-06 22:20:46 +00:00
import { renderAvatar } from './character/AvatarCard.js'
import { uploadCharacterImg } from './character/ImgUpload.js'
import { wife, wifeReg } from './character/AvatarWife.js'
import { getOriginalPicture } from './character/ProfileUtils.js'
2022-09-16 20:37:09 +00:00
let app = App.init({
id: 'character',
2022-09-16 22:01:31 +00:00
name: '角色查询'
2022-09-16 20:37:09 +00:00
})
2022-09-16 20:37:09 +00:00
app.reg('character', character, {
rule: /^#喵喵角色卡片$/,
check: checkCharacter,
name: '角色卡片'
2022-09-16 20:37:09 +00:00
})
app.reg('upload-img', uploadCharacterImg, {
rule: /^#*(喵喵)?(上传|添加)(.+)(照片|写真|图片|图像)\s*$/,
name: '上传角色写真'
})
app.reg('wife', wife, {
rule: wifeReg,
describe: '#老公 #老婆 查询'
})
app.reg('original-pic', getOriginalPicture, {
rule: /^#?(获取|给我|我要|求|发|发下|发个|发一下)?原图(吧|呗)?$/,
describe: '【#原图】 回复角色卡片,可获取原图'
})
export default app
2022-08-06 22:36:05 +00:00
2022-03-26 21:34:33 +00:00
// 查看当前角色
export async function character (e) {
if (!e.char) {
return false
}
return renderAvatar(e, e.char?.name)
}
function checkCharacter (e) {
let msg = e.original_msg || e.msg
if (!msg || !/^#/.exec(msg)) {
return false
}
2022-04-09 21:33:21 +00:00
2022-07-23 20:32:10 +00:00
let uidRet = /[0-9]{9}/.exec(msg)
if (uidRet) {
2022-07-23 20:32:10 +00:00
e.uid = uidRet[0]
msg = msg.replace(uidRet[0], '')
}
let name = msg.replace(/#|老婆|老公|卡片/g, '').trim()
if (Common.isDisable(e, 'char.char')) {
return false
}
2022-07-23 20:32:10 +00:00
let char = Character.get(name.trim())
2022-03-26 21:34:33 +00:00
if (!char) {
2022-07-23 20:32:10 +00:00
return false
2022-03-26 21:34:33 +00:00
}
e.msg = '#喵喵角色卡片'
e.char = char
return true
}