2019-10-15 18:39:08 -04:00
|
|
|
import { Message } from 'eris';
|
2019-10-17 15:43:32 -04:00
|
|
|
// eslint-disable-next-line import/no-unresolved
|
2019-10-15 18:39:08 -04:00
|
|
|
import { createPaginationEmbed } from 'eris-pagination';
|
2019-10-26 13:06:32 -04:00
|
|
|
import { Client } from '..';
|
2019-10-15 20:34:13 -04:00
|
|
|
import { Command, RichEmbed } from '../class';
|
2019-10-15 18:39:08 -04:00
|
|
|
|
|
|
|
export default class Modlogs extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'modlogs';
|
|
|
|
this.description = 'Check a user\'s Cloud Modlogs';
|
|
|
|
this.aliases = ['infractions', 'modlog'];
|
|
|
|
this.enabled = true;
|
|
|
|
this.permissions = { roles: ['446104438969466890'] };
|
|
|
|
}
|
|
|
|
|
|
|
|
public async run(message: Message, args: string[]) {
|
2019-10-15 19:10:37 -04:00
|
|
|
try {
|
2019-10-28 16:21:04 -04:00
|
|
|
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
|
2019-10-15 19:10:37 -04:00
|
|
|
const msg: Message = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Locating modlogs...***`);
|
2019-10-26 00:01:31 -04:00
|
|
|
const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] });
|
2019-10-15 19:10:37 -04:00
|
|
|
if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`);
|
2019-10-15 18:39:08 -04:00
|
|
|
|
2019-11-02 12:17:55 -04:00
|
|
|
// @ts-ignore
|
|
|
|
const formatted = query.sort((a, b) => a.date - b.date).map((log) => {
|
2019-10-26 00:01:31 -04:00
|
|
|
const { username, moderatorID, reason, type, date } = log;
|
|
|
|
let name: string;
|
2019-10-29 13:35:41 -04:00
|
|
|
switch (type) {
|
|
|
|
default: name = 'Generic'; break;
|
|
|
|
case 0: name = 'Create'; break;
|
|
|
|
case 1: name = 'Warn'; break;
|
|
|
|
case 2: name = 'Lock'; break;
|
|
|
|
case 3: name = 'Unlock'; break;
|
|
|
|
case 4: name = 'Delete'; break;
|
2019-10-26 00:01:31 -04:00
|
|
|
}
|
2019-10-29 15:43:53 -04:00
|
|
|
const value = `**Account name:** ${username}\n**Moderator:** <@${moderatorID}>\n**Reason:** ${reason || 'Not supplied'}\n**Date:** ${date.toLocaleString('en-us')} EST`;
|
2019-10-15 19:10:37 -04:00
|
|
|
const inline = true;
|
|
|
|
return { name, value, inline };
|
|
|
|
});
|
|
|
|
const users = [...new Set(query.map((log) => log.userID))].map((u) => `<@${u}>`);
|
2019-10-15 18:39:08 -04:00
|
|
|
|
2019-10-26 13:06:32 -04:00
|
|
|
const logs = this.client.util.splitFields(formatted);
|
2019-10-15 18:39:08 -04:00
|
|
|
|
2019-10-15 19:10:37 -04:00
|
|
|
const embeds = logs.map((l) => {
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
embed.setDescription(`List of Cloud moderation logs for ${users.join(', ')}`);
|
2019-10-28 16:21:04 -04:00
|
|
|
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL, 'https://libraryofcode.org/');
|
2019-10-15 19:10:37 -04:00
|
|
|
embed.setTitle('Cloud Modlogs/Infractions');
|
|
|
|
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
2019-10-29 13:35:41 -04:00
|
|
|
l.forEach((f) => embed.addField(f.name, f.value, f.inline));
|
2019-10-15 19:10:37 -04:00
|
|
|
embed.setTimestamp();
|
|
|
|
embed.setColor(3447003);
|
|
|
|
return embed;
|
|
|
|
});
|
2019-10-15 18:39:08 -04:00
|
|
|
|
2019-10-28 16:21:04 -04:00
|
|
|
if (embeds.length === 1) {
|
|
|
|
// @ts-ignore
|
2019-10-29 16:14:02 -04:00
|
|
|
msg.edit({ content: '', embed: embeds[0] });
|
2019-10-28 16:21:04 -04:00
|
|
|
} else {
|
|
|
|
createPaginationEmbed(message, this.client, embeds, {}, msg);
|
|
|
|
}
|
2019-10-15 19:10:37 -04:00
|
|
|
return msg;
|
|
|
|
} catch (error) {
|
2019-10-26 13:06:32 -04:00
|
|
|
return this.client.util.handleError(error, message, this);
|
2019-10-15 19:10:37 -04:00
|
|
|
}
|
2019-10-15 18:39:08 -04:00
|
|
|
}
|
|
|
|
}
|