优化推送

Signed-off-by: 帮帮 <3102509561@qq.com>
This commit is contained in:
帮帮 2023-07-30 05:29:47 +00:00 committed by Gitee
parent cd5ec16c3a
commit 6c25052829
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 21 additions and 37 deletions

View File

@ -45,11 +45,11 @@ export default class MysNews extends base {
const img = await this.render(param) const img = await this.render(param)
let game = this.game() let game = this.game()
return await this.replyMsg(img, `${game}${typeName}${param.data.post.subject}`) return this.replyMsg(img, `${game}${typeName}${param.data.post.subject}`)
} }
async render(param) { render(param) {
return await puppeteer.screenshots(this.model, param) return puppeteer.screenshots(this.model, param)
} }
async newsDetail(postId, gid) { async newsDetail(postId, gid) {
@ -210,7 +210,7 @@ export default class MysNews extends base {
const img = await this.render(param) const img = await this.render(param)
return await this.replyMsg(img, `${param.data.post.subject}`) return this.replyMsg(img, `${param.data.post.subject}`)
} }
async mysUrl() { async mysUrl() {
@ -223,7 +223,7 @@ export default class MysNews extends base {
const img = await this.render(param) const img = await this.render(param)
return await this.replyMsg(img, `${param.data.post.subject}`) return this.replyMsg(img, `${param.data.post.subject}`)
} }
async ysEstimate() { async ysEstimate() {
@ -254,15 +254,16 @@ export default class MysNews extends base {
img.push(segment.image(param.data.post.images[0] + '?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg')) img.push(segment.image(param.data.post.images[0] + '?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg'))
} }
return await this.replyMsg(img, `${param.data.post.subject}`) return this.replyMsg(img, `${param.data.post.subject}`)
} }
async replyMsg(img, title = '') { replyMsg(img, title = '') {
if (!img || img.length <= 0) return false if (!img || img.length <= 0) return false
if (img.length == 1) { if (img.length == 1) {
return img[0] if (title) img.unshift(title)
return img
} else { } else {
return await common.makeForwardMsg(this.e, img, title) return common.makeForwardMsg(this.e, img, title)
} }
} }
@ -297,29 +298,21 @@ export default class MysNews extends base {
this.e.isGroup = true this.e.isGroup = true
this.pushGroup = [] this.pushGroup = []
for (let val of news) { for (let val of news) {
if (Number(now - val.post.created_at) > interval) { if (Number(now - val.post.created_at) > interval)
continue continue
} if (cfg.banWord[type] && new RegExp(cfg.banWord[type]).test(val.post.subject))
if (cfg.banWord[type] && new RegExp(cfg.banWord[type]).test(val.post.subject)) {
continue continue
} if (val.typeName == '公告')
if (val.typeName == '公告') { for (let botId in cfg[`${type}announceGroup`])
for (let botId in cfg[`${type}announceGroup`]) { for (let groupId of cfg[`${type}announceGroup`][botId])
for (let groupId of cfg[`${type}announceGroup`][botId]) {
await this.sendNews(botId, groupId, val.typeName, val.post.post_id, gid) await this.sendNews(botId, groupId, val.typeName, val.post.post_id, gid)
} if (val.typeName == '资讯')
} for (let botId in cfg[`${type}infoGroup`])
} for (let groupId of cfg[`${type}infoGroup`][botId])
if (val.typeName == '资讯') {
for (let botId in cfg[`${type}infoGroup`]) {
for (let groupId of cfg[`${type}infoGroup`][botId]) {
await this.sendNews(botId, groupId, val.typeName, val.post.post_id, gid) await this.sendNews(botId, groupId, val.typeName, val.post.post_id, gid)
} }
} }
} }
}
}
}
async sendNews(botId, groupId, typeName, postId, gid) { async sendNews(botId, groupId, typeName, postId, gid) {
if (!this.pushGroup[groupId]) this.pushGroup[groupId] = 0 if (!this.pushGroup[groupId]) this.pushGroup[groupId] = 0
@ -348,20 +341,11 @@ export default class MysNews extends base {
} }
this.pushGroup[groupId]++ this.pushGroup[groupId]++
this.e.group_id = groupId
let tmp = await this.replyMsg(this[postId].img, `${game}${typeName}推送:${this[postId].title}`)
await common.sleep(1000)
if (!tmp) return
if (tmp?.type != 'xml') {
tmp = [`${game}${typeName}推送\n`, tmp]
}
await redis.set(`${this.key}${botId}:${groupId}:${postId}`, '1', { EX: 3600 * 10 }) await redis.set(`${this.key}${botId}:${groupId}:${postId}`, '1', { EX: 3600 * 10 })
// 随机延迟10-90秒 // 随机延迟10-90秒
await common.sleep(lodash.random(10, 90) * 1000) await common.sleep(lodash.random(10000, 90000))
await this.e.group.sendMsg(tmp) const msg = await this.replyMsg(this[postId].img, `${game}${typeName}推送:${this[postId].title}`)
return this.e.group.sendMsg(msg)
} }
game(gid) { game(gid) {