miao-plugin/apps/wiki.js

92 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-07-23 20:32:10 +00:00
import { segment } from 'oicq'
import lodash from 'lodash'
2022-08-18 10:13:42 +00:00
import Calendar from './wiki/calendar.js'
import { Cfg, Common } from '../components/index.js'
import { Character } from '../models/index.js'
2022-07-23 20:32:10 +00:00
// eslint-disable-next-line no-unused-vars
let action = {
wiki: {
2022-07-23 20:32:10 +00:00
keyword: '命座|天赋|技能|资料|照片|写真|图片|插画'
}
}
2022-04-03 22:06:03 +00:00
export async function wiki (e) {
if (!e.msg) {
2022-07-23 20:32:10 +00:00
return false
2022-04-03 22:06:03 +00:00
}
2022-08-18 10:13:42 +00:00
let reg = /#?(.+)(命座|命之座|天赋|技能|资料|照片|写真|图片|图像)$/;
let msg = e.msg
2022-07-23 20:32:10 +00:00
let ret = reg.exec(msg)
2022-04-08 21:52:05 +00:00
if (!ret || !ret[1] || !ret[2]) {
2022-07-23 20:32:10 +00:00
return false
}
2022-04-03 22:06:03 +00:00
2022-07-23 20:32:10 +00:00
let mode = 'talent'
2022-04-07 19:39:43 +00:00
if (/命/.test(ret[2])) {
2022-07-23 20:32:10 +00:00
mode = 'cons'
2022-04-08 21:52:05 +00:00
} else if (/图|画|写真|照片/.test(ret[2])) {
2022-07-23 20:32:10 +00:00
mode = 'pic'
2022-04-07 19:39:43 +00:00
}
2022-04-03 22:06:03 +00:00
2022-07-23 20:32:10 +00:00
if ((mode === 'pic' && Common.isDisable(e, 'wiki.pic')) ||
(mode !== 'pic' && Common.isDisable('wiki.wiki'))) {
return
2022-04-09 21:33:21 +00:00
}
2022-07-23 20:32:10 +00:00
let char = Character.get(ret[1])
2022-04-11 20:26:28 +00:00
if (!char) {
2022-07-23 20:32:10 +00:00
return false
2022-04-11 20:26:28 +00:00
}
2022-04-08 21:52:05 +00:00
2022-07-23 20:32:10 +00:00
if (mode === 'pic') {
let img = char.getCardImg(Cfg.get('char.se', false), false)
2022-04-08 21:52:05 +00:00
if (img && img.img) {
2022-07-23 20:32:10 +00:00
e.reply(segment.image(process.cwd() + '/plugins/miao-plugin/resources/' + img.img))
2022-04-08 21:52:05 +00:00
} else {
2022-07-23 20:32:10 +00:00
e.reply('暂无图片')
2022-04-08 21:52:05 +00:00
}
2022-07-23 20:32:10 +00:00
return true
2022-04-08 21:52:05 +00:00
}
if (char.isCustom) {
2022-07-23 20:32:10 +00:00
e.reply('暂不支持自定义角色')
return true
}
2022-07-23 20:32:10 +00:00
return await Common.render('wiki/character', {
save_id: '天赋' + char.name,
...char,
2022-04-07 19:39:43 +00:00
mode,
line: getLineData(char),
2022-07-23 20:32:10 +00:00
_char: `/meta/character/${char.name}/`
}, { e, scale: 1 })
2022-04-03 22:06:03 +00:00
}
const getLineData = function (data) {
2022-07-23 20:32:10 +00:00
let ret = []
lodash.forEach(data.lvStat.detail['90'], (num, idx) => {
ret.push({
2022-04-07 21:47:05 +00:00
num,
label: data.lvStat.stat[idx]
})
})
2022-04-03 22:06:03 +00:00
2022-07-23 20:32:10 +00:00
return ret
2022-04-03 22:06:03 +00:00
}
export async function calendar (e) {
2022-07-23 20:32:10 +00:00
let calData = await Calendar.get()
let mode = 'calendar'
if (/(日历列表|活动)$/.test(e.msg)) {
2022-07-23 20:32:10 +00:00
mode = 'list'
}
2022-07-23 20:32:10 +00:00
return await Common.render('wiki/calendar', {
...calData,
2022-07-23 20:32:10 +00:00
displayMode: mode
}, { e, scale: 1.1 })
2022-07-23 20:32:10 +00:00
}