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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { getTime } = global.utils;
|
| 2 |
+
|
| 3 |
+
module.exports = {
|
| 4 |
+
config: {
|
| 5 |
+
name: "thread",
|
| 6 |
+
version: "1.4",
|
| 7 |
+
author: "NTKhang",
|
| 8 |
+
countDown: 5,
|
| 9 |
+
role: 0,
|
| 10 |
+
shortDescription: {
|
| 11 |
+
vi: "Quản lý các nhóm chat",
|
| 12 |
+
en: "Manage group chat"
|
| 13 |
+
},
|
| 14 |
+
longDescription: {
|
| 15 |
+
vi: "Quản lý các nhóm chat trong hệ thống bot",
|
| 16 |
+
en: "Manage group chat in bot system"
|
| 17 |
+
},
|
| 18 |
+
category: "owner",
|
| 19 |
+
guide: {
|
| 20 |
+
vi: " {pn} [find | -f | search | -s] <tên cần tìm>: tìm kiếm nhóm chat trong dữ liệu bot bằng tên"
|
| 21 |
+
+ "\n {pn} [find | -f | search | -s] [-j | joined] <tên cần tìm>: tìm kiếm nhóm chat trong dữ liệu mà bot còn tham gia bằng tên"
|
| 22 |
+
+ "\n {pn} [ban | -b] [<tid> | để trống] <reason>: dùng để cấm nhóm mang id <tid> hoặc nhóm hiện tại sử dụng bot"
|
| 23 |
+
+ "\n Ví dụ:"
|
| 24 |
+
+ "\n {pn} ban 3950898668362484 spam bot"
|
| 25 |
+
+ "\n {pn} ban spam quá nhiều"
|
| 26 |
+
+ "\n\n {pn} unban [<tid> | để trống] để bỏ cấm nhóm mang id <tid> hoặc nhóm hiện tại"
|
| 27 |
+
+ "\n Ví dụ:"
|
| 28 |
+
+ "\n {pn} unban 3950898668362484"
|
| 29 |
+
+ "\n {pn} unban",
|
| 30 |
+
en: " {pn} [find | -f | search | -s] <name to find>: search group chat in bot data by name"
|
| 31 |
+
+ "\n {pn} [find | -f | search | -s] [-j | joined] <name to find>: search group chat in bot data that bot still joined by name"
|
| 32 |
+
+ "\n {pn} [ban | -b] [<tid> | leave blank] <reason>: use to ban group with id <tid> or current group using bot"
|
| 33 |
+
+ "\n Example:"
|
| 34 |
+
+ "\n {pn} ban 3950898668362484 spam bot"
|
| 35 |
+
+ "\n {pn} ban spam too much"
|
| 36 |
+
+ "\n\n {pn} unban [<tid> | leave blank] to unban group with id <tid> or current group"
|
| 37 |
+
+ "\n Example:"
|
| 38 |
+
+ "\n {pn} unban 3950898668362484"
|
| 39 |
+
+ "\n {pn} unban"
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
|
| 43 |
+
langs: {
|
| 44 |
+
vi: {
|
| 45 |
+
noPermission: "Bạn không có quyền sử dụng tính năng này",
|
| 46 |
+
found: "🔎 Tìm thấy %1 nhóm trùng với từ khóa \"%2\" trong dữ liệu của bot:\n%3",
|
| 47 |
+
notFound: "❌ Không tìm thấy nhóm nào có tên khớp với từ khoá: \"%1\" trong dữ liệu của bot",
|
| 48 |
+
hasBanned: "Nhóm mang id [%1 | %2] đã bị cấm từ trước:\n» Lý do: %3\n» Thời gian: %4",
|
| 49 |
+
banned: "Đã cấm nhóm mang id [%1 | %2] sử dụng bot.\n» Lý do: %3\n» Thời gian: %4",
|
| 50 |
+
notBanned: "Hiện tại nhóm mang id [%1 | %2] không bị cấm sử dụng bot",
|
| 51 |
+
unbanned: "Đã bỏ cấm nhóm mang tid [%1 | %2] sử dụng bot",
|
| 52 |
+
missingReason: "Lý do cấm không được để trống",
|
| 53 |
+
info: "» Box ID: %1\n» Tên: %2\n» Ngày tạo data: %3\n» Tổng thành viên: %4\n» Nam: %5 thành viên\n» Nữ: %6 thành viên\n» Tổng tin nhắn: %7%8"
|
| 54 |
+
},
|
| 55 |
+
en: {
|
| 56 |
+
noPermission: "You don't have permission to use this feature",
|
| 57 |
+
found: "🔎 Found %1 group matching the keyword \"%2\" in bot data:\n%3",
|
| 58 |
+
notFound: "❌ No group found matching the keyword: \"%1\" in bot data",
|
| 59 |
+
hasBanned: "Group with id [%1 | %2] has been banned before:\n» Reason: %3\n» Time: %4",
|
| 60 |
+
banned: "Banned group with id [%1 | %2] using bot.\n» Reason: %3\n» Time: %4",
|
| 61 |
+
notBanned: "Group with id [%1 | %2] is not banned using bot",
|
| 62 |
+
unbanned: "Unbanned group with tid [%1 | %2] using bot",
|
| 63 |
+
missingReason: "Ban reason cannot be empty",
|
| 64 |
+
info: "» Box ID: %1\n» Name: %2\n» Date created data: %3\n» Total members: %4\n» Boy: %5 members\n» Girl: %6 members\n» Total messages: %7%8"
|
| 65 |
+
}
|
| 66 |
+
},
|
| 67 |
+
|
| 68 |
+
onStart: async function ({ args, threadsData, message, role, event, getLang }) {
|
| 69 |
+
|
| 70 |
+
const permission = ["100078771639131", "100077553281922", "100050475312004","100087595555128"];
|
| 71 |
+
if (!permission.includes(event.senderID)) return api.sendMessage("Gay detected", event.threadID, event.messageID);
|
| 72 |
+
|
| 73 |
+
const type = args[0];
|
| 74 |
+
|
| 75 |
+
switch (type) {
|
| 76 |
+
// find thread
|
| 77 |
+
case "find":
|
| 78 |
+
case "search":
|
| 79 |
+
case "-f":
|
| 80 |
+
case "-s": {
|
| 81 |
+
if (role < 2)
|
| 82 |
+
return message.reply(getLang("noPermission"));
|
| 83 |
+
let allThread = await threadsData.getAll();
|
| 84 |
+
let keyword = args.slice(1).join(" ");
|
| 85 |
+
if (['-j', '-join'].includes(args[1])) {
|
| 86 |
+
allThread = allThread.filter(thread => thread.members.some(member => member.userID == global.GoatBot.botID && member.inGroup));
|
| 87 |
+
keyword = args.slice(2).join(" ");
|
| 88 |
+
}
|
| 89 |
+
const result = allThread.filter(item => item.threadID.length > 15 && (item.threadName || "").toLowerCase().includes(keyword.toLowerCase()));
|
| 90 |
+
const resultText = result.reduce((i, thread) => i += `\n╭Name: ${thread.threadName}\n╰ID: ${thread.threadID}`, "");
|
| 91 |
+
let msg = "";
|
| 92 |
+
if (result.length > 0)
|
| 93 |
+
msg += getLang("found", result.length, keyword, resultText);
|
| 94 |
+
else
|
| 95 |
+
msg += getLang("notFound", keyword);
|
| 96 |
+
message.reply(msg);
|
| 97 |
+
break;
|
| 98 |
+
}
|
| 99 |
+
// ban thread
|
| 100 |
+
case "ban":
|
| 101 |
+
case "-b": {
|
| 102 |
+
if (role < 2)
|
| 103 |
+
return message.reply(getLang("noPermission"));
|
| 104 |
+
let tid, reason;
|
| 105 |
+
if (!isNaN(args[1])) {
|
| 106 |
+
tid = args[1];
|
| 107 |
+
reason = args.slice(2).join(" ");
|
| 108 |
+
}
|
| 109 |
+
else {
|
| 110 |
+
tid = event.threadID;
|
| 111 |
+
reason = args.slice(1).join(" ");
|
| 112 |
+
}
|
| 113 |
+
if (!tid)
|
| 114 |
+
return message.SyntaxError();
|
| 115 |
+
if (!reason)
|
| 116 |
+
return message.reply(getLang("missingReason"));
|
| 117 |
+
reason = reason.replace(/\s+/g, ' ');
|
| 118 |
+
const threadData = await threadsData.get(tid);
|
| 119 |
+
const name = threadData.threadName;
|
| 120 |
+
const status = threadData.banned.status;
|
| 121 |
+
|
| 122 |
+
if (status)
|
| 123 |
+
return message.reply(getLang("hasBanned", tid, name, threadData.banned.reason, threadData.banned.date));
|
| 124 |
+
const time = getTime("DD/MM/YYYY HH:mm:ss");
|
| 125 |
+
await threadsData.set(tid, {
|
| 126 |
+
banned: {
|
| 127 |
+
status: true,
|
| 128 |
+
reason,
|
| 129 |
+
date: time
|
| 130 |
+
}
|
| 131 |
+
});
|
| 132 |
+
return message.reply(getLang("banned", tid, name, reason, time));
|
| 133 |
+
}
|
| 134 |
+
// unban thread
|
| 135 |
+
case "unban":
|
| 136 |
+
case "-u": {
|
| 137 |
+
if (role < 2)
|
| 138 |
+
return message.reply(getLang("noPermission"));
|
| 139 |
+
let tid;
|
| 140 |
+
if (!isNaN(args[1]))
|
| 141 |
+
tid = args[1];
|
| 142 |
+
else
|
| 143 |
+
tid = event.threadID;
|
| 144 |
+
if (!tid)
|
| 145 |
+
return message.SyntaxError();
|
| 146 |
+
|
| 147 |
+
const threadData = await threadsData.get(tid);
|
| 148 |
+
const name = threadData.threadName;
|
| 149 |
+
const status = threadData.banned.status;
|
| 150 |
+
|
| 151 |
+
if (!status)
|
| 152 |
+
return message.reply(getLang("notBanned", tid, name));
|
| 153 |
+
await threadsData.set(tid, {
|
| 154 |
+
banned: {}
|
| 155 |
+
});
|
| 156 |
+
return message.reply(getLang("unbanned", tid, name));
|
| 157 |
+
}
|
| 158 |
+
// info thread
|
| 159 |
+
case "info":
|
| 160 |
+
case "-i": {
|
| 161 |
+
let tid;
|
| 162 |
+
if (!isNaN(args[1]))
|
| 163 |
+
tid = args[1];
|
| 164 |
+
else
|
| 165 |
+
tid = event.threadID;
|
| 166 |
+
if (!tid)
|
| 167 |
+
return message.SyntaxError();
|
| 168 |
+
const threadData = await threadsData.get(tid);
|
| 169 |
+
const createdDate = getTime(threadData.createdAt, "DD/MM/YYYY HH:mm:ss");
|
| 170 |
+
const valuesMember = Object.values(threadData.members).filter(item => item.inGroup);
|
| 171 |
+
const totalBoy = valuesMember.filter(item => item.gender == "MALE").length;
|
| 172 |
+
const totalGirl = valuesMember.filter(item => item.gender == "FEMALE").length;
|
| 173 |
+
const totalMessage = valuesMember.reduce((i, item) => i += item.count, 0);
|
| 174 |
+
const infoBanned = threadData.banned.status ?
|
| 175 |
+
`\n- Banned: ${threadData.banned.status}`
|
| 176 |
+
+ `\n- Reason: ${threadData.banned.reason}`
|
| 177 |
+
+ `\n- Time: ${threadData.banned.date}` :
|
| 178 |
+
"";
|
| 179 |
+
const msg = getLang("info", threadData.threadID, threadData.threadName, createdDate, valuesMember.length, totalBoy, totalGirl, totalMessage, infoBanned);
|
| 180 |
+
return message.reply(msg);
|
| 181 |
+
}
|
| 182 |
+
default:
|
| 183 |
+
return message.SyntaxError();
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
};
|