File size: 10,359 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | const { getPrefix } = global.utils;
module.exports = {
config: {
name: "rules",
version: "1.4",
author: "NTKhang",
countDown: 5,
role: 0,
shortDescription: {
vi: "Quy tắc của nhóm",
en: "Group rules"
},
longDescription: {
vi: "Tạo/xem/thêm/sửa/đổi vị trí/xóa nội quy nhóm của bạn",
en: "Create/view/add/edit/change position/delete group rules of you"
},
category: "box chat",
guide: {
vi: " {pn} [add | -a] <nội quy muốn thêm>: thêm nội quy cho nhóm."
+ "\n {pn}: xem nội quy của nhóm."
+ "\n {pn} [edit | -e] <n> <nội dung sau khi sửa>: chỉnh sửa lại nội quy thứ n."
+ "\n {pn} [move | -m] <stt1> <stt2> hoán đổi vị trí của nội quy thứ <stt1> và <stt2> với nhau."
+ "\n {pn} [delete | -d] <n>: xóa nội quy theo số thứ tự thứ n."
+ "\n {pn} [remove | -r]: xóa tất cả nội quy của nhóm."
+ "\n"
+ "\n Ví dụ:"
+ "\n {pn} add không spam"
+ "\n {pn} move 1 3"
+ "\n {pn} -e 1 không spam tin nhắn trong nhóm"
+ "\n {pn} -r",
en: " {pn} [add | -a] <rule to add>: add rule for group."
+ "\n {pn}: view group rules."
+ "\n {pn} [edit | -e] <n> <content after edit>: edit rule number n."
+ "\n {pn} [move | -m] <stt1> <stt2> swap position of rule number <stt1> and <stt2>."
+ "\n {pn} [delete | -d] <n>: delete rule number n."
+ "\n {pn} [remove | -r]: delete all rules of group."
+ "\n"
+ "\n Example:"
+ "\n {pn} add don't spam"
+ "\n {pn} move 1 3"
+ "\n {pn} -e 1 don't spam message in group"
+ "\n {pn} -r"
}
},
langs: {
vi: {
yourRules: "Nội quy của nhóm bạn\n%1",
noRules: "Hiện tại nhóm bạn chưa có bất kỳ nội quy nào, để thêm nội quy cho nhóm hãy sử dụng `%1rules add`",
noPermissionAdd: "Chỉ quản trị viên mới có thể thêm nội quy cho nhóm",
noContent: "Vui lòng nhập nội dung cho nội quy bạn muốn thêm",
success: "Đã thêm nội quy mới cho nhóm thành công",
noPermissionEdit: "Chỉ quản trị viên mới có thể chỉnh sửa nội quy nhóm",
invalidNumber: "Vui lòng nhập số thứ tự của quy định bạn muốn chỉnh sửa",
rulesNotExist: "Không tồn tại nội quy thứ %1",
numberRules: "Hiện tại nhóm bạn chỉ có %1 nội quy được đặt ra",
noContentEdit: "Vui lòng nhập nội dung bạn muốn thay đổi cho nội quy thứ %1",
successEdit: "Đã chỉnh sửa nội quy thứ %1 thành: %2",
noPermissionMove: "Chỉ quản trị viên mới có thể đổi vị trí nội quy của nhóm",
invalidNumberMove: "Vui lòng nhập số thứ tự của 2 nội quy nhóm bạn muốn chuyển đổi vị trí với nhau",
rulesNotExistMove2: "Không tồn tại nội quy thứ %1 và %2",
successMove: "Đã chuyển đổi vị trí của 2 nội quy thứ %1 và %2",
noPermissionDelete: "Chỉ quản trị viên mới có thể xóa nội quy của nhóm",
invalidNumberDelete: "Vui lòng nhập số thứ tự của nội quy bạn muốn xóa",
rulesNotExistDelete: "Không tồn tại nội quy thứ %1",
successDelete: "Đã xóa nội quy thứ %1 của nhóm, nội dung: %2",
noPermissionRemove: "Chỉ có quản trị viên nhóm mới có thể xoá bỏ tất cả nội quy của nhóm",
confirmRemove: "⚠️ Thả cảm xúc bất kỳ vào tin nhắn này để xác nhận xóa toàn bộ nội quy của nhóm",
successRemove: "Đã xóa toàn bộ nội quy của nhóm thành công",
invalidNumberView: "Vui lòng nhập số thứ tự của nội quy bạn muốn xem"
},
en: {
yourRules: "Your group rules\n%1",
noRules: "Your group has no rules, to add rules for group use `%1rules add`",
noPermissionAdd: "Only admins can add rules for group",
noContent: "Please enter the content for the rule you want to add",
success: "Added new rule for group successfully",
noPermissionEdit: "Only admins can edit group rules",
invalidNumber: "Please enter the number of the rule you want to edit",
rulesNotExist: "Rule number %1 does not exist",
numberRules: "Your group only has %1 rules",
noContentEdit: "Please enter the content you want to change for rule number %1",
successEdit: "Edited rule number %1 to: %2",
noPermissionMove: "Only admins can move group rules",
invalidNumberMove: "Please enter the number of 2 group rules you want to swap",
rulesNotExistMove2: "Rule number %1 and %2 does not exist",
successMove: "Swapped position of rule number %1 and %2",
noPermissionDelete: "Only admins can delete group rules",
invalidNumberDelete: "Please enter the number of the rule you want to delete",
rulesNotExistDelete: "Rule number %1 does not exist",
successDelete: "Deleted rule number %1 of group, content: %2",
noPermissionRemove: "Only group admins can remove all group rules",
confirmRemove: "⚠️ React to this message with any emoji to confirm remove all group rules",
successRemove: "Removed all group rules successfully",
invalidNumberView: "Please enter the number of the rule you want to view"
}
},
onStart: async function ({ role, args, message, event, threadsData, getLang, commandName }) {
const { threadID, senderID } = event;
const type = args[0];
const rulesOfThread = await threadsData.get(threadID, "data.rules", []);
const totalRules = rulesOfThread.length;
if (!type) {
let i = 1;
const msg = rulesOfThread.reduce((text, rules) => text += `${i++}. ${rules}\n`, "");
message.reply(msg ? getLang("yourRules", msg) : getLang("noRules", getPrefix(threadID)), (err, info) => {
global.GoatBot.onReply.set(info.messageID, {
commandName,
author: senderID,
rulesOfThread,
messageID: info.messageID
});
});
}
else if (["add", "-a"].includes(type)) {
if (role < 1)
return message.reply(getLang("noPermissionAdd"));
if (!args[1])
return message.reply(getLang("noContent"));
rulesOfThread.push(args.slice(1).join(" "));
try {
await threadsData.set(threadID, rulesOfThread, "data.rules");
message.reply(getLang("success"));
}
catch (err) {
message.err(err);
}
}
else if (["edit", "-e"].includes(type)) {
if (role < 1)
return message.reply(getLang("noPermissionEdit"));
const stt = parseInt(args[1]);
if (stt === NaN)
return message.reply(getLang("invalidNumber"));
if (!rulesOfThread[stt - 1])
return message.reply(`${getLang("rulesNotExist", stt)}, ${totalRules == 0 ? getLang("noRules") : getLang("numberRules", totalRules)}`);
if (!args[2])
return message.reply(getLang("noContentEdit", stt));
const newContent = args.slice(2).join(" ");
rulesOfThread[stt - 1] = newContent;
try {
await threadsData.set(threadID, rulesOfThread, "data.rules");
message.reply(getLang("successEdit", stt, newContent));
}
catch (err) {
message.err(err);
}
}
else if (["move", "-m"].includes(type)) {
if (role < 1)
return message.reply(getLang("noPermissionMove"));
const stt1 = parseInt(args[1]);
const stt2 = parseInt(args[2]);
if (isNaN(stt1) || isNaN(stt2))
return message.reply(getLang("invalidNumberMove"));
if (!rulesOfThread[stt1 - 1] || !rulesOfThread[stt2 - 1]) {
let msg = !rulesOfThread[stt1 - 1] ?
!rulesOfThread[stt2 - 1] ?
message.reply(getLang("rulesNotExistMove2", stt1, stt2)) :
message.reply(getLang("rulesNotExistMove", stt1)) :
message.reply(getLang("rulesNotExistMove", stt2));
msg += `, ${totalRules == 0 ? getLang("noRules") : getLang("numberRules", totalRules)}`;
return message.reply(msg);
}
// swap
[rulesOfThread[stt1 - 1], rulesOfThread[stt2 - 1]] = [rulesOfThread[stt2 - 1], rulesOfThread[stt1 - 1]];
try {
await threadsData.set(threadID, rulesOfThread, "data.rules");
message.reply(getLang("successMove"));
}
catch (err) {
message.err(err);
}
}
else if (["delete", "del", "-d"].includes(type)) {
if (role < 1)
return message.reply(getLang("noPermissionDelete"));
if (!args[1] || isNaN(args[1]))
return message.reply(getLang("invalidNumberDelete"));
const rulesDel = rulesOfThread[parseInt(args[1]) - 1];
if (!rulesDel)
return message.reply(`${getLang("rulesNotExistDelete", args[1])}, ${totalRules == 0 ? getLang("noRules") : getLang("numberRules", totalRules)}`);
rulesOfThread.splice(parseInt(args[1]) - 1, 1);
await threadsData.set(threadID, rulesOfThread, "data.rules");
message.reply(getLang("successDelete", args[1], rulesDel));
}
else if (["remove", "reset", "-r", "-rm"].includes(type)) {
if (role < 1)
return message.reply(getLang("noPermissionRemove"));
message.reply(getLang("confirmRemove"), (err, info) => {
global.GoatBot.onReaction.set(info.messageID, {
commandName: "rules",
messageID: info.messageID,
author: senderID
});
});
}
else if (!isNaN(type)) {
let msg = "";
for (const stt of args) {
const rules = rulesOfThread[parseInt(stt) - 1];
if (rules)
msg += `${stt}. ${rules}\n`;
}
if (msg == "")
return message.reply(`${getLang("rulesNotExist", type)}, ${totalRules == 0 ? getLang("noRules") : getLang("numberRules", totalRules)}`);
message.reply(msg);
}
else {
message.SyntaxError();
}
},
onReply: async function ({ message, event, getLang, Reply }) {
const { author, rulesOfThread } = Reply;
if (author != event.senderID)
return;
const num = parseInt(event.body || "");
if (isNaN(num) || num < 1)
return message.reply(getLang("invalidNumberView"));
const totalRules = rulesOfThread.length;
if (num > totalRules)
return message.reply(`${getLang("rulesNotExist", num)}, ${totalRules == 0 ? getLang("noRules") : getLang("numberRules", totalRules)}`);
message.reply(`${num}. ${rulesOfThread[num - 1]}`, () => message.unsend(Reply.messageID));
},
onReaction: async ({ threadsData, message, Reaction, event, getLang }) => {
const { author } = Reaction;
const { threadID, userID } = event;
if (author != userID)
return;
await threadsData.set(threadID, [], "data.rules");
message.reply(getLang("successRemove"));
}
};
|