mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 05:37:46 +00:00
Merge pull request #7 from ZZZure/guide-multiple-sources
给攻略加入多个源,并优化添加与选择策略
This commit is contained in:
commit
e7af2ba1bd
1 changed files with 36 additions and 14 deletions
|
|
@ -8,8 +8,6 @@ import fetch from 'node-fetch'
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
|
|
||||||
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides')
|
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides')
|
||||||
// 最大攻略数量
|
|
||||||
const maxNum = 2
|
|
||||||
|
|
||||||
export class Guide extends ZZZPlugin {
|
export class Guide extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -20,7 +18,7 @@ export class Guide extends ZZZPlugin {
|
||||||
priority: 100,
|
priority: 100,
|
||||||
rule: [
|
rule: [
|
||||||
{
|
{
|
||||||
reg: `${rulePrefix}(更新)?\\S+攻略([0-${maxNum}])?$`,
|
reg: `${rulePrefix}(更新)?\\S+攻略(\\d+)?$`,
|
||||||
fnc: 'Guide',
|
fnc: 'Guide',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -31,16 +29,24 @@ export class Guide extends ZZZPlugin {
|
||||||
[],
|
[],
|
||||||
// 来源:新艾利都快讯
|
// 来源:新艾利都快讯
|
||||||
[2712859],
|
[2712859],
|
||||||
[2727116]
|
[2727116],
|
||||||
|
[2721968],
|
||||||
|
[2724610],
|
||||||
|
[2722266]
|
||||||
]
|
]
|
||||||
this.source = [
|
this.source = [
|
||||||
'新艾利都快讯',
|
'新艾利都快讯',
|
||||||
'清茶沐沐Kiyotya'
|
'清茶沐沐Kiyotya',
|
||||||
|
'小橙子阿',
|
||||||
|
'猫冬',
|
||||||
|
'月光中心'
|
||||||
]
|
]
|
||||||
|
// 最大攻略数量
|
||||||
|
this.maxNum = this.source.length
|
||||||
}
|
}
|
||||||
|
|
||||||
async init () {
|
async init () {
|
||||||
for (let group = 1; group <= maxNum; group++) {
|
for (let group = 1; group <= this.maxNum; group++) {
|
||||||
let guideFolder = this.getGuideFolder(group)
|
let guideFolder = this.getGuideFolder(group)
|
||||||
if (!fs.existsSync(guideFolder)) {
|
if (!fs.existsSync(guideFolder)) {
|
||||||
fs.mkdirSync(guideFolder, { recursive: true })
|
fs.mkdirSync(guideFolder, { recursive: true })
|
||||||
|
|
@ -59,12 +65,23 @@ export class Guide extends ZZZPlugin {
|
||||||
return guidePath
|
return guidePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canGetImageFromFile(guidePath, isUpdate) {
|
||||||
|
return (
|
||||||
|
fs.existsSync(guidePath) &&
|
||||||
|
!isUpdate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async Guide() {
|
async Guide() {
|
||||||
logger.warn('123')
|
let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略(\\d+)?$`)
|
||||||
let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略([0-${maxNum}])?$`)
|
|
||||||
let [,,,, isUpdate, name,
|
let [,,,, isUpdate, name,
|
||||||
group = 1 // setting.getConfig('mys')?.defaultSource
|
group = '1' // setting.getConfig('mys')?.defaultSource
|
||||||
] = this.e.msg.match(reg)
|
] = this.e.msg.match(reg)
|
||||||
|
group = +group
|
||||||
|
if (group > this.maxNum) {
|
||||||
|
await this.reply(`超过攻略数量(${this.maxNum})`)
|
||||||
|
return
|
||||||
|
}
|
||||||
let id = atlasToName(name)
|
let id = atlasToName(name)
|
||||||
if (!id) {
|
if (!id) {
|
||||||
await this.reply('该角色不存在')
|
await this.reply('该角色不存在')
|
||||||
|
|
@ -75,9 +92,9 @@ export class Guide extends ZZZPlugin {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
let msg = []
|
let msg = []
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
for (let i = 1; i <= maxNum; i++) {
|
for (let i = 1; i <= this.maxNum; i++) {
|
||||||
let guildePath = this.getGuidePath(i, name)
|
let guidePath = this.getGuidePath(i, name)
|
||||||
if (fs.existsSync(this.sfPath) && !isUpdate) {
|
if (this.canGetImageFromFile(guidePath, isUpdate)) {
|
||||||
msg.push(segment.image(`file://${guidePath}`))
|
msg.push(segment.image(`file://${guidePath}`))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +107,7 @@ export class Guide extends ZZZPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
let guidePath = this.getGuidePath(group, name)
|
let guidePath = this.getGuidePath(group, name)
|
||||||
if (fs.existsSync(guidePath)) {
|
if (this.canGetImageFromFile(guidePath, isUpdate)) {
|
||||||
await this.e.reply(segment.image(`file://${guidePath}`))
|
await this.e.reply(segment.image(`file://${guidePath}`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +136,12 @@ export class Guide extends ZZZPlugin {
|
||||||
if (val.post.subject.includes(name)) {
|
if (val.post.subject.includes(name)) {
|
||||||
let max = 0
|
let max = 0
|
||||||
val.image_list.forEach((v, i) => {
|
val.image_list.forEach((v, i) => {
|
||||||
if (Number(v.size) >= Number(val.image_list[max].size)) max = i
|
if (
|
||||||
|
Number(v.size) >= Number(val.image_list[max].size) &&
|
||||||
|
v.format != 'gif' // 动图天生 size 会撑得很大
|
||||||
|
) {
|
||||||
|
max = i
|
||||||
|
}
|
||||||
})
|
})
|
||||||
url = val.image_list[max].url
|
url = val.image_list[max].url
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue