2022-03-23 13:39:45 +01:00
|
|
|
const { MessageAttachment } = require('discord.js');
|
|
|
|
const Command = require('../Command');
|
|
|
|
|
|
|
|
class MessageIds extends Command {
|
|
|
|
|
|
|
|
constructor (client) {
|
|
|
|
super(client, {
|
|
|
|
name: 'messageids',
|
|
|
|
aliases: [ 'msgids', 'mmids' ]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute (message, { args }) {
|
|
|
|
|
|
|
|
let channel = null;
|
|
|
|
if (args?.length) channel = await this.client.resolveChannel(args[0]);
|
|
|
|
else ({ channel } = message);
|
|
|
|
|
|
|
|
const result = this.client.getUserFromChannel(channel);
|
|
|
|
if (result.error) return result;
|
|
|
|
const [ userId ] = result;
|
|
|
|
|
|
|
|
const user = await this.client.users.fetch(userId);
|
2022-03-23 21:46:42 +01:00
|
|
|
const dmChannel = await user.createDM();
|
2022-03-23 13:39:45 +01:00
|
|
|
|
|
|
|
const history = await this.client.cache.loadModmailHistory(userId);
|
|
|
|
const sorted = history.sort((a, b) => b.timestamp - a.timestamp);
|
|
|
|
const idContentPairs = [];
|
2022-03-23 21:48:43 +01:00
|
|
|
const urlBase = `https://discord.com/channels/@me`;
|
2022-03-23 13:39:45 +01:00
|
|
|
|
|
|
|
for (const mm of sorted) {
|
|
|
|
if (!mm.msgid && !mm.isReply) break; // Old modmails from before msg id logging -- could probably supplement with fetching messages but cba rn
|
2022-03-23 21:48:43 +01:00
|
|
|
idContentPairs.push(`${urlBase}/${dmChannel.id}/${mm.msgid} - ${mm.content}`);
|
2022-03-23 13:39:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!idContentPairs.length) {
|
2022-03-23 21:46:42 +01:00
|
|
|
const msgs = await dmChannel.messages.fetch();
|
2022-03-23 13:39:45 +01:00
|
|
|
const sortedMsgs = msgs.filter(msg => msg.author.id !== this.client.user.id).sort((a, b) => b.createdTimestamp - a.createdTimestamp);
|
2022-03-23 21:48:43 +01:00
|
|
|
for (const msg of sortedMsgs.values()) idContentPairs.push(`${urlBase}/${dmChannel.id}/${msg.id} - ${msg.content}`);
|
2022-03-23 13:39:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await message.channel.send({
|
|
|
|
files: [
|
|
|
|
new MessageAttachment(
|
|
|
|
Buffer.from(`ID - Content pairs for\n${user.tag} - ${user.id}\n\n${idContentPairs.join('\n')}`),
|
|
|
|
'ids.txt'
|
|
|
|
)
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MessageIds;
|