Small fixes. Mute.js makeover

This commit is contained in:
Neko Life 2021-05-10 11:55:07 +00:00
parent 6bea0bee72
commit 21e3e48252
4 changed files with 112 additions and 66 deletions

View file

@ -1,11 +1,12 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const { getUser, trySend } = require("../../resources/functions");
const { getUser, trySend, findMemberRegEx, cleanMentionID } = require("../../resources/functions");
const { database } = require("../../database/mongo");
const { muteDurationMultiplier } = require("../../resources/date");
const col = database.collection("Guild");
const dbExp = database.collection("Experiment");
const { scheduler } = require("../../resources/scheduler");
module.exports = class mute extends commando.Command {
constructor(client) {
@ -19,79 +20,128 @@ module.exports = class mute extends commando.Command {
});
}
/**
*
* @param {commando.CommandoMessage} msg
* @param {*} arg
* @returns
*/
async run(msg, arg) {
const doc = await col.findOne({document: msg.guild.id});
const muteConf = doc?.["moderation"]?.mute;
const args = arg.trim().split(/ +/);
const setArgs = arg.trim().split(/(\-\-)+/);
/* if (config.mute.role.length === 0) {
return msg.channel.send(`Mute role isn't set! Run \`${this.client.commandPrefix}mute --role <role_[mention, ID]>\`. If you insist i will just give them admin perms <:purifyLife:774102054046007298>`)
const modConf = doc?.["moderation"];
const muteConf = modConf?.mute;
const modCase = modConf?.case;
const args = arg.trim().split(/(\-\-)+/, 5);
const mentions = args.shift().split(/,+/);
const durationRegExp = /\d+(?![^ymwdhs])[ymwdhs]?o?/gi;
const invokedAt = msg.createdAt;
const duration = {
year: invokedAt.getFullYear(),
month: invokedAt.getMonth(),
date: invokedAt.getDate(),
hour: invokedAt.getHours(),
minute: invokedAt.getMinutes(),
second: invokedAt.getSeconds()
}
if (setArgs) {
for(let set of setArgs) {
set = set.toLowerCase();
switch(set) {
case startsWith('role'): {
let role = set.slice('role'.length).trim();
if (role.startsWith('<&')) {
role = role.slice(2,-1);
}
//const foundRole =
let [timeForMessage, targetUser] = [[], []], reason = "No reason provided by " + msg.author.tag;
for (const argument of args) {
if (/^\d+(?![^ymwdhs])[ymwdhs]?o?/i.test(argument.trim())) {
const durationArg = argument.match(durationRegExp);
console.log(durationArg);
for (const value of durationArg) {
console.log(value);
const val = parseInt(value.match(/\d+/)[0], 10);
console.log(val);
if (value.endsWith("h") || value.endsWith("ho")) {
duration.hour = duration.hour + val;
timeForMessage.push(val + " Hours");
}
if (value.endsWith("y")) {
duration.year = duration.year + val;
timeForMessage.push(val + " Years");
}
if (value.endsWith("mo")) {
duration.month = duration.month + val;
timeForMessage.push(val + " Months");
}
if (value.endsWith("w")) {
duration.date = duration.date + 7 * val;
timeForMessage.push(val + " Weeks");
}
if (value.endsWith("d")) {
duration.date = duration.date + val;
timeForMessage.push(val + " Days");
}
if (value.endsWith("m") || !/\D/.test(value)) {
duration.minute = duration.minute + val;
timeForMessage.push(val + " Minutes");
}
if (value.endsWith("s")) {
duration.second = duration.second + val;
timeForMessage.push(val + " Seconds");
}
}
} else {
if (argument.length > 0 && argument !== "--") {
reason = msg.author.tag+": "+argument.trim();
}
}
}
for (const usermention of mentions) {
if (usermention.length > 0) {
let found = [];
let nameid = usermention.trim();
nameid = cleanMentionID(nameid);
if (/\D/.test(nameid)) {
found = findMemberRegEx(msg, nameid);
} else {
found.push(msg.guild.member(nameid));
if (found[0] === null) {
found = [];
found = findMemberRegEx(msg, nameid);
}
}
if (found.length > 0) {
targetUser.push(found[0].user.tag);
} else {
trySend(this.client, msg, `Can't find user: **${usermention.trim()}**`);
}
}
if (targetUser.length > 0) {
const dateDur = new Date(msg.createdAt.valueOf() + duration).toUTCString();
const newMuteSchedule = {
name: "unmute schedule " + targetUser.id,
path: "./scheduler/unmute.js",
worker: {
argv: [msg.guild.id, modCase?.length + 1 ?? 1, targetUser.id]
}
}
}
}*/
if (args[0]) {
const targetUser = await getUser(this.client, msg, args[0]);
if (targetUser) {
let duration = muteConf?.defaultDuration;
if (/^\d+(?![^ymwdhs])[ymwdhs]?o?/i.test(args[1])) {
duration = 0;
const durationRegExp = /\d+(?![^ymwdhs])[ymwdhs]?o?/gi;
const durationArg = args[1].match(durationRegExp);
for (const value of durationArg) {
//console.log(value);
if (value.endsWith("h") || value.endsWith("ho")) {
duration = muteDurationMultiplier(duration, value, 60 * 60 * 1000);
}
if (value.endsWith("y")) {
duration = muteDurationMultiplier(duration, value, 365 * 24 * 60 * 60 * 1000);
}
if (value.endsWith("mo")) {
duration = muteDurationMultiplier(duration, value, 30 * 24 * 60 * 60 * 1000)
}
if (value.endsWith("w")) {
duration = muteDurationMultiplier(duration, value, 7 * 24 * 60 * 60 * 1000)
}
if (value.endsWith("d")) {
duration = muteDurationMultiplier(duration, value, 24 * 60 * 60 * 1000)
}
if (value.endsWith("m")) {
duration = muteDurationMultiplier(duration, value, 60 * 1000)
}
if (value.endsWith("s")) {
duration = muteDurationMultiplier(duration, value, 1000)
}
if (!/\D/.test(value)) {
duration = muteDurationMultiplier(duration, value, 1000)
}
const testdate = new Date(String(duration.year), String(duration.month), String(duration.date), String(duration.hour), String(duration.minute), String(duration.second));
return trySend(this.client, msg, `Result:\`\`\`js\n${targetUser}\n${reason}\n${invokedAt.toUTCString()}\n${testdate.toUTCString()}\nMuted for: ${timeForMessage.join(" + ")}\`\`\``);
}
};
/* if (config.mute.role.length === 0) {
return msg.channel.send(`Mute role isn't set! Run \`${this.client.commandPrefix}mute --role <role_[mention, ID]>\`. If you insist i will just give them admin perms <:purifyLife:774102054046007298>`)
}
if (setArgs) {
for(let set of setArgs) {
set = set.toLowerCase();
switch(set) {
case startsWith('role'): {
let role = set.slice('role'.length).trim();
if (role.startsWith('<&')) {
role = role.slice(2,-1);
}
//const foundRole =
}
}
const dateDur = new Date(msg.createdAt.valueOf() + duration).toUTCString();
}
}*/
//scheduler.add()
/*const yearDate = dateDur.getFullYear();
const monthDate = dateDur.getMonth();
const dayDate = dateDur.getDay();
const hourDate = dateDur.getHours();
const minuteDate = dateDur.getMinutes();
const secondDate = dateDur.getSeconds();*/
return trySend(this.client, msg, `Result:\`\`\`js\n${duration} ms\n${dateDur}\`\`\``);
}
} else
return trySend(this.client, msg, "No user with that ID.");
}
}
};
const secondDate = dateDur.getSeconds();*/

View file

@ -281,7 +281,6 @@ module.exports = class embmaker extends commando.Command {
if (newAttach.length > 0) {
console.log("Uploading attachments...");
}
console.log(embed);
if (editSrc) {
if (channel) {
channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg));

View file

@ -21,17 +21,14 @@ module.exports = class uinfo extends commando.Command {
} else {
profile = msg.author;
}
const member = await msg.guild.member(profile);
const member = msg.guild.member(profile);
let result = 'User: '+profile.tag+'```js\n';
if (profile) {
console.log(profile);
result = result+JSON.stringify(profile).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
}
if (member) {
console.log(member);
result = result+'As member: '+member.displayName+'```js\n'+JSON.stringify(member).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
if ((member.displayColor)) {
console.log(member.displayColor);
result = result+'Display color:```js\n'+member.displayColor+'```';
}
}

View file

@ -3,7 +3,7 @@
const bree = require("bree");
const cabin = require("cabin");
module.exports.schedule = new bree({
module.exports.scheduler = new bree({
// logger: new cabin(),
root: false,
workerMessageHandler: () => console.log,