Untitled
unknown
javascript
3 years ago
3.9 kB
10
Indexable
e("for (;;);", ""));
formData.input.attachments.push({
"photo": {
"id": result.payload.fbid.toString(),
}
});
}
/*
for (const path of paths) {
try {
fs.unlinkSync(path);
}
catch(e) {}
}
*/
}
/*
api.unsendMessage(handleReply.messageID, () => {
api.sendMessage(`Bắt đầu tạo bài viết....`, threadID, (e, info) => {
global.client.handleReply.push({
name: this.config.name,
messageID: info.messageID,
author: senderID,
formData,
type: "video"
});
}, messageID);
});
}
else if (type == "video") {
if (event.body != "0") {
if (!handleReply.uploadVideos) handleReply.uploadVideos = [];
const { uploadVideos } = handleReply;
if (attachments[0].type != "video") return;
const getFile = (await axios.get(attachments[0].url, { responseType: "arraybuffer" })).data;
const pathVideo = __dirname + "/cache/videoPost.mp4";
fs.writeFileSync(pathVideo, Buffer.from(getFile));
uploadVideos.push(fs.createReadStream(pathVideo));
return api.unsendMessage(handleReply.messageID, () => {
api.sendMessage(`Phản hồi tin nhắn này kèm video hoặc reply 0 để kết thúc`, threadID, (e, info) => {
global.client.handleReply.push({
name: this.config.name,
messageID: info.messageID,
author: senderID,
formData,
uploadVideos,
type: "video"
});
}, messageID);
});
}
if (handleReply.uploadVideos) {
let uploads = [];
for (const attachment of handleReply.uploadVideos) {
const form = {
upload_1024: attachment,
voice_clip: "true"
};
uploads.push(api.httpPostFormData("https://upload.facebook.com/ajax/mercury/upload.php", form));
}
uploads = await Promise.all(uploads);
for (let result of uploads) {
if (typeof result == "string") result = JSON.parse(result.replace("for (;;);", ""));
formData.input.attachments.push({
"video": {
"id": result.payload.metadata[0].video_id.toString(),
"notify_when_processed": true
}
});
}
}
*/
const form = {
av: botID,
fb_api_req_friendly_name: "ComposerStoryCreateMutation",
fb_api_caller_class: "RelayModern",
doc_id: "7711610262190099",
variables: JSON.stringify(formData)
};
api.httpPost('https://www.facebook.com/api/graphql/', form, (e, info) => {
api.unsendMessage(handleReply.messageID);
try {
if (e) throw e;
if (typeof info == "string") info = JSON.parse(info.replace("for (;;);", ""));
const postID = info.data.story_create.story.legacy_story_hideable_id;
const urlPost = info.data.story_create.story.url;
if (!postID) throw info.errors;
try {
fs.unlinkSync(__dirname + "/cache/imagePost.png");
//fs.unlinkSync(__dirname + "/cache/videoPost.mp4");
}
catch(e) {}
return api.sendMessage(`» Post created successfully\n» postID: ${postID}\n» urlPost: ${urlPost}`, threadID, messageID);
}
catch (e) {
//console.log(e)
return api.sendMessage(`Post creation failed, please try again later`, threadID, messageID);
}
});
}
};
function getGUID() {
var sectionLength = Date.now();
var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = Math.floor((sectionLength + Math.random() * 16) % 16);
sectionLength = Math.floor(sectionLength / 16);
var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
return _guid;
});
return id;
}Editor is loading...