mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: 修复各种小问题
This commit is contained in:
parent
22415c7546
commit
46a1e209b7
@ -79,7 +79,7 @@ export class mystery extends plugin {
|
|||||||
result = await oldReply(msgs, quote, data)
|
result = await oldReply(msgs, quote, data)
|
||||||
} else {
|
} else {
|
||||||
let MsgList = [ {
|
let MsgList = [ {
|
||||||
message: msgs, nickname: Bot.nickname, user_id: Bot.uin
|
message: msgs, nickname: Bot.nickname, user_id: Bot.user_id
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
let forwardMsg = await Bot.makeForwardMsg(MsgList)
|
let forwardMsg = await Bot.makeForwardMsg(MsgList)
|
||||||
@ -113,25 +113,20 @@ export class mystery extends plugin {
|
|||||||
// 回复
|
// 回复
|
||||||
this.reply('确实是吧, 正在探索...')
|
this.reply('确实是吧, 正在探索...')
|
||||||
// 请求
|
// 请求
|
||||||
let images = []
|
|
||||||
let imgData = []
|
|
||||||
let url = `https://www.cos6.net/wp-json/wp/v2/posts?page=${ page }`
|
let url = `https://www.cos6.net/wp-json/wp/v2/posts?page=${ page }`
|
||||||
|
let images = []
|
||||||
await fetch(url)
|
await fetch(url)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
return resp.json()
|
return resp.json()
|
||||||
})
|
})
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (!json.length) {
|
const template = {
|
||||||
this.e.reply('探索失败,你再我去一次吧')
|
nickname: this.e.sender.card || this.e.user_id,
|
||||||
return false
|
user_id: this.e.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = json[randomIndex].content
|
const content = json[randomIndex].content
|
||||||
images = this.getImages(content.rendered)
|
images = this.getCos6Img(content.rendered)
|
||||||
// 如果图片为空直接返回
|
|
||||||
if (images.length === 0) {
|
|
||||||
this.e.reply('探索失败,你再我去一次吧')
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// 洗牌
|
// 洗牌
|
||||||
images = _.shuffle(images)
|
images = _.shuffle(images)
|
||||||
// 限制长度
|
// 限制长度
|
||||||
@ -139,16 +134,19 @@ export class mystery extends plugin {
|
|||||||
images = images.slice(1, imageCountLimit + 1)
|
images = images.slice(1, imageCountLimit + 1)
|
||||||
}
|
}
|
||||||
// 循环队列
|
// 循环队列
|
||||||
images.forEach((item) => {
|
for (let i = 0; i < images.length; i++) {
|
||||||
imgData.push({
|
images[i] = {
|
||||||
message: segment.image(item),
|
message: segment.image(images[i]),
|
||||||
nickname: this.e.sender.card || this.e.user_id,
|
...template
|
||||||
user_id: this.e.user_id
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.e.reply('探索失败,你再我去一次吧')
|
||||||
|
logger.error(err)
|
||||||
|
return false
|
||||||
})
|
})
|
||||||
})
|
return !!(await this.reply(await Bot.makeForwardMsg(images)))
|
||||||
.catch((err) => logger.error(err))
|
|
||||||
return !!(await this.reply(await Bot.makeForwardMsg(imgData)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async cospro (e) {
|
async cospro (e) {
|
||||||
@ -187,15 +185,14 @@ export class mystery extends plugin {
|
|||||||
})
|
})
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (!json.length) {
|
if (!json.length) {
|
||||||
this.e.reply('探索失败,你再我去一次吧')
|
e.reply('探索失败,你再我去一次吧')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const content = json[randomIndex].content
|
const content = json[randomIndex].content
|
||||||
images = this.getImages2(content.rendered)
|
images = this.getImages2(content.rendered)
|
||||||
console.log(images)
|
|
||||||
// 如果图片为空直接返回
|
// 如果图片为空直接返回
|
||||||
if (images.length === 0) {
|
if (images.length === 0) {
|
||||||
this.e.reply('探索失败,你再我去一次吧')
|
e.reply('探索失败,你再我去一次吧')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 洗牌
|
// 洗牌
|
||||||
@ -208,8 +205,8 @@ export class mystery extends plugin {
|
|||||||
images.forEach((item) => {
|
images.forEach((item) => {
|
||||||
imgData.push({
|
imgData.push({
|
||||||
message: segment.image(item),
|
message: segment.image(item),
|
||||||
nickname: this.e.sender.card || this.e.user_id,
|
nickname: e.sender.card || e.user_id,
|
||||||
user_id: this.e.user_id
|
user_id: e.user_id
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -256,12 +253,12 @@ export class mystery extends plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 正则:获取图片
|
// 正则:获取图片
|
||||||
getImages (string) {
|
getCos6Img (string) {
|
||||||
const imgRex = /(http|https):\/\/([\w.]+\/?)\S*.(jpg|JPG|png|PNG|gif|GIF|jpeg|JPEG)/g
|
const imgRex = /\/([\w].*?).(jpg|JPG|png|PNG|gif|GIF|jpeg|JPEG|svg)/g
|
||||||
const images = []
|
const images = []
|
||||||
let img
|
let img
|
||||||
while ((img = imgRex.exec(string))) {
|
while ((img = imgRex.exec(string))) {
|
||||||
images.push(encodeURI(img[0]))
|
images.push(`https://www.cos6.net/${img[1]}.jpg`)
|
||||||
}
|
}
|
||||||
return images
|
return images
|
||||||
}
|
}
|
||||||
@ -272,7 +269,7 @@ export class mystery extends plugin {
|
|||||||
const images = []
|
const images = []
|
||||||
let img
|
let img
|
||||||
while ((img = imgRex.exec(string))) {
|
while ((img = imgRex.exec(string))) {
|
||||||
images.push(encodeURI(img[1]))
|
images.push(img[1])
|
||||||
}
|
}
|
||||||
return images
|
return images
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import axios from "axios";
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { mkdirsSync } from '../utils/file.js'
|
import { mkdirsSync } from '../utils/file.js'
|
||||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4 } from '../utils/bilibili.js'
|
import { downloadBFile, getDownloadUrl, mergeFileToMp4 } from '../utils/bilibili.js'
|
||||||
|
import { get, remove, add} from "../utils/redisu.js";
|
||||||
|
|
||||||
export class tools extends plugin {
|
export class tools extends plugin {
|
||||||
constructor () {
|
constructor () {
|
||||||
@ -39,7 +40,10 @@ export class tools extends plugin {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
// 视频保存路径
|
||||||
this.defaultPath = `./data/rcmp4/`
|
this.defaultPath = `./data/rcmp4/`
|
||||||
|
// redis的key
|
||||||
|
this.redisKey = `Yz:tools:cache:${this.e.group_id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 翻译插件
|
// 翻译插件
|
||||||
@ -145,6 +149,7 @@ export class tools extends plugin {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 百科
|
||||||
async wiki (e) {
|
async wiki (e) {
|
||||||
const key = e.msg.replace(/#|百科|wiki/g, "").trim();
|
const key = e.msg.replace(/#|百科|wiki/g, "").trim();
|
||||||
const url = `https://xiaoapi.cn/API/bk.php?m=json&type=bd&msg=${ encodeURI(key) }`
|
const url = `https://xiaoapi.cn/API/bk.php?m=json&type=bd&msg=${ encodeURI(key) }`
|
||||||
@ -193,6 +198,7 @@ export class tools extends plugin {
|
|||||||
if (!fs.existsSync(this.defaultPath)) {
|
if (!fs.existsSync(this.defaultPath)) {
|
||||||
mkdirsSync(this.defaultPath);
|
mkdirsSync(this.defaultPath);
|
||||||
}
|
}
|
||||||
|
const redisObj = get(this.redisKey)
|
||||||
const target = this.defaultPath + `${ this.e.group_id || this.e.user_id }/temp.mp4`
|
const target = this.defaultPath + `${ this.e.group_id || this.e.user_id }/temp.mp4`
|
||||||
// 待优化
|
// 待优化
|
||||||
if (fs.existsSync(target)) {
|
if (fs.existsSync(target)) {
|
||||||
|
28
utils/redisu.js
Normal file
28
utils/redisu.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 批量/单个添加
|
||||||
|
function add (key, values) {
|
||||||
|
if (typeof values instanceof Array) {
|
||||||
|
values.forEach(async (value) => {
|
||||||
|
await redis.set(key, value)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
redis.set(key, values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量/单个删除
|
||||||
|
function remove (key, values) {
|
||||||
|
if (typeof values instanceof Array) {
|
||||||
|
values.forEach(async (values) => {
|
||||||
|
await redis.del(key, values)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
redis.del(key, values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量/单个查询
|
||||||
|
function get (key) {
|
||||||
|
return redis.get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { get, remove, add }
|
Loading…
x
Reference in New Issue
Block a user