-
Notifications
You must be signed in to change notification settings - Fork 10
/
message.js
74 lines (72 loc) · 2.32 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Copyright (C) 2022 X-Electra.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
X-Asena - X-Electra
*/
exports.getChatjids = function (){
const store = require('../database/store.json')
let jid = []
store.chats.forEach(({id})=> {
jid.push(id)
})
return jid}
exports.getmsg=function(jid) {
const store = require('../database/store.json')
let messagea = {};
let users = [];
function user(){
return users
}
if (jid.endsWith("@g.us")) {
context = {
users: messagea,
};
store.messages[jid].forEach((str) => {
let msg = store.messages[jid].filter(
({ key }) => !users.includes(key.participant)
);
for (let { key, message } of msg) {
if (!users.includes(key.participant)) {
users.push(key.participant);
}
}
store.messages[jid].forEach((str) => {
let msg, name, mseg;
for (let i of users) {
mseg = store.messages[jid].filter(({ key }) => key.participant === i);
msg = store.messages[jid]
.filter(({ key }) => key.participant === i)
.map((b) => JSON.stringify(b));
name = mseg[0].pushName;
messagea[i] = {
name,
messages: msg,
total_msg: msg.length,
text: mseg.filter(
({ message }) =>
message.hasOwnProperty("conversation") ||
message.hasOwnProperty("extendedTextMessage")
).length,
sticker: mseg.filter(({ message }) =>
message.hasOwnProperty("stickerMessage")
).length,
image: mseg.filter(({ message }) =>
message.hasOwnProperty("imageMessage")
).length,
video: mseg.filter(({ message }) =>
message.hasOwnProperty("videoMessage")
).length,
audio: mseg.filter(({ message }) =>
message.hasOwnProperty("audioMessage")
).length,
reaction: mseg.filter(({ message }) =>
message.hasOwnProperty("reactionMessage")
).length,
};
}
});
//console.log(msg)
});
}
return context;
}