mirror of
https://github.com/danbulant/Shasha
synced 2026-07-05 02:50:49 +00:00
Small fixes. Mute.js makeover
This commit is contained in:
parent
6bea0bee72
commit
21e3e48252
4 changed files with 112 additions and 66 deletions
|
|
@ -1,11 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const commando = require("@iceprod/discord.js-commando");
|
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 { database } = require("../../database/mongo");
|
||||||
const { muteDurationMultiplier } = require("../../resources/date");
|
const { muteDurationMultiplier } = require("../../resources/date");
|
||||||
const col = database.collection("Guild");
|
const col = database.collection("Guild");
|
||||||
const dbExp = database.collection("Experiment");
|
const dbExp = database.collection("Experiment");
|
||||||
|
const { scheduler } = require("../../resources/scheduler");
|
||||||
|
|
||||||
module.exports = class mute extends commando.Command {
|
module.exports = class mute extends commando.Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
|
@ -19,79 +20,128 @@ module.exports = class mute extends commando.Command {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {commando.CommandoMessage} msg
|
* @param {commando.CommandoMessage} msg
|
||||||
* @param {*} arg
|
* @param {*} arg
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async run(msg, arg) {
|
async run(msg, arg) {
|
||||||
const doc = await col.findOne({document: msg.guild.id});
|
const doc = await col.findOne({document: msg.guild.id});
|
||||||
const muteConf = doc?.["moderation"]?.mute;
|
const modConf = doc?.["moderation"];
|
||||||
const args = arg.trim().split(/ +/);
|
const muteConf = modConf?.mute;
|
||||||
const setArgs = arg.trim().split(/(\-\-)+/);
|
const modCase = modConf?.case;
|
||||||
/* if (config.mute.role.length === 0) {
|
const args = arg.trim().split(/(\-\-)+/, 5);
|
||||||
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 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) {
|
let [timeForMessage, targetUser] = [[], []], reason = "No reason provided by " + msg.author.tag;
|
||||||
for(let set of setArgs) {
|
for (const argument of args) {
|
||||||
set = set.toLowerCase();
|
if (/^\d+(?![^ymwdhs])[ymwdhs]?o?/i.test(argument.trim())) {
|
||||||
switch(set) {
|
const durationArg = argument.match(durationRegExp);
|
||||||
case startsWith('role'): {
|
console.log(durationArg);
|
||||||
let role = set.slice('role'.length).trim();
|
for (const value of durationArg) {
|
||||||
if (role.startsWith('<&')) {
|
console.log(value);
|
||||||
role = role.slice(2,-1);
|
const val = parseInt(value.match(/\d+/)[0], 10);
|
||||||
}
|
console.log(val);
|
||||||
//const foundRole =
|
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 testdate = new Date(String(duration.year), String(duration.month), String(duration.date), String(duration.hour), String(duration.minute), String(duration.second));
|
||||||
const targetUser = await getUser(this.client, msg, args[0]);
|
return trySend(this.client, msg, `Result:\`\`\`js\n${targetUser}\n${reason}\n${invokedAt.toUTCString()}\n${testdate.toUTCString()}\nMuted for: ${timeForMessage.join(" + ")}\`\`\``);
|
||||||
if (targetUser) {
|
}
|
||||||
let duration = muteConf?.defaultDuration;
|
};
|
||||||
if (/^\d+(?![^ymwdhs])[ymwdhs]?o?/i.test(args[1])) {
|
|
||||||
duration = 0;
|
/* if (config.mute.role.length === 0) {
|
||||||
const durationRegExp = /\d+(?![^ymwdhs])[ymwdhs]?o?/gi;
|
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 durationArg = args[1].match(durationRegExp);
|
}
|
||||||
for (const value of durationArg) {
|
if (setArgs) {
|
||||||
//console.log(value);
|
for(let set of setArgs) {
|
||||||
if (value.endsWith("h") || value.endsWith("ho")) {
|
set = set.toLowerCase();
|
||||||
duration = muteDurationMultiplier(duration, value, 60 * 60 * 1000);
|
switch(set) {
|
||||||
}
|
case startsWith('role'): {
|
||||||
if (value.endsWith("y")) {
|
let role = set.slice('role'.length).trim();
|
||||||
duration = muteDurationMultiplier(duration, value, 365 * 24 * 60 * 60 * 1000);
|
if (role.startsWith('<&')) {
|
||||||
}
|
role = role.slice(2,-1);
|
||||||
if (value.endsWith("mo")) {
|
}
|
||||||
duration = muteDurationMultiplier(duration, value, 30 * 24 * 60 * 60 * 1000)
|
//const foundRole =
|
||||||
}
|
|
||||||
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 dateDur = new Date(msg.createdAt.valueOf() + duration).toUTCString();
|
}
|
||||||
|
}*/
|
||||||
|
//scheduler.add()
|
||||||
/*const yearDate = dateDur.getFullYear();
|
/*const yearDate = dateDur.getFullYear();
|
||||||
const monthDate = dateDur.getMonth();
|
const monthDate = dateDur.getMonth();
|
||||||
const dayDate = dateDur.getDay();
|
const dayDate = dateDur.getDay();
|
||||||
const hourDate = dateDur.getHours();
|
const hourDate = dateDur.getHours();
|
||||||
const minuteDate = dateDur.getMinutes();
|
const minuteDate = dateDur.getMinutes();
|
||||||
const secondDate = dateDur.getSeconds();*/
|
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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -281,7 +281,6 @@ module.exports = class embmaker extends commando.Command {
|
||||||
if (newAttach.length > 0) {
|
if (newAttach.length > 0) {
|
||||||
console.log("Uploading attachments...");
|
console.log("Uploading attachments...");
|
||||||
}
|
}
|
||||||
console.log(embed);
|
|
||||||
if (editSrc) {
|
if (editSrc) {
|
||||||
if (channel) {
|
if (channel) {
|
||||||
channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg));
|
channel.send({content:content,embed:embed,files:newAttach}).catch(e => noPerm(msg));
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,14 @@ module.exports = class uinfo extends commando.Command {
|
||||||
} else {
|
} else {
|
||||||
profile = msg.author;
|
profile = msg.author;
|
||||||
}
|
}
|
||||||
const member = await msg.guild.member(profile);
|
const member = msg.guild.member(profile);
|
||||||
let result = 'User: '+profile.tag+'```js\n';
|
let result = 'User: '+profile.tag+'```js\n';
|
||||||
if (profile) {
|
if (profile) {
|
||||||
console.log(profile);
|
|
||||||
result = result+JSON.stringify(profile).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
|
result = result+JSON.stringify(profile).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
|
||||||
}
|
}
|
||||||
if (member) {
|
if (member) {
|
||||||
console.log(member);
|
|
||||||
result = result+'As member: '+member.displayName+'```js\n'+JSON.stringify(member).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
|
result = result+'As member: '+member.displayName+'```js\n'+JSON.stringify(member).split(',"').join(',\n"').split(',{').join(',\n{')+'```';
|
||||||
if ((member.displayColor)) {
|
if ((member.displayColor)) {
|
||||||
console.log(member.displayColor);
|
|
||||||
result = result+'Display color:```js\n'+member.displayColor+'```';
|
result = result+'Display color:```js\n'+member.displayColor+'```';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
const bree = require("bree");
|
const bree = require("bree");
|
||||||
const cabin = require("cabin");
|
const cabin = require("cabin");
|
||||||
|
|
||||||
module.exports.schedule = new bree({
|
module.exports.scheduler = new bree({
|
||||||
// logger: new cabin(),
|
// logger: new cabin(),
|
||||||
root: false,
|
root: false,
|
||||||
workerMessageHandler: () => console.log,
|
workerMessageHandler: () => console.log,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue