forked from Galactic/galactic-bot
148 lines
5.8 KiB
JavaScript
148 lines
5.8 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
const { inspect } = require('util');
|
|
|
|
class CaseCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'case',
|
|
module: 'moderation',
|
|
usage: "<id>",
|
|
memberPermissions: ['BAN_MEMBERS'],
|
|
examples: [
|
|
'23',
|
|
'23 --verbose'
|
|
],
|
|
keepQuotes: true,
|
|
arguments: [
|
|
{
|
|
name: 'verbose',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG']
|
|
},
|
|
{
|
|
name: 'raw',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG']
|
|
},
|
|
{
|
|
name: 'changes',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG']
|
|
}
|
|
],
|
|
guildOnly: true,
|
|
showUsage: true//,
|
|
// throttling: {
|
|
// usages: 2,
|
|
// duration: 5
|
|
// }
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute(message, { params, args }) {
|
|
|
|
const { guild } = message;
|
|
let [caseID] = params;
|
|
caseID = parseInt(caseID);
|
|
if (isNaN(caseID) || caseID < 0) return message.formattedRespond('C_CASE_INVALID', { params: { caseID: params[0] } });
|
|
|
|
const infraction = await this.client.storageManager.mongodb.infractions.findOne({
|
|
id: `${guild.id}:${caseID}`
|
|
});
|
|
|
|
if (!infraction) return message.formattedRespond('C_CASE_NOTFOUND', { params: { caseID } });
|
|
if (args.raw) return message.respond(`\`\`\`js\n${inspect(infraction)}\n\`\`\``);
|
|
if (args.changes) return message.embed(await this._listChanges(message, infraction));
|
|
|
|
const target = infraction.targetType === 'user' ? await this.client.resolver.resolveUser(infraction.target) : await guild.resolveChannel(infraction.target);
|
|
const staff = await this.client.resolver.resolveUser(infraction.executor);
|
|
|
|
let index = 'C_CASE_TEMPLATE',
|
|
caseTitleIndex = 'C_CASE_TITLE',
|
|
caseSlowmodeIndex = 'C_CASE_SLOWMODE',
|
|
caseLengthIndex = 'C_CASE_LENGTH',
|
|
targetUserIndex = 'C_CASE_TARGET_USER',
|
|
targetChannelIndex = 'C_CASE_TARGET_CHANNEL';
|
|
if (args.verbose) {
|
|
index += '_VERBOSE';
|
|
caseTitleIndex += '_VERBOSE';
|
|
caseSlowmodeIndex += '_VERBOSE';
|
|
caseLengthIndex += '_VERBOSE';
|
|
targetUserIndex += '_VERBOSE';
|
|
targetChannelIndex += '_VERBOSE';
|
|
}
|
|
|
|
let description = message.format(index, {
|
|
uniqueID: infraction.id,
|
|
type: infraction.type,
|
|
date: new Date(infraction.timestamp).toUTCString(),
|
|
unix: Math.floor(infraction.timestamp/1000),
|
|
relativeTime: this.client.resolver.timeAgo(Math.floor((Date.now() - infraction.timestamp) / 1000)),
|
|
relativeTimeSeconds: Math.floor((Date.now() - infraction.timestamp) / 1000),
|
|
target: infraction.targetType === 'user' ? message.format(targetUserIndex, { target: target.tag, targetID: target.id }) : message.format(targetChannelIndex, { target: target.name, targetID: target.id }),
|
|
staff: staff.tag,
|
|
staffID: staff.id,
|
|
nrChanges: infraction.changes?.length || 0,
|
|
changes: infraction.changes?.map((change) => change.type).join(', ') || 'N/A',
|
|
guild: guild.id,
|
|
channel: infraction.channel,
|
|
message: infraction.message
|
|
});
|
|
|
|
if (infraction.data.seconds) description += '\n' + message.format(caseSlowmodeIndex, { readable: this.client.resolver.timeAgo(infraction.data.seconds), seconds: infraction.data.seconds });
|
|
|
|
if (infraction.duration !== null) description += '\n' + message.format(caseLengthIndex, { time: this.client.resolver.timeAgo(infraction.duration), inSeconds: infraction.duration });
|
|
|
|
if (guild._settings.moderationPoints.enabled) description += '\n' + message.format('C_CASE_MODPOINTS', {
|
|
points: infraction.points,
|
|
expires: infraction.expiration
|
|
});
|
|
|
|
description += '\n\n' + message.format('C_CASE_REASON', { reason: infraction.reason });
|
|
|
|
const embed = {
|
|
title: message.format(caseTitleIndex, { caseID }),
|
|
description,
|
|
color: 8662306
|
|
};
|
|
|
|
message.embed(embed);
|
|
|
|
}
|
|
|
|
async _listChanges(message, infraction) {
|
|
|
|
const embed = {
|
|
title: message.format('C_CASE_CHANGES_TITLE', { case: infraction.case }),
|
|
color: 8662306
|
|
};
|
|
|
|
if (!infraction.changes || !infraction.changes.length) embed.description = message.format('C_CASE_CHANGES_NONE');
|
|
else embed.fields = await Promise.all(infraction.changes.sort((a, b) => b.timestamp - a.timestamp).map(async (change) => {
|
|
|
|
const staff = await this.client.resolver.resolveUser(change.staff);
|
|
const field = {
|
|
name: change.type,
|
|
value: message.format('C_CASE_CHANGE_BASE', { staff: staff.tag, date: new Date(change.timestamp * 1000).toUTCString(), timeAgo: this.client.resolver.timeAgo(Math.floor(Date.now() / 1000) - change.timestamp) })
|
|
};
|
|
|
|
if (change.type === 'RESOLVE') field.value += '\n' + message.format('C_CASE_CHANGES_RESOLVE', { reason: change.reason || message.format('C_CASE_CHANGE_NOREASON') });
|
|
if (change.type === 'REASON') field.value += '\n' + message.format('C_CASE_CHANGES_REASON', { reason: change.reason });
|
|
if (change.type === 'DURATION') field.value += '\n' + message.format('C_CASE_CHANGES_DURATION', { duration: this.client.resolver.timeAgo(change.duration) });
|
|
|
|
return field;
|
|
|
|
}));
|
|
|
|
return embed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = CaseCommand; |