From d706e56706eb88d7285d29bae27caa7dff20f572 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Wed, 8 Feb 2023 12:52:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8A=9F=E8=83=BD=E4=B8=BA=E5=8F=AF=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 +++++++++++++++++++- apps/mystery.js | 80 ++++++++++++++++++++++++------------------------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 0374a91..50332e8 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/apps/mystery.js b/apps/mystery.js index 216dfde..cc70524 100644 --- a/apps/mystery.js +++ b/apps/mystery.js @@ -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) {