2021-06-19 20:05:32 +02:00
|
|
|
const Command = require('../Command');
|
2021-12-22 23:52:06 +01:00
|
|
|
const Util = require('../Util');
|
2021-06-19 20:05:32 +02:00
|
|
|
|
|
|
|
class Logs extends Command {
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
constructor (client) {
|
2021-06-19 20:05:32 +02:00
|
|
|
super(client, {
|
|
|
|
name: 'logs',
|
2021-10-22 09:35:04 +02:00
|
|
|
aliases: [ 'mmlogs', 'mmhistory', 'mmlog' ],
|
2021-06-19 20:05:32 +02:00
|
|
|
showUsage: true,
|
|
|
|
usage: '<user> [page]'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
async execute (message, { args }) {
|
2021-06-19 22:41:51 +02:00
|
|
|
|
2021-06-19 20:05:32 +02:00
|
|
|
const user = await this.client.resolveUser(args[0]);
|
|
|
|
let pageNr = 1;
|
|
|
|
if (args[1]) {
|
|
|
|
const num = parseInt(args[1]);
|
|
|
|
if (isNaN(num)) return {
|
|
|
|
error: true,
|
|
|
|
msg: 'Invalid page number, must be number'
|
|
|
|
};
|
|
|
|
pageNr = num;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { member, channel } = message;
|
2021-06-20 16:43:05 +02:00
|
|
|
const history = await this.client.cache.loadModmailHistory(user.id);
|
2021-06-19 22:21:29 +02:00
|
|
|
if (!history.length) return 'Not found in modmail DB';
|
2021-12-22 23:52:06 +01:00
|
|
|
const page = Util.paginate([ ...history ].filter((e) => !('readState' in e)).reverse(), pageNr, 10);
|
2021-06-19 20:05:32 +02:00
|
|
|
|
|
|
|
const embed = {
|
|
|
|
author: {
|
|
|
|
name: `${user.tag} modmail history`,
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
icon_url: user.displayAvatarURL({ dynamic: true })
|
|
|
|
},
|
|
|
|
footer: {
|
|
|
|
text: `${user.id} | Page ${page.page}/${page.maxPage}`
|
|
|
|
},
|
|
|
|
fields: [],
|
|
|
|
color: member.highestRoleColor
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const entry of page.items) {
|
2021-10-22 09:35:04 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2021-06-19 20:05:32 +02:00
|
|
|
const user = await this.client.resolveUser(entry.author);
|
2021-11-29 11:48:45 +01:00
|
|
|
let value = entry.content.substring(0, 1000) + (entry.content.length > 1000 ? '...' : '');
|
|
|
|
if (!value.length) value = entry.attachments.join('\n');
|
2021-06-19 20:05:32 +02:00
|
|
|
embed.fields.push({
|
|
|
|
name: `${user.tag}${entry.anon ? ' (ANON)' : ''} @ ${new Date(entry.timestamp).toUTCString()}`,
|
2021-11-29 11:48:45 +01:00
|
|
|
value
|
|
|
|
});
|
|
|
|
if (entry.attachments?.length && entry.content.length) embed.fields.push({
|
|
|
|
name: `Attachments`,
|
|
|
|
value: entry.attachments.join('\n')
|
2021-06-19 20:05:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await channel.send({ embed });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Logs;
|