🐞 fix: 设置部分功能为可选

This commit is contained in:
zhiyu1998 2023-02-08 12:52:27 +08:00
parent 96c7ea3fe7
commit d706e56706
2 changed files with 71 additions and 41 deletions

View File

@ -38,10 +38,13 @@ index -- 主入口
5. 【可选】要使用视频解析功能要下载插件【推荐ubuntu系统】
> sudo apt-get install ffmpeg
必要】备注如果启动不起来删除mongodb的代码即可
可选】备注考虑到不是所有电脑都有mongodb,如果要开启#我靠功能,需要把以下代码(apps/mystery.js)注释取消
```javascript
// in apps/mystery.js
// Mongodb初始化
import mongodb from 'mongodb'
// Mongodb初始化
function initMongo () {
const MongoClient = mongodb.MongoClient
@ -57,6 +60,33 @@ function initMongo () {
})
})
}
const mongo = initMongo()
// ...
{
reg: '^#我靠', fnc: 'tuiimg'
}
// ...
async tuiimg (e) {
const MAX_SIZE = this.mysteryConfig.tuiimg.count
this.reply('这群早晚被你整没了...')
let images = []
const template = {
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
}
await mongo.then(conn => {
return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
}).then((result) => {
result.forEach((item) => {
images.push({
message: segment.image(item.url), ...template
})
})
})
return !!(await this.reply(await Bot.makeForwardMsg(images), false, {
recallMsg: recallTime
}))
}
```
【必要】相关配置(apps/tools.js)

View File

@ -6,25 +6,25 @@ import fetch from 'node-fetch'
import config from '../model/index.js'
// 其他库
import _ from 'lodash'
import mongodb from 'mongodb'
// import mongodb from 'mongodb'
// Mongodb初始化
function initMongo () {
const MongoClient = mongodb.MongoClient
const url = 'mongodb://localhost:27017/'
return new Promise((resolve, reject) => {
MongoClient.connect(url, (err, db) => {
const dbo = db.db('test')
if (err) {
throw err // 和调用 reject(err) 效果类似
}
let collection = dbo.collection('temp')
resolve(collection)
})
})
}
const mongo = initMongo()
// function initMongo () {
// const MongoClient = mongodb.MongoClient
// const url = 'mongodb://localhost:27017/'
// return new Promise((resolve, reject) => {
// MongoClient.connect(url, (err, db) => {
// const dbo = db.db('test')
// if (err) {
// throw err // 和调用 reject(err) 效果类似
// }
// let collection = dbo.collection('temp')
// resolve(collection)
// })
// })
// }
//
// const mongo = initMongo()
// 60s后撤回
const recallTime = 109
@ -48,9 +48,9 @@ export class mystery extends plugin {
{
reg: '^#(啊?|啊?)$', fnc: 'aaa'
},
{
reg: '^#我靠', fnc: 'tuiimg'
}
// {
// reg: '^#我靠', fnc: 'tuiimg'
// }
]
})
this.mysteryConfig = config.getConfig('mystery')
@ -252,26 +252,26 @@ export class mystery extends plugin {
return true
}
async tuiimg (e) {
const MAX_SIZE = this.mysteryConfig.tuiimg.count
this.reply('这群早晚被你整没了...')
let images = []
const template = {
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
}
await mongo.then(conn => {
return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
}).then((result) => {
result.forEach((item) => {
images.push({
message: segment.image(item.url), ...template
})
})
})
return !!(await this.reply(await Bot.makeForwardMsg(images), false, {
recallMsg: recallTime
}))
}
// async tuiimg (e) {
// const MAX_SIZE = this.mysteryConfig.tuiimg.count
// this.reply('这群早晚被你整没了...')
// let images = []
// const template = {
// nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
// }
// await mongo.then(conn => {
// return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
// }).then((result) => {
// result.forEach((item) => {
// images.push({
// message: segment.image(item.url), ...template
// })
// })
// })
// return !!(await this.reply(await Bot.makeForwardMsg(images), false, {
// recallMsg: recallTime
// }))
// }
// 正则:获取图片
getCos6Img (string) {