forked from dark-sasiya/DEXTER-V1-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgs.js
49 lines (43 loc) · 1.96 KB
/
msgs.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
const { Function, getMessage, formatDuration } = require('../lib/');
Function({
pattern: 'msgs ?(.*)',
fromMe: true,
desc: 'Gives an overview of the total messages in the group',
type: 'group'
}, async (message, match, client) => {
if (!message.isGroup) return await message.reply('_This command only works in group chats_');
const userId = message.mention[0] || message.reply_message?.sender;
const data = await getMessage(message.jid);
const timeNow = new Date().getTime();
let msg = '';
if (match === 'total') {
let totalCount = 0;
const typeCount = {};
Object.values(data).forEach(({ total, type }) => {
totalCount += total;
Object.entries(type).forEach(([typeName, count]) => {
typeCount[typeName] = (typeCount[typeName] || 0) + count;
});
});
msg += '*Total :* ' + totalCount + '\n';
Object.entries(typeCount).forEach(([typeName, count]) => {
msg += '*' + typeName + ' :* ' + count + '\n';
});
} else if (userId) {
const user = await getMessage(message.jid, userId);
msg += '*Number :* ' + userId.split("@")[0] + '\n*Name :* ' + (user.name.replace( /[\r\n]+/gm, "") || 'Unknown') + '\n';
Object.keys(user.type).map(item => msg += '*' + item + ' :* ' + user.type[item] + '\n');
msg += '*Total :* ' + user.total + '\n';
msg += '*lastActivity :* ' + formatDuration((timeNow - user.time) / 1000) + ' ago\n\n';
} else {
Object.entries(data)
.sort(([, a], [, b]) => b.total - a.total)
.map(([user, { name, total, type, time }]) => {
msg += '*Number :* ' + user.split("@")[0] + '\n*Name :* ' + (name.replace( /[\r\n]+/gm, "") || 'Unknown') + '\n';
Object.keys(type).map(item => msg += '*' + item + ' :* ' + type[item] + '\n');
msg += '*Total :* ' + total + '\n';
msg += '*lastActivity :* ' + formatDuration((timeNow - time) / 1000) + ' ago\n\n';
});
}
return await message.send(msg.trim());
});