-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccept.js
More file actions
109 lines (99 loc) · 3.74 KB
/
accept.js
File metadata and controls
109 lines (99 loc) · 3.74 KB
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
module.exports.config = {
name: "accept",
version: "1.0.0",
hasPermssion: 2,
credits: "SenProject", //Ntkhang
description: "chấp nhận lời kb",
group: "economy",
usages: "",
cooldowns: 5
};
module.exports.handleReply = async ({ handleReply, event, api }) => {
const { author, listRequest } = handleReply;
if (author != event.senderID) return;
const args = event.body.replace(/ +/g, " ").toLowerCase().split(" ");
const form = {
av: api.getCurrentUserID(),
fb_api_caller_class: "RelayModern",
variables: {
input: {
source: "friends_tab",
actor_id: api.getCurrentUserID(),
client_mutation_id: Math.round(Math.random() * 19).toString()
},
scale: 3,
refresh_num: 0
}
};
const success = [];
const failed = [];
if (args[0] == "add") {
form.fb_api_req_friendly_name = "FriendingCometFriendRequestConfirmMutation";
form.doc_id = "3147613905362928";
}
else if (args[0] == "del") {
form.fb_api_req_friendly_name = "FriendingCometFriendRequestDeleteMutation";
form.doc_id = "4108254489275063";
}
else return api.sendMessage("Vui lòng chọn <add | del > <số thứ tự | hoặc \"all\">", event.threadID, event.messageID);
let targetIDs = args.slice(1);
if (args[1] == "all") {
targetIDs = [];
const lengthList = listRequest.length;
for (let i = 1; i <= lengthList; i++) targetIDs.push(i);
}
const newTargetIDs = [];
const promiseFriends = [];
for (const stt of targetIDs) {
const u = listRequest[parseInt(stt) - 1];
if (!u) {
failed.push(`Không tìm thấy stt ${stt} trong danh sách`);
continue;
}
form.variables.input.friend_requester_id = u.node.id;
form.variables = JSON.stringify(form.variables);
newTargetIDs.push(u);
promiseFriends.push(api.httpPost("https://www.facebook.com/api/graphql/", form));
form.variables = JSON.parse(form.variables);
}
const lengthTarget = newTargetIDs.length;
for (let i = 0; i < lengthTarget; i++) {
try {
const friendRequest = await promiseFriends[i];
if (JSON.parse(friendRequest).errors) failed.push(newTargetIDs[i].node.name);
else success.push(newTargetIDs[i].node.name);
}
catch(e) {
failed.push(newTargetIDs[i].node.name);
}
}
api.sendMessage(`» Đã ${args[0] == 'add' ? 'chấp nhận' : 'xóa'} lời mời kết bạn thành công của ${success.length} người:\n${success.join("\n")}${failed.length > 0 ? `\n» Thất bại với ${failed.length} người: ${failed.join("\n")}` : ""}`, event.threadID, event.messageID);
};
module.exports.run = async ({ event, api }) => {
const moment = require("moment-timezone");
const form = {
av: api.getCurrentUserID(),
fb_api_req_friendly_name: "FriendingCometFriendRequestsRootQueryRelayPreloader",
fb_api_caller_class: "RelayModern",
doc_id: "4499164963466303",
variables: JSON.stringify({input: {scale: 3}})
};
const listRequest = JSON.parse(await api.httpPost("https://www.facebook.com/api/graphql/", form)).data.viewer.friending_possibilities.edges;
let msg = "";
let i = 0;
for (const user of listRequest) {
i++;
msg += (`\n${i}. Name: ${user.node.name}`
+ `\nID: ${user.node.id}`
+ `\nUrl: ${user.node.url.replace("www.facebook", "fb")}`
+ `\nTime: ${moment(user.time*1009).tz("Asia/Ho_Chi_Minh").format("DD/MM/YYYY HH:mm:ss")}\n`);
}
api.sendMessage(`${msg}\nReply tin nhắn này với nội dung: <add | del> <số thứ tự | hoặc \"all\"> để thực hiện hành động`, event.threadID, (e, info) => {
global.client.handleReply.push({
name: this. config. name,
messageID: info.messageID,
listRequest,
author: event.senderID
});
}, event.messageID);
};