mirror of
https://github.com/danbulant/Shasha
synced 2026-07-05 02:50:49 +00:00
created defaultDateFormat
This commit is contained in:
parent
4f7ba301af
commit
e878fa5335
6 changed files with 32 additions and 31 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const commando = require("@iceprod/discord.js-commando");
|
const commando = require("@iceprod/discord.js-commando");
|
||||||
const { trySend, findMemberRegEx, cleanMentionID, findChannelRegEx, findRoleRegEx, defaultImageEmbed, parseDoubleDash, parseComa, getRole, defaultEventLogEmbed } = require("../../resources/functions");
|
const { trySend, findMemberRegEx, cleanMentionID, findChannelRegEx, findRoleRegEx, defaultImageEmbed, parseDoubleDash, parseComa, getRole, defaultEventLogEmbed, defaultDateFormat } = require("../../resources/functions");
|
||||||
const { database } = require("../../database/mongo");
|
const { database } = require("../../database/mongo");
|
||||||
const col = database.collection("Guild");
|
const col = database.collection("Guild");
|
||||||
const schedule = database.collection("Schedule");
|
const schedule = database.collection("Schedule");
|
||||||
|
|
@ -113,7 +113,8 @@ module.exports = class mute extends commando.Command {
|
||||||
} else return trySend(this.client, msg, "Args: `<[user_[mention|ID|name]]> -- [reason] -- [duration]`. Use `,` to provide multiple user. `--s` to view settings.\nExample:```js\n" + `${msg.guild.commandPrefix + this.name} 580703409934696449, @Shasha#1234, ur mom,#6969,^yuck\\s(ur)?\\s.{5}#\\d+69$--69y69mo69w420d420h420m420s -- Saying "joe"\`\`\``);
|
} else return trySend(this.client, msg, "Args: `<[user_[mention|ID|name]]> -- [reason] -- [duration]`. Use `,` to provide multiple user. `--s` to view settings.\nExample:```js\n" + `${msg.guild.commandPrefix + this.name} 580703409934696449, @Shasha#1234, ur mom,#6969,^yuck\\s(ur)?\\s.{5}#\\d+69$--69y69mo69w420d420h420m420s -- Saying "joe"\`\`\``);
|
||||||
|
|
||||||
if (targetUsers.length > 0) {
|
if (targetUsers.length > 0) {
|
||||||
let muted = [], cant = [], already = [], infractionN = [];
|
let muted = [], cant = [], already = [], infractionN = [],
|
||||||
|
infractionToDoc = createInfraction(msg, targetUsers, "mute", reason);
|
||||||
|
|
||||||
for (const EXEC of targetUsers) {
|
for (const EXEC of targetUsers) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -127,14 +128,12 @@ module.exports = class mute extends commando.Command {
|
||||||
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", duration.invoked.toFormat(fn.DT_PRINT_FORMAT), true)
|
.addField("At", defaultDateFormat(duration.invoked), true)
|
||||||
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
||||||
.addField("Until", duration.until?.toFormat(fn.DT_PRINT_FORMAT) || "Never", true);
|
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true);
|
||||||
EXEC.createDM().then(r => trySend(msg.client, r, emb));
|
EXEC.createDM().then(r => trySend(msg.client, r, emb));
|
||||||
}
|
}
|
||||||
|
|
||||||
let infractionToDoc = createInfraction(msg, targetUsers, "mute", reason);
|
|
||||||
|
|
||||||
infractionToDoc.executed = muted;
|
infractionToDoc.executed = muted;
|
||||||
infractionToDoc.aborted = already;
|
infractionToDoc.aborted = already;
|
||||||
infractionToDoc.failed = cant;
|
infractionToDoc.failed = cant;
|
||||||
|
|
@ -163,10 +162,9 @@ module.exports = class mute extends commando.Command {
|
||||||
if (mutedArr.length > 0) mutedStr += `and ${mutedArr.length} more...`;
|
if (mutedArr.length > 0) mutedStr += `and ${mutedArr.length} more...`;
|
||||||
emb.setDescription("**Reason**\n" + reason)
|
emb.setDescription("**Reason**\n" + reason)
|
||||||
.addField("Muted", mutedStr || "`[NONE]`")
|
.addField("Muted", mutedStr || "`[NONE]`")
|
||||||
.addField("At", duration.invoked.toFormat(fn.DT_PRINT_FORMAT), true)
|
.addField("At", defaultDateFormat(duration.invoked), true)
|
||||||
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
.addField("For", duration.duration?.strings.join(" ") || "Indefinite", true)
|
||||||
.addField("Until", duration.until?.toFormat(fn.DT_PRINT_FORMAT) || "Never", true)
|
.addField("Until", duration.until ? defaultDateFormat(duration.until) : "Never", true);
|
||||||
.addField("Reason", reason);
|
|
||||||
|
|
||||||
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
return trySend(msg.client, msg, { content: resultMsg, embed: emb });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
const commando = require("@iceprod/discord.js-commando");
|
const commando = require("@iceprod/discord.js-commando");
|
||||||
const { MessageEmbed, User, Message } = require("discord.js");
|
const { MessageEmbed, User, Message } = require("discord.js");
|
||||||
const { DateTime, Interval } = require("luxon");
|
const { DateTime, Interval } = require("luxon");
|
||||||
const { errLog, trySend, getUser, defaultImageEmbed, splitOnLength } = require("../../resources/functions");
|
const { errLog, trySend, getUser, defaultImageEmbed, splitOnLength, defaultDateFormat } = require("../../resources/functions");
|
||||||
const getColor = require("../../resources/getColor");
|
const getColor = require("../../resources/getColor");
|
||||||
const { DT_PRINT_FORMAT, intervalToDuration } = require("../moderation/src/duration");
|
const { DT_PRINT_FORMAT, intervalToDuration } = require("../moderation/src/duration");
|
||||||
|
|
||||||
|
|
@ -32,12 +32,12 @@ module.exports = class profile extends commando.Command {
|
||||||
emb
|
emb
|
||||||
.setThumbnail(TM.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
.setThumbnail(TM.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
||||||
.addField("ID", TM.id)
|
.addField("ID", TM.id)
|
||||||
.addField("Registered", "<t:" + (Math.floor(TM.createdAt.valueOf() / 1000)) + ":F>");
|
.addField("Registered", defaultDateFormat(TM.createdAt));
|
||||||
if (TM.description) emb.setDescription(TM.description);
|
if (TM.description) emb.setDescription(TM.description);
|
||||||
if (MEM) {
|
if (MEM) {
|
||||||
const RI = MEM.roles.cache.sort((a, b) => b.position - a.position).map(r => r.id).slice(0, -1),
|
const RI = MEM.roles.cache.sort((a, b) => b.position - a.position).map(r => r.id).slice(0, -1),
|
||||||
RFS = splitOnLength(RI, 1010, ">, <@&"), INT = Interval.fromDateTimes(DateTime.fromJSDate(MEM.joinedAt), DateTime.now());
|
RFS = splitOnLength(RI, 1010, ">, <@&"), INT = Interval.fromDateTimes(DateTime.fromJSDate(MEM.joinedAt), DateTime.now());
|
||||||
emb.addField("Joined", "<t:" + (Math.floor(MEM.joinedAt.valueOf() / 1000)) + `:F>\n(${intervalToDuration(INT).strings.join(" ")} ago)`)
|
emb.addField("Joined", defaultDateFormat(MEM.joinedAt) + `\n(${intervalToDuration(INT).strings.join(" ")} ago)`)
|
||||||
.addField("Nick", `\`${MEM.displayName}\``);
|
.addField("Nick", `\`${MEM.displayName}\``);
|
||||||
if (RFS[0]?.length > 0) {
|
if (RFS[0]?.length > 0) {
|
||||||
for (const p of RFS) {
|
for (const p of RFS) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const { GuildMember } = require("discord.js"),
|
const { GuildMember } = require("discord.js"),
|
||||||
{ DateTime } = require("luxon"),
|
{ DateTime } = require("luxon"),
|
||||||
{ getChannel, defaultEventLogEmbed, trySend } = require("../functions"),
|
{ getChannel, defaultEventLogEmbed, trySend, defaultDateFormat } = require("../functions"),
|
||||||
getColor = require("../getColor"),
|
getColor = require("../getColor"),
|
||||||
{ DT_PRINT_FORMAT } = require("../../cmds/moderation/src/duration");
|
{ DT_PRINT_FORMAT } = require("../../cmds/moderation/src/duration");
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ module.exports = (member) => {
|
||||||
.setTitle("`" + member.user.tag + "` joined")
|
.setTitle("`" + member.user.tag + "` joined")
|
||||||
.setThumbnail(member.user.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
.setThumbnail(member.user.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
||||||
.setColor(getColor("cyan"))
|
.setColor(getColor("cyan"))
|
||||||
.addField("Registered", "<t:" + (Math.floor(member.user.createdAt.valueOf() / 1000)) + ":F>", true)
|
.addField("Registered", defaultDateFormat(member.user.createdAt), true)
|
||||||
.setDescription(`<@!${member.id}> (${member.id}) just joined.\nWe have ${member.guild.memberCount} total members now.`);
|
.setDescription(`<@!${member.id}> (${member.id}) just joined.\nWe have ${member.guild.memberCount} total members now.`);
|
||||||
return trySend(member.client, log, emb);
|
return trySend(member.client, log, emb);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
const { GuildMember } = require("discord.js");
|
const { GuildMember } = require("discord.js");
|
||||||
const { DateTime, Interval, Settings } = require("luxon");
|
const { DateTime, Interval, Settings } = require("luxon");
|
||||||
const { DT_PRINT_FORMAT, intervalToDuration } = require("../../cmds/moderation/src/duration");
|
const { DT_PRINT_FORMAT, intervalToDuration } = require("../../cmds/moderation/src/duration");
|
||||||
const { getChannel, defaultEventLogEmbed, trySend, splitOnLength } = require("../functions");
|
const { getChannel, defaultEventLogEmbed, trySend, splitOnLength, defaultDateFormat } = require("../functions");
|
||||||
const getColor = require("../getColor");
|
const getColor = require("../getColor");
|
||||||
Settings.defaultZone = "utc";
|
Settings.defaultZone = "utc";
|
||||||
|
|
||||||
|
|
@ -24,8 +24,8 @@ module.exports = (member) => {
|
||||||
.setTitle("`" + member.user.tag + "` left")
|
.setTitle("`" + member.user.tag + "` left")
|
||||||
.setThumbnail(member.user.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
.setThumbnail(member.user.displayAvatarURL({ format: "png", size: 4096, dynamic: true }))
|
||||||
.setColor(getColor("yellow"))
|
.setColor(getColor("yellow"))
|
||||||
.addField("Registered", "<t:" + (Math.floor(member.user.createdAt.valueOf() / 1000)) + ":F>", true)
|
.addField("Registered", defaultDateFormat(member.user.createdAt), true)
|
||||||
.addField("Joined", "<t:" + (Math.floor(member.joinedAt.valueOf() / 1000)) + `:F>\n(${intervalToDuration(INT).strings.join(" ")} ago)`, true)
|
.addField("Joined", defaultDateFormat(member.joinedAt) + `\n(${intervalToDuration(INT).strings.join(" ")} ago)`, true)
|
||||||
.addField("Nick", "`" + member.displayName + "`")
|
.addField("Nick", "`" + member.displayName + "`")
|
||||||
.setDescription(`<@!${member.id}> (${member.id}) just left.\nWe have ${member.guild.memberCount} total members now.`);
|
.setDescription(`<@!${member.id}> (${member.id}) just left.\nWe have ${member.guild.memberCount} total members now.`);
|
||||||
for (const U of RU) {
|
for (const U of RU) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const { timestampAt } = require('./debug');
|
||||||
const getColor = require('./getColor');
|
const getColor = require('./getColor');
|
||||||
const { randomColors } = require("../config.json");
|
const { randomColors } = require("../config.json");
|
||||||
const { CommandoMessage, CommandoClient } = require('@iceprod/discord.js-commando');
|
const { CommandoMessage, CommandoClient } = require('@iceprod/discord.js-commando');
|
||||||
|
const { DateTime } = require('luxon');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log an error. Second or third argument is required
|
* Log an error. Second or third argument is required
|
||||||
|
|
@ -519,6 +520,18 @@ function getRole(guild, key) {
|
||||||
|
|
||||||
function wait(ms) { return new Promise(r => setTimeout(() => r(), ms)) }
|
function wait(ms) { return new Promise(r => setTimeout(() => r(), ms)) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Date|DateTime|number|string} date - Number | String must be in miliseconds
|
||||||
|
* @returns {string} - Discord format ready to use
|
||||||
|
*/
|
||||||
|
function defaultDateFormat(date) {
|
||||||
|
let use;
|
||||||
|
if ((date instanceof Date) || date instanceof DateTime) use = date.valueOf();
|
||||||
|
else if (typeof date === "string") use = parseInt(date, 10);
|
||||||
|
else use = date;
|
||||||
|
return "<t:" + (Math.floor(use / 1000)) + ":F>";
|
||||||
|
}
|
||||||
|
|
||||||
const defaultSplitMessage = { maxLength: 2000, char: ",", append: ',```', prepend: '```js\n' };
|
const defaultSplitMessage = { maxLength: 2000, char: ",", append: ',```', prepend: '```js\n' };
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cleanMentionID, defaultEventLogEmbed,
|
cleanMentionID, defaultEventLogEmbed,
|
||||||
|
|
@ -526,7 +539,7 @@ module.exports = {
|
||||||
findMemberRegEx, findChannelRegEx, findRoleRegEx,
|
findMemberRegEx, findChannelRegEx, findRoleRegEx,
|
||||||
getChannelMessage, errLog,
|
getChannelMessage, errLog,
|
||||||
execCB, ranLog, noPerm, getUTCComparison,
|
execCB, ranLog, noPerm, getUTCComparison,
|
||||||
trySend, tryDelete, tryReact,
|
trySend, tryDelete, tryReact, defaultDateFormat,
|
||||||
adCheck, defaultImageEmbed, getChannel,
|
adCheck, defaultImageEmbed, getChannel,
|
||||||
splitOnLength, parseComa, parseDoubleDash, getMember,
|
splitOnLength, parseComa, parseDoubleDash, getMember,
|
||||||
parseDash, reValidURL, getUser, getRole, wait, defaultSplitMessage
|
parseDash, reValidURL, getUser, getRole, wait, defaultSplitMessage
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ Structures.extend("User", u => {
|
||||||
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) 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");
|
||||||
}
|
}
|
||||||
|
|
@ -350,18 +350,11 @@ Structures.extend("GuildMember", u => {
|
||||||
try {
|
try {
|
||||||
if (ROLES?.length > 0) await this.roles.remove(ROLES, reason);
|
if (ROLES?.length > 0) await this.roles.remove(ROLES, reason);
|
||||||
await this.roles.add(this.DB.muteRole, reason);
|
await this.roles.add(this.DB.muteRole, reason);
|
||||||
const ret = this.user.pushMutedIn(this.guild.id, {
|
|
||||||
state: true,
|
|
||||||
duration: data.duration,
|
|
||||||
infraction: data.infraction
|
|
||||||
});
|
|
||||||
this.setDb(this.DB);
|
this.setDb(this.DB);
|
||||||
this.user.setDb(this.user.DB);
|
return true;
|
||||||
return ret;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (this.DB.takenRoles?.length > 0) await this.roles.add(this.DB.takenRoles, reason).catch(() => { });
|
if (this.DB.takenRoles?.length > 0) await this.roles.add(this.DB.takenRoles, reason).catch(() => { });
|
||||||
if (this.DB.muteRole) await this.roles.remove(this.DB.muteRole, reason).catch(() => { });
|
if (this.DB.muteRole) await this.roles.remove(this.DB.muteRole, reason).catch(() => { });
|
||||||
this.user.removeMutedIn(this.guild.id);
|
|
||||||
console.log("clear takenRoles M");
|
console.log("clear takenRoles M");
|
||||||
this.DB.takenRoles = [];
|
this.DB.takenRoles = [];
|
||||||
this.DB.muteRole = undefined;
|
this.DB.muteRole = undefined;
|
||||||
|
|
@ -371,17 +364,14 @@ Structures.extend("GuildMember", u => {
|
||||||
|
|
||||||
async unmute(reason) {
|
async unmute(reason) {
|
||||||
if (!this.DB) await this.dbLoad();
|
if (!this.DB) await this.dbLoad();
|
||||||
if (!this.user.DB) await this.user.dbLoad();
|
|
||||||
try {
|
try {
|
||||||
if (this.DB.takenRoles.length > 0) await this.roles.add(this.DB.takenRoles, reason);
|
if (this.DB.takenRoles.length > 0) await this.roles.add(this.DB.takenRoles, reason);
|
||||||
if (this.DB.muteRole) await this.roles.remove(this.DB.muteRole, reason);
|
if (this.DB.muteRole) await this.roles.remove(this.DB.muteRole, reason);
|
||||||
const ret = this.user.removeMutedIn(this.guild.id);
|
|
||||||
console.log("clear takenRoles UM");
|
console.log("clear takenRoles UM");
|
||||||
this.DB.takenRoles = [];
|
this.DB.takenRoles = [];
|
||||||
this.DB.muteRole = undefined;
|
this.DB.muteRole = undefined;
|
||||||
this.setDb(this.DB);
|
this.setDb(this.DB);
|
||||||
this.user.setDb(this.user.DB)
|
return true;
|
||||||
return ret;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue