forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-all-message.js
60 lines (54 loc) · 1.4 KB
/
delete-all-message.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
export async function deleteMessages(chatId, messageArray) {
if (typeof chatId != 'string') {
return WAPI.scope(
null,
true,
404,
'enter the chatid variable as an string'
);
}
const chat = await WAPI.sendExist(chatId);
if (chat && chat.status != 404) {
if (!Array.isArray(messageArray)) {
return WAPI.scope(
chat,
true,
404,
'enter the message identification variable as an array'
);
}
for (let i in messageArray) {
if (typeof messageArray[i] === 'string') {
let checkID = await WAPI.checkIdMessage(chatId, messageArray[i]);
if (checkID.erro == true) {
return checkID;
}
}
}
let messagesToDelete = (
await Promise.all(
messageArray.map(
async (msgId) => await WAPI.getMessageById(msgId, null, false)
)
)
).filter((x) => x);
const To = chat.id;
const m = { type: 'deleteMessages' };
let jobs = [
chat.sendRevokeMsgs(messagesToDelete, chat),
chat.sendDeleteMsgs(messagesToDelete, chat)
];
const result = (await Promise.all(jobs))[1];
if (result >= 0) {
let obj = WAPI.scope(To, false, result, '');
Object.assign(obj, m);
return obj;
} else {
let obj = WAPI.scope(To, true, result, '');
Object.assign(obj, m);
return obj;
}
} else {
return chat;
}
}