forked from Time3517/Bncr_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path姐姐.js
46 lines (41 loc) · 1.28 KB
/
姐姐.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @author YG
* @name 姐姐
* @team YG
* @version 1.0.0
* @description 随机返回一个跳舞的小姐姐视频
* @rule ^(姐姐|jj)$
* @admin true
*/
const request = require('request');
const { randomUUID } = require('crypto');
const path = require('path');
const fs = require('fs');
module.exports = async s => {
if (!(await s.isAdmin())) {
await s.reply('你没有权限使用这个命令。');
return;
}
let url = 'http://api.yujn.cn/api/zzxjj.php';
console.log('请求 URL:', url);
try {
const videoPath = await downloadVideo(url);
await s.reply({
type: 'video',
path: videoPath,
msg: '跳舞小姐姐来啦~',
});
fs.unlinkSync(videoPath); // 删除临时文件
} catch (error) {
console.error('发送视频时发生错误:', error);
await s.reply('未能获取到视频,请稍后再试。');
}
};
async function downloadVideo(url) {
const filePath = path.join(process.cwd(), `BncrData/public/${randomUUID().split('-').join('')}.mp4`);
return new Promise((resolve, reject) => {
const stream = request(url).pipe(fs.createWriteStream(filePath));
stream.on('finish', () => resolve(filePath));
stream.on('error', reject);
});
}