-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCyber1fbdo.js
171 lines (147 loc) · 5.5 KB
/
Cyber1fbdo.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import pkg, { prepareWAMessageMedia } from '@whiskeysockets/baileys';
const { generateWAMessageFromContent, proto } = pkg;
import getFBInfo from '@xaviabot/fb-downloader';
import config from '../../config.cjs';
const fbSearchResultsMap = new Map();
let fbSearchIndex = 1;
const facebookCommand = async (m, Matrix) => {
let selectedListId;
const selectedButtonId = m?.message?.templateButtonReplyMessage?.selectedId;
const interactiveResponseMessage = m?.message?.interactiveResponseMessage;
if (interactiveResponseMessage) {
const paramsJson = interactiveResponseMessage.nativeFlowResponseMessage?.paramsJson;
if (paramsJson) {
const params = JSON.parse(paramsJson);
selectedListId = params.id;
}
}
const selectedId = selectedListId || selectedButtonId;
const prefix = config.PREFIX;
const cmd = m.body.startsWith(prefix) ? m.body.slice(prefix.length).split(' ')[0].toLowerCase() : '';
const text = m.body.slice(prefix.length + cmd.length).trim();
const validCommands = ['facebook', 'fb', 'fbdl'];
if (validCommands.includes(cmd)) {
if (!text) {
return m.reply('Please provide a Facebook video URL.');
}
try {
await m.React("🕘");
const fbData = await getFBInfo(text);
console.log("fbData:", fbData); // Log the data structure
if (!fbData) {
await m.reply('No results found.');
await m.React("❌");
return;
}
fbSearchResultsMap.set(fbSearchIndex, fbData);
const videoQualities = [];
if (fbData.sd) {
videoQualities.push({ resolution: 'SD', url: fbData.sd });
}
if (fbData.hd) {
videoQualities.push({ resolution: 'HD', url: fbData.hd });
}
const buttons = videoQualities.map((video, index) => ({
"name": "quick_reply",
"buttonParamsJson": JSON.stringify({
display_text: `📥 Download ${video.resolution}`,
id: `fbmedia_${index}_${fbSearchIndex}`
})
}));
const sections = videoQualities.map((video) => ({
title: 'Video Qualities',
rows: [{
title: `📥 Download ${video.resolution}`,
description: `Resolution: ${video.resolution}`,
id: `fbmedia_${fbSearchIndex}_${video.resolution}`
}]
}));
const msg = generateWAMessageFromContent(m.from, {
viewOnceMessage: {
message: {
messageContextInfo: {
deviceListMetadata: {},
deviceListMetadataVersion: 2
},
interactiveMessage: proto.Message.InteractiveMessage.create({
body: proto.Message.InteractiveMessage.Body.create({
text: `*BONIFHACE-MD FACEBOOK POST DOWNLOADER*\n\n> *TITLE*: ${fbData.title}`
}),
footer: proto.Message.InteractiveMessage.Footer.create({
text: "©Bonifhace Tech"
}),
header: proto.Message.InteractiveMessage.Header.create({
...(await prepareWAMessageMedia({ image: { url: fbData.thumbnail } }, { upload: Matrix.waUploadToServer })),
title: "",
gifPlayback: true,
subtitle: "",
hasMediaAttachment: false
}),
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
buttons
}),
contextInfo: {
quotedMessage: m.message,
mentionedJid: [m.sender],
forwardingScore: 9999,
isForwarded: true,
}
}),
},
},
}, {});
await Matrix.relayMessage(msg.key.remoteJid, msg.message, {
messageId: msg.key.id
});
await m.React("✅");
fbSearchIndex += 1;
} catch (error) {
console.error("Error processing your request:", error);
await m.reply('Error processing your request.');
await m.React("❌");
}
} else if (selectedId) {
if (selectedId.startsWith('fbmedia_')) {
const parts = selectedId.split('_');
const qualityIndex = parseInt(parts[1]);
const key = parseInt(parts[2]);
const selectedMedia = fbSearchResultsMap.get(key);
if (selectedMedia) {
try {
const videoQualities = [];
if (selectedMedia.sd) {
videoQualities.push({ resolution: 'SD', url: selectedMedia.sd });
}
if (selectedMedia.hd) {
videoQualities.push({ resolution: 'HD', url: selectedMedia.hd });
}
const videoUrl = videoQualities[qualityIndex].url;
let finalMediaBuffer, mimeType, content;
finalMediaBuffer = await getStreamBuffer(videoUrl);
mimeType = 'video/mp4';
const fileSizeInMB = finalMediaBuffer.length / (1024 * 1024);
if (fileSizeInMB <= 300) {
content = {
video: finalMediaBuffer,
mimetype: 'video/mp4',
caption: '> © Bonifhace Tech',
};
await Matrix.sendMessage(m.from, content, { quoted: m });
} else {
await m.reply('The video file size exceeds 300MB.');
}
} catch (error) {
console.error("Error processing your request:", error);
await m.reply('Error processing your request.');
await m.React("❌");
}
}
}
}
};
const getStreamBuffer = async (url) => {
const response = await fetch(url);
const buffer = await response.arrayBuffer();
return Buffer.from(buffer);
};
export default facebookCommand;