Mute: Methods written

This commit is contained in:
Neko-Life 2021-07-14 14:14:38 +07:00
parent 702c719833
commit 7a0cad4bfe

View file

@ -4,8 +4,8 @@ const { Structures } = require("discord.js"),
{ database } = require("../database/mongo"), { database } = require("../database/mongo"),
{ errLog } = require("./functions"); { errLog } = require("./functions");
Structures.extend("Guild", g => { Structures.extend("Guild", u => {
return class Guild extends g { return class Guild extends u {
constructor(client, data) { constructor(client, data) {
super(client, data); super(client, data);
} }
@ -30,7 +30,7 @@ Structures.extend("Guild", g => {
/** /**
* Get user infractions * Get user infractions
* @param {String} get - User ID * @param {String} get - User ID
* @returns {Promise<Object[]>} Infractions object * @returns {Promise<Object[]>} Array of infractions objects
*/ */
async getInfractions(get) { async getInfractions(get) {
try { try {
@ -136,8 +136,8 @@ Structures.extend("User", u => {
} }
}); });
Structures.extend("TextChannel", e => { Structures.extend("TextChannel", u => {
return class TextChannel extends e { return class TextChannel extends u {
constructor(guild, data) { constructor(guild, data) {
super(guild, data); super(guild, data);
this.lastMessagesID = []; this.lastMessagesID = [];
@ -152,8 +152,8 @@ Structures.extend("TextChannel", e => {
} }
}); });
Structures.extend("DMChannel", e => { Structures.extend("DMChannel", u => {
return class DMChannel extends e { return class DMChannel extends u {
constructor(client, data) { constructor(client, data) {
super(client, data); super(client, data);
this.lastMessagesID = []; this.lastMessagesID = [];
@ -181,8 +181,8 @@ Structures.extend("Message", e => {
}; };
}); });
Structures.extend("GuildMember", e => { Structures.extend("GuildMember", u => {
return class GuildMember extends e { return class GuildMember extends u {
constructor(client, data, guild) { constructor(client, data, guild) {
super(client, data, guild); super(client, data, guild);
} }
@ -208,8 +208,48 @@ Structures.extend("GuildMember", e => {
return this.guild.getInfractions(this.id); return this.guild.getInfractions(this.id);
} }
async mute() { /**
* @param {Date | number} until
* @returns
*/
async mute(until) {
if (!this.DB) await this.dbLoad();
if (!this.guild.DB) await this.guild.dbLoad();
this.DB.takenRoles = this.roles.cache.map(r => r.id);
this.DB.muteRole = this.guild.DB.moderation.settings.mute.role;
if ((typeof until) === "number") until = new Date(until);
try {
const RM = await this.roles.remove(this.DB.takenRoles);
await RM.roles.add(this.DB.muteRole);
this.DB.muted = {
state: true,
until: until
};
return this.setDb(this.DB);
} catch (e) {
if (this.DB.takenRoles?.length > 0) this.roles.add(this.DB.takenRoles).catch(() => { });
this.DB.takenRoles = [];
this.DB.muteRole = undefined;
this.DB.muted = { state: false };
const R = await this.setDb(this.DB);
if (e) throw e;
return R;
}
}
async unmute() {
if (!this.DB) await this.dbLoad();
try {
const RM = await this.roles.add(this.DB.takenRoles);
await RM.roles.remove(this.DB.muteRole);
this.DB.takenRoles = [];
this.DB.muteRole = undefined;
this.DB.muted = { state: false };
return this.setDb(this.DB);
} catch (e) {
if (e) throw e;
return;
}
} }
} }
}); });