mirror of
https://github.com/danbulant/Shasha
synced 2026-07-08 04:21:06 +00:00
saves
This commit is contained in:
parent
d21c564ba8
commit
5a6de7b981
6 changed files with 47 additions and 43 deletions
|
|
@ -124,15 +124,15 @@ module.exports = class mute extends commando.Command {
|
||||||
muted.push(EXEC.id);
|
muted.push(EXEC.id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (/Missing Permissions|someone with higher position/.test(e.message)) cant.push(EXEC.id);
|
if (/Missing Permissions|someone with higher position/.test(e.message)) cant.push(EXEC.id);
|
||||||
else if (/already muted/.test(e.message)) already.push(EXEC.id); else trySend(msg.client, msg, e.message); continue;
|
else if (/already muted/.test(e.message)) already.push(EXEC.id); else console.log(e); continue;
|
||||||
}
|
}
|
||||||
if (!EXEC.bot) {
|
if (!EXEC.bot) {
|
||||||
const emb = defaultEventLogEmbed(msg.guild);
|
const emb = defaultEventLogEmbed(msg.guild);
|
||||||
emb.setTitle("You have been muted")
|
emb.setTitle("You have been muted")
|
||||||
.setDescription("**Reason**\n" + reason)
|
.setDescription("**Reason**\n" + reason)
|
||||||
.addField("At", defaultDateFormat(duration.invoked), true)
|
.addField("At", defaultDateFormat(duration.invoked), true)
|
||||||
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true)
|
||||||
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true);
|
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true);
|
||||||
EXEC.createDM().then(r => trySend(msg.client, r, emb));
|
EXEC.createDM().then(r => trySend(msg.client, r, emb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +154,6 @@ module.exports = class mute extends commando.Command {
|
||||||
};
|
};
|
||||||
|
|
||||||
let emb = defaultImageEmbed(msg, null, "Infraction #" + infractionToDoc.infraction);
|
let emb = defaultImageEmbed(msg, null, "Infraction #" + infractionToDoc.infraction);
|
||||||
|
|
||||||
if (cant.length > 0) emb.addField("Can't mute", "<@" + cant.join(">, <@") + ">\n\n**You can't mute someone with higher position than you <:nekokekLife:852865942530949160>**");
|
|
||||||
if (already.length > 0) emb.addField("Already muted", "<@" + already.join(">, <@") + ">\n\nDuration updated for these users");
|
|
||||||
let mutedStr = "", mutedArr = [];
|
let mutedStr = "", mutedArr = [];
|
||||||
if (muted.length > 0) for (const U of muted) {
|
if (muted.length > 0) for (const U of muted) {
|
||||||
const tU = "<@" + U + ">\n";
|
const tU = "<@" + U + ">\n";
|
||||||
|
|
@ -166,8 +163,11 @@ module.exports = class mute extends commando.Command {
|
||||||
emb.setDescription("**Reason**\n" + reason)
|
emb.setDescription("**Reason**\n" + reason)
|
||||||
.addField("Muted", mutedStr || "`[NONE]`")
|
.addField("Muted", mutedStr || "`[NONE]`")
|
||||||
.addField("At", defaultDateFormat(duration.invoked), true)
|
.addField("At", defaultDateFormat(duration.invoked), true)
|
||||||
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true)
|
||||||
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true);
|
.addField("For", duration.duration?.strings.join(" ") || "Indefinite");
|
||||||
|
|
||||||
|
if (cant.length > 0) emb.addField("Can't mute", "<@" + cant.join(">, <@") + ">\n\n**You can't mute someone with higher position than you <:nekokekLife:852865942530949160>**");
|
||||||
|
if (already.length > 0) emb.addField("Already muted", "<@" + already.join(">, <@") + ">\n\nDuration updated for these users");
|
||||||
|
|
||||||
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const { Message, User } = require("discord.js");
|
||||||
module.exports = (msg, targetUsers, punishment, reason) => {
|
module.exports = (msg, targetUsers, punishment, reason) => {
|
||||||
let infractionCase = msg.guild.DB.infractions.size;
|
let infractionCase = msg.guild.DB.infractions.size;
|
||||||
return {
|
return {
|
||||||
infraction: infractionCase ? infractionCase++ : 1,
|
infraction: infractionCase ? ++infractionCase : 1,
|
||||||
by: targetUsers,
|
by: targetUsers,
|
||||||
moderator: msg.author,
|
moderator: msg.author,
|
||||||
punishment: punishment,
|
punishment: punishment,
|
||||||
|
|
|
||||||
|
|
@ -13,33 +13,32 @@ const { cleanMentionID, findMemberRegEx } = require("../../../resources/function
|
||||||
module.exports = async (msg, mentions = [], targetUser = [], resultMsg = "") => {
|
module.exports = async (msg, mentions = [], targetUser = [], resultMsg = "") => {
|
||||||
if (mentions.length === 0) throw new TypeError("Mentions has no length");
|
if (mentions.length === 0) throw new TypeError("Mentions has no length");
|
||||||
for (const usermention of mentions) {
|
for (const usermention of mentions) {
|
||||||
if (usermention.length > 0) {
|
if (usermention.trim().length < 1) continue;
|
||||||
let found = [],
|
let found = [],
|
||||||
nameid = cleanMentionID(usermention);
|
nameid = cleanMentionID(usermention);
|
||||||
if (/^\d{17,19}$/.test(nameid)) {
|
if (/^\d{17,19}$/.test(nameid)) {
|
||||||
const findmem = msg.guild.member(nameid);
|
const findmem = msg.guild.member(nameid);
|
||||||
if (findmem) {
|
if (findmem) {
|
||||||
found.push(findmem.user);
|
found.push(findmem.user);
|
||||||
} else {
|
|
||||||
await msg.client.users.fetch(nameid).then(fetchUser => found.push(fetchUser)).catch(() => { });
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
found = findMemberRegEx(msg, nameid).map(r => r.user);
|
await msg.client.users.fetch(nameid).then(fetchUser => found.push(fetchUser)).catch(() => { });
|
||||||
}
|
}
|
||||||
if (found.length > 0 && found[0] !== null) {
|
} else {
|
||||||
const foundDupli = targetUser.findIndex(r => r === found[0]);
|
found = findMemberRegEx(msg, nameid)?.map(r => r.user);
|
||||||
if (foundDupli !== -1) {
|
}
|
||||||
resultMsg += `**[WARNING]** Duplicate for user **${targetUser[foundDupli].tag}** with keyword: **${usermention.trim()}**\n`;
|
if (found?.length > 0 && found[0] !== null) {
|
||||||
} else {
|
const foundDupli = targetUser.findIndex(r => r === found[0]);
|
||||||
targetUser.push(found[0]);
|
if (foundDupli !== -1) {
|
||||||
if (found.length > 1) {
|
resultMsg += `**[WARNING]** Duplicate for user **${targetUser[foundDupli].tag}** with keyword: **${usermention.trim()}**\n`;
|
||||||
resultMsg += `**[WARNING]** Multiple users found for: **${usermention.trim()}**\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
resultMsg += `Can't find user: **${usermention.trim()}**\n`;
|
targetUser.push(found[0]);
|
||||||
|
if (found.length > 1) {
|
||||||
|
resultMsg += `**[WARNING]** Multiple users found for: **${usermention.trim()}**\n`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else continue;
|
} else {
|
||||||
|
resultMsg += `Can't find user: **${usermention.trim()}**\n`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { targetUser, resultMsg };
|
return { targetUser, resultMsg };
|
||||||
}
|
}
|
||||||
|
|
@ -60,10 +60,10 @@ module.exports = class unmute extends commando.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
let emb = defaultImageEmbed(msg, null, "Unmute");
|
let emb = defaultImageEmbed(msg, null, "Unmute");
|
||||||
|
emb.setDescription("**Reason**\n" + reason)
|
||||||
|
.addField("Unmuted", (success.length > 0 ? "<@" + success.join(">, <@") + ">" : "`[NONE]`"));
|
||||||
if (cant.length > 0) emb.addField("Can't unmute", "<@" + cant.join(">, <@") + ">");
|
if (cant.length > 0) emb.addField("Can't unmute", "<@" + cant.join(">, <@") + ">");
|
||||||
if (notMuted.length > 0) emb.addField("Wasn't muted", "<@" + notMuted.join(">, <@") + ">");
|
if (notMuted.length > 0) emb.addField("Wasn't muted", "<@" + notMuted.join(">, <@") + ">");
|
||||||
emb.setDescription("**Unmuted**\n" + (success.length > 0 ? "<@" + success.join(">, <@") + ">" : "`[NONE]`"))
|
|
||||||
.addField("Reason", reason);
|
|
||||||
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ module.exports = class perms extends commando.Command {
|
||||||
run(msg, arg) {
|
run(msg, arg) {
|
||||||
let member, channel, mes = "";
|
let member, channel, mes = "";
|
||||||
if (arg) {
|
if (arg) {
|
||||||
const forC = arg.match(/(?<!\\)--c [^ ]*/)?.[0];
|
const forC = arg.match(/(?<!\\)--ch [^ ]*/)?.[0];
|
||||||
if (forC) {
|
if (forC) {
|
||||||
const use = forC.slice(4).trim();
|
const use = forC.slice(4).trim();
|
||||||
channel = getChannel(msg, use);
|
channel = getChannel(msg, use);
|
||||||
|
|
@ -66,7 +66,7 @@ module.exports = class perms extends commando.Command {
|
||||||
}
|
}
|
||||||
const title = `Permissions for: \`${member.user.tag}\``;
|
const title = `Permissions for: \`${member.user.tag}\``;
|
||||||
mes += `**Default:**\`\`\`js\n`;
|
mes += `**Default:**\`\`\`js\n`;
|
||||||
if (msg.member.isAdmin) mes += "'ADMINISTRATOR', ";
|
if (member.isAdmin) mes += "'ADMINISTRATOR', ";
|
||||||
if (res.length > 0) {
|
if (res.length > 0) {
|
||||||
mes += `${res.join(", ")}\`\`\``;
|
mes += `${res.join(", ")}\`\`\``;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,17 @@ Structures.extend("Guild", u => {
|
||||||
async dbLoad() {
|
async dbLoad() {
|
||||||
return database.collection("Guild").findOne({ document: this.id }).then((r, e) => {
|
return database.collection("Guild").findOne({ document: this.id }).then((r, e) => {
|
||||||
if (e) return errLog(e, null, this.client);
|
if (e) return errLog(e, null, this.client);
|
||||||
|
console.log(r);
|
||||||
if (!r) r = {};
|
if (!r) r = {};
|
||||||
if (!r.eventChannels) r.eventChannels = {};
|
if (!r.eventChannels) r.eventChannels = {};
|
||||||
if (!r.settings) r.settings = {};
|
if (!r.settings) r.settings = {};
|
||||||
let infractions = new Map(),
|
let infractions = new Map(),
|
||||||
timedPunishments = new Map();
|
timedPunishments = new Map();
|
||||||
if (r.infractions)
|
if (r.infractions)
|
||||||
for (const U in r.infractions)
|
for (const U in r.infractions) {
|
||||||
|
console.log(r.infractions[U]);
|
||||||
infractions.set(U, r.infractions[U]);
|
infractions.set(U, r.infractions[U]);
|
||||||
|
}
|
||||||
if (r.timedPunishments)
|
if (r.timedPunishments)
|
||||||
for (const U in r.timedPunishments) {
|
for (const U in r.timedPunishments) {
|
||||||
const tr = new TimedPunishment(r.timedPunishments[U]);
|
const tr = new TimedPunishment(r.timedPunishments[U]);
|
||||||
|
|
@ -58,9 +61,10 @@ Structures.extend("Guild", u => {
|
||||||
try {
|
try {
|
||||||
if (!this.DB) await this.dbLoad();
|
if (!this.DB) await this.dbLoad();
|
||||||
console.log("SETTING INF");
|
console.log("SETTING INF");
|
||||||
const ret = this.DB.infractions.set(add.infraction, add);
|
const ret = this.DB.infractions.set(add.moderator.id + "/" + add.infraction, add);
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
await this.setDb("infractions", this.DB.infractions);
|
await this.setDb("infractions", this.DB.infractions);
|
||||||
|
console.log(ret);
|
||||||
return ret;
|
return ret;
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
@ -197,7 +201,7 @@ Structures.extend("User", u => {
|
||||||
if (!guild.DB) await guild.dbLoad();
|
if (!guild.DB) await guild.dbLoad();
|
||||||
const MEM = guild.member(this);
|
const MEM = guild.member(this);
|
||||||
if (MEM) {
|
if (MEM) {
|
||||||
if (data.moderator.roles.highest.position < MEM.roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>");
|
if (data.moderator.roles.highest.position < MEM.roles.highest.position || MEM.roles.highest.position > guild.member(this.client.user).roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>");
|
||||||
await MEM.mute(data, reason);
|
await MEM.mute(data, reason);
|
||||||
}
|
}
|
||||||
const MC = guild.getTimedPunishment(this.id, "mute"),
|
const MC = guild.getTimedPunishment(this.id, "mute"),
|
||||||
|
|
@ -212,7 +216,7 @@ Structures.extend("User", u => {
|
||||||
if (!MC) throw new Error(this.tag + " isn't muted in " + guild.name);
|
if (!MC) throw new Error(this.tag + " isn't muted in " + guild.name);
|
||||||
const MEM = guild.member(this);
|
const MEM = guild.member(this);
|
||||||
if (MEM) {
|
if (MEM) {
|
||||||
if (moderator.roles.highest.position < MEM.roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>");
|
if (moderator.roles.highest.position < MEM.roles.highest.position || MEM.roles.highest.position > guild.member(this.client.user).roles.highest.position) throw new Error("You can't mute someone with higher position than you <:nekokekLife:852865942530949160>");
|
||||||
await MEM.unmute(reason);
|
await MEM.unmute(reason);
|
||||||
}
|
}
|
||||||
return guild.removeTimedPunishment(this.id, "mute");
|
return guild.removeTimedPunishment(this.id, "mute");
|
||||||
|
|
@ -308,14 +312,15 @@ Structures.extend("GuildMember", u => {
|
||||||
async mute(data, reason) {
|
async mute(data, reason) {
|
||||||
if (!this.DB) await this.dbLoad();
|
if (!this.DB) await this.dbLoad();
|
||||||
if (!data || !data.infraction) throw new Error("Missing infraction id");
|
if (!data || !data.infraction) throw new Error("Missing infraction id");
|
||||||
if (data.saveTakenRoles === undefined) data.saveTakenRoles = true;
|
if (!this.DB.muted) this.DB.muted = {};
|
||||||
|
if (data.saveTakenRoles === undefined) data.saveTakenRoles = !(this.DB.muted.takenRoles?.length > 0);
|
||||||
|
|
||||||
const ROLES = this.roles.cache.filter((r) => !r.managed).map(r => r.id);
|
const ROLES = this.roles.cache.filter((r) => !r.managed).map(r => r.id);
|
||||||
if (data.saveTakenRoles && ROLES?.length > 0) {
|
if (data.saveTakenRoles && ROLES?.length > 0) {
|
||||||
console.log("populating takenRoles M");
|
console.log("populating takenRoles M");
|
||||||
this.DB.muted.takenRoles = ROLES;
|
this.DB.muted.takenRoles = ROLES;
|
||||||
}
|
}
|
||||||
this.DB.muted.muteRole = this.guild.DB.mute.role;
|
this.DB.muted.muteRole = this.guild.DB.settings.mute.role;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ROLES?.length > 0) await this.roles.remove(ROLES, reason);
|
if (ROLES?.length > 0) await this.roles.remove(ROLES, reason);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue