-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathaccept.js
More file actions
148 lines (129 loc) · 8.36 KB
/
Copy pathaccept.js
File metadata and controls
148 lines (129 loc) · 8.36 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
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
const moment = require("moment-timezone");
module.exports = {
config: {
name: "accept",
aliases: ["acp"],
version: "1.7",
author: "MahMUD",
countDown: 5,
role: 0,
description: {
bn: "বটের পেন্ডিং ফ্রেন্ড রিকোয়েস্টগুলো এক্সেপ্ট বা ডিলিট করুন (অ্যাডমিন)",
en: "Accept or delete pending friend requests of the bot (Admin)",
vi: "Chấp nhận hoặc xóa các yêu cầu kết bạn đang chờ của bot (Quản trị viên)"
},
category: "admin",
guide: {
bn: ' {pn}: রিকোয়েস্ট লিস্ট দেখতে ব্যবহার করুন। তারপর রিপ্লাই দিন "add <index>" অথবা "del <index>"।',
en: ' {pn}: Use to see request list. Then reply "add <index>" or "del <index>".',
vi: ' {pn}: Sử dụng để xem danh sách yêu cầu. Sau đó trả lời "add <index>" hoặc "del <index>".'
}
},
langs: {
bn: {
noRequest: "× কোনো পেন্ডিং ফ্রেন্ড রিকোয়েস্ট নেই! 😴",
listHeader: "📋 মোট রিকোয়েস্ট: %1টি\n",
replyGuide: "\n• 'add <index|all>' দিয়ে এক্সেপ্ট করুন\n• 'del <index|all>' দিয়ে ডিলিট করুন",
invalidAction: "× ভুল কমান্ড! শুধু add অথবা del ব্যবহার করুন।",
done: "✅ কাজ শেষ!\n• সফল: %1\n• ব্যর্থ: %2",
error: "× সমস্যা হয়েছে: %1। প্রয়োজনে Contact MahMUD।"
},
en: {
noRequest: "× No pending friend requests! 😴",
listHeader: "📋 Total Requests: %1\n",
replyGuide: "\n• Reply 'add <index|all>' to accept\n• Reply 'del <index|all>' to delete",
invalidAction: "× Invalid action! Use 'add' or 'del'.",
done: "✅ Task Complete!\n• Success: %1\n• Failed: %2",
error: "× API error: %1. Contact MahMUD for help."
},
vi: {
noRequest: "× Không có yêu cầu kết bạn nào đang chờ! 😴",
listHeader: "📋 Tổng số yêu cầu: %1\n",
replyGuide: "\n• Trả lời 'add <index|all>' để chấp nhận\n• Trả lời 'del <index|all>' để xóa",
invalidAction: "× Hành động không hợp lệ! Sử dụng 'add' hoặc 'del'.",
done: "✅ Hoàn thành!\n• Thành công: %1\n• Thất bại: %2",
error: "× Lỗi: %1. Liên hệ MahMUD để hỗ trợ."
}
},
onReply: async function ({ message, Reply, event, api, commandName, getLang }) {
const authorName = String.fromCharCode(77, 97, 104, 77, 85, 68);
if (this.config.author !== authorName) return;
const { author, listRequest } = Reply;
if (author !== event.senderID) return;
const args = event.body.trim().toLowerCase().split(" ");
let action, doc_id;
if (args[0] === "add") {
action = "accepted";
doc_id = "3147613905362928";
} else if (args[0] === "del") {
action = "deleted";
doc_id = "4108254489275063";
} else {
return message.reply(getLang("invalidAction"));
}
try {
api.setMessageReaction("⏳", event.messageID, () => {}, true);
let targetIDs = args[1] === "all" ? listRequest.map((_, index) => index + 1) : args.slice(1);
const success = [], failed = [];
for (const stt of targetIDs) {
const user = listRequest[parseInt(stt) - 1];
if (!user) continue;
const form = {
av: api.getCurrentUserID(),
fb_api_caller_class: "RelayModern",
fb_api_req_friendly_name: action === "accepted" ? "FriendingCometFriendRequestConfirmMutation" : "FriendingCometFriendRequestDeleteMutation",
doc_id,
variables: JSON.stringify({
input: {
source: "friends_tab",
actor_id: api.getCurrentUserID(),
friend_requester_id: user.node.id,
client_mutation_id: Math.round(Math.random() * 19).toString()
},
scale: 3,
refresh_num: 0
})
};
const response = await api.httpPost("https://www.facebook.com/api/graphql/", form);
if (JSON.parse(response).errors) failed.push(user.node.name);
else success.push(user.node.name);
}
api.setMessageReaction("✅", event.messageID, () => {}, true);
return message.reply(getLang("done", success.length, failed.length));
} catch (err) {
api.setMessageReaction("❌", event.messageID, () => {}, true);
return message.reply(getLang("error", err.message));
}
},
onStart: async function ({ event, api, commandName, getLang, message }) {
const authorName = String.fromCharCode(77, 97, 104, 77, 85, 68);
if (this.config.author !== authorName) return;
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 } })
};
try {
api.setMessageReaction("⏳", event.messageID, () => {}, true);
const response = await api.httpPost("https://www.facebook.com/api/graphql/", form);
const listRequest = JSON.parse(response).data.viewer.friending_possibilities.edges;
if (!listRequest.length) {
api.setMessageReaction("🥺", event.messageID, () => {}, true);
return message.reply(getLang("noRequest"));
}
let msg = getLang("listHeader", listRequest.length);
listRequest.forEach((user, index) => {
msg += `${index + 1}. ${user.node.name} (${user.node.id})\n`;
});
msg += getLang("replyGuide");
return message.reply(msg, (e, info) => {
global.GoatBot.onReply.set(info.messageID, { commandName, listRequest, author: event.senderID });
});
} catch (err) {
api.setMessageReaction("❌", event.messageID, () => {}, true);
return message.reply(getLang("error", err.message));
}
}
};