File size: 5,538 Bytes
9d1558c | 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | module.exports = {
config: {
name: "count",
version: "1.2",
author: "NTKhang",
countDown: 5,
role: 0,
shortDescription: {
vi: "Xem tin nhắn nhóm",
en: "View group messages"
},
longDescription: {
vi: "Xem số lượng tin nhắn của tất cả thành viên hoặc bản thân (tính từ lúc bot vào nhóm)",
en: "View the number of messages of all members or yourself (since the bot joined the group)"
},
category: "box chat",
guide: {
vi: " {pn}: dùng để xem số lượng tin nhắn của bạn"
+ "\n {pn} @tag: dùng để xem số lượng tin nhắn của những người được tag"
+ "\n {pn} all: dùng để xem số lượng tin nhắn của tất cả thành viên",
en: " {pn}: used to view the number of messages of you"
+ "\n {pn} @tag: used to view the number of messages of those tagged"
+ "\n {pn} all: used to view the number of messages of all members"
}
},
langs: {
vi: {
count: "Số tin nhắn của các thành viên:",
endMessage: "Những người không có tên trong danh sách là chưa gửi tin nhắn nào.",
page: "Trang [%1/%2]",
reply: "Phản hồi tin nhắn này kèm số trang để xem tiếp",
result: "%1 hạng %2 với %3 tin nhắn",
yourResult: "Bạn đứng hạng %1 và đã gửi %2 tin nhắn trong nhóm này",
invalidPage: "Số trang không hợp lệ"
},
en: {
count: "Number of messages of members:",
endMessage: "Those who do not have a name in the list have not sent any messages.",
page: "Page [%1/%2]",
reply: "Reply to this message with the page number to view more",
result: "%1 rank %2 with %3 messages",
yourResult: "You are ranked %1 and have sent %2 messages in this group",
invalidPage: "Invalid page number"
}
},
onStart: async function ({ args, threadsData, message, event, api, commandName, getLang }) {
const { threadID, senderID } = event;
const threadData = await threadsData.get(threadID);
const { members } = threadData;
const usersInGroup = (await api.getThreadInfo(threadID)).participantIDs;
let arraySort = [];
for (const user of members) {
if (!usersInGroup.includes(user.userID))
continue;
const charac = "️️️️️️️️️️️️️️️️️"; // This character is banned from facebook chat (it is not an empty string)
arraySort.push({
name: user.name.includes(charac) ? `Uid: ${user.userID}` : user.name,
count: user.count,
uid: user.userID
});
}
let stt = 1;
arraySort.sort((a, b) => b.count - a.count);
arraySort.map(item => item.stt = stt++);
if (args[0]) {
if (args[0].toLowerCase() == "all") {
let msg = getLang("count");
const endMessage = getLang("endMessage");
for (const item of arraySort) {
if (item.count > 0)
msg += `\n${item.stt}/ ${item.name}: ${item.count}`;
}
if ((msg + endMessage).length > 19999) {
msg = "";
let page = parseInt(args[1]);
if (isNaN(page))
page = 1;
const splitPage = global.utils.splitPage(arraySort, 50);
arraySort = splitPage.allPage[page - 1];
for (const item of arraySort) {
if (item.count > 0)
msg += `\n${item.stt}/ ${item.name}: ${item.count}`;
}
msg += getLang("page", page, splitPage.totalPage)
+ `\n${getLang("reply")}`
+ `\n\n${endMessage}`;
return message.reply(msg, (err, info) => {
if (err)
return message.err(err);
global.GoatBot.onReply.set(info.messageID, {
commandName,
messageID: info.messageID,
splitPage,
author: senderID
});
});
}
message.reply(msg);
}
else if (event.mentions) {
let msg = "";
for (const id in event.mentions) {
const findUser = arraySort.find(item => item.uid == id);
msg += `\n${getLang("result", findUser.name, findUser.stt, findUser.count)}`;
}
message.reply(msg);
}
}
else {
const findUser = arraySort.find(item => item.uid == senderID);
return message.reply(getLang("yourResult", findUser.stt, findUser.count));
}
},
onReply: ({ message, event, Reply, commandName, getLang }) => {
const { senderID, body } = event;
const { author, splitPage } = Reply;
if (author != senderID)
return;
const page = parseInt(body);
if (isNaN(page) || page < 1 || page > splitPage.totalPage)
return message.reply(getLang("invalidPage"));
let msg = getLang("count");
const endMessage = getLang("endMessage");
const arraySort = splitPage.allPage[page - 1];
for (const item of arraySort) {
if (item.count > 0)
msg += `\n${item.stt}/ ${item.name}: ${item.count}`;
}
msg += getLang("page", page, splitPage.totalPage)
+ "\n" + getLang("reply")
+ "\n\n" + endMessage;
message.reply(msg, (err, info) => {
if (err)
return message.err(err);
message.unsend(Reply.messageID);
global.GoatBot.onReply.set(info.messageID, {
commandName,
messageID: info.messageID,
splitPage,
author: senderID
});
});
},
onChat: async ({ usersData, threadsData, event }) => {
const { senderID, threadID } = event;
const members = await threadsData.get(threadID, "members");
const findMember = members.find(user => user.userID == senderID);
if (!findMember) {
members.push({
userID: senderID,
name: await usersData.getName(senderID),
nickname: null,
inGroup: true,
count: 1
});
}
else
findMember.count += 1;
await threadsData.set(threadID, members, "members");
}
};
|