mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-05 12:23:09 +02:00
Archive & log message updates/deletes
This commit is contained in:
parent
59c6ab3537
commit
bb4f872c41
@ -84,7 +84,9 @@ commands:
|
||||
title: ❌ Error
|
||||
options:
|
||||
category:
|
||||
description: Close all tickets in the specified category (can be used with `time`)
|
||||
description: >-
|
||||
Close all tickets in the specified category (can be used with
|
||||
`time`)
|
||||
name: category
|
||||
reason:
|
||||
description: The reason for closing the ticket(s)
|
||||
@ -93,7 +95,9 @@ commands:
|
||||
description: The ticket to close
|
||||
name: ticket
|
||||
time:
|
||||
description: Close all tickets that have been inactive for the specified time (can be used with `category`)
|
||||
description: >-
|
||||
Close all tickets that have been inactive for the specified time
|
||||
(can be used with `category`)
|
||||
name: time
|
||||
help:
|
||||
description: Show the help menu
|
||||
@ -213,6 +217,13 @@ log:
|
||||
create: created
|
||||
delete: deleted
|
||||
update: updated
|
||||
message:
|
||||
description: "{user} {verb} a message"
|
||||
message: Message
|
||||
title: Message {verb}
|
||||
verb:
|
||||
delete: deleted
|
||||
update: updated
|
||||
ticket:
|
||||
description: "{user} {verb} a ticket"
|
||||
ticket: Ticket
|
||||
|
@ -183,8 +183,61 @@ async function logTicketEvent(client, {
|
||||
return await channel.send({ embeds });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("client")} client
|
||||
* @param {object} details
|
||||
* @param {string} details.action
|
||||
* @param {import("discord.js").Message} details.target
|
||||
* @param {import("@prisma/client").Ticket & {guild: import("@prisma/client").Guild}} details.ticket
|
||||
*/
|
||||
async function logMessageEvent(client, {
|
||||
action, target, ticket, diff,
|
||||
}) {
|
||||
if (!ticket) return;
|
||||
client.log.info.tickets(`${target.member.user.tag} ${client.i18n.getMessage('en-GB', `log.message.verb.${action}`)} message ${target.id}`);
|
||||
if (!ticket.guild.logChannel) return;
|
||||
const colour = action === 'update'
|
||||
? 'Purple' : action === 'delete'
|
||||
? 'DarkPurple' : 'Default';
|
||||
const getMessage = client.i18n.getLocale(ticket.guild.locale);
|
||||
const i18nOptions = {
|
||||
user: `<@${target.member.user.id}>`,
|
||||
verb: getMessage(`log.message.verb.${action}`),
|
||||
};
|
||||
const channel = client.channels.cache.get(ticket.guild.logChannel);
|
||||
if (!channel) return;
|
||||
const embeds = [
|
||||
new EmbedBuilder()
|
||||
.setColor(colour)
|
||||
.setAuthor({
|
||||
iconURL: target.member.displayAvatarURL(),
|
||||
name: target.member.displayName,
|
||||
})
|
||||
.setTitle(getMessage('log.message.title', i18nOptions))
|
||||
.setDescription(getMessage('log.message.description', i18nOptions))
|
||||
.addFields([
|
||||
{
|
||||
name: getMessage('log.message.message'),
|
||||
value: `[${target.id}](${target.url})`,
|
||||
},
|
||||
]),
|
||||
];
|
||||
|
||||
if (diff && diff.original) {
|
||||
embeds.push(
|
||||
new EmbedBuilder()
|
||||
.setColor(colour)
|
||||
.setTitle(getMessage('log.admin.changes'))
|
||||
.setFields(makeDiff(diff)),
|
||||
);
|
||||
}
|
||||
|
||||
return await channel.send({ embeds });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getLogChannel,
|
||||
logAdminEvent,
|
||||
logMessageEvent,
|
||||
logTicketEvent,
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
const { Listener } = require('@eartharoid/dbf');
|
||||
const { logMessageEvent } = require('../../lib/logging');
|
||||
|
||||
module.exports = class extends Listener {
|
||||
constructor(client, options) {
|
||||
@ -9,8 +10,44 @@ module.exports = class extends Listener {
|
||||
});
|
||||
}
|
||||
|
||||
run(message) {
|
||||
// TODO: archive messages in tickets
|
||||
// TODO: log channel
|
||||
/**
|
||||
* @param {import("discord.js").Message} oldMessage
|
||||
* @param {import("discord.js").Message} message
|
||||
*/
|
||||
async run(message) {
|
||||
/** @type {import("client")} */
|
||||
const client = this.client;
|
||||
|
||||
if (message.partial) message.fetch().then(m => (message = m)).catch(client.log.error);
|
||||
const ticket = await client.prisma.ticket.findUnique({
|
||||
include: { guild: true },
|
||||
where: { id: message.channel.id },
|
||||
});
|
||||
if (!ticket) return;
|
||||
|
||||
if (ticket.guild.archive) {
|
||||
try {
|
||||
const archived = await client.prisma.archivedMessage.findUnique({ where: { id: message.id } });
|
||||
if (archived) {
|
||||
await client.prisma.archivedMessage.update({
|
||||
data: { deleted: true },
|
||||
where: { id: message.id },
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
client.log.warn('Failed to "delete" archived message', message.id);
|
||||
client.log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
await logMessageEvent(this.client, {
|
||||
action: 'delete',
|
||||
diff: {
|
||||
original: { content: message.cleanContent },
|
||||
updated: { content: '' },
|
||||
},
|
||||
target: message,
|
||||
ticket,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
const { Listener } = require('@eartharoid/dbf');
|
||||
const { logMessageEvent } = require('../../lib/logging');
|
||||
|
||||
module.exports = class extends Listener {
|
||||
constructor(client, options) {
|
||||
@ -9,8 +10,39 @@ module.exports = class extends Listener {
|
||||
});
|
||||
}
|
||||
|
||||
run(oldMessage, newMessage) {
|
||||
// TODO: archive messages in tickets
|
||||
// TODO: log channel
|
||||
|
||||
/**
|
||||
* @param {import("discord.js").Message} oldMessage
|
||||
* @param {import("discord.js").Message} newMessage
|
||||
*/
|
||||
async run(oldMessage, newMessage) {
|
||||
/** @type {import("client")} */
|
||||
const client = this.client;
|
||||
|
||||
if (newMessage.partial) newMessage.fetch().then(m => (newMessage = m)).catch(client.log.error);
|
||||
const ticket = await client.prisma.ticket.findUnique({
|
||||
include: { guild: true },
|
||||
where: { id: newMessage.channel.id },
|
||||
});
|
||||
if (!ticket) return;
|
||||
|
||||
if (ticket.guild.archive) {
|
||||
try {
|
||||
await client.tickets.archiver.saveMessage(ticket.id, newMessage);
|
||||
} catch (error) {
|
||||
client.log.warn('Failed to update archived message', newMessage.id);
|
||||
client.log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
await logMessageEvent(this.client, {
|
||||
action: 'update',
|
||||
diff: {
|
||||
original: { content: oldMessage.cleanContent },
|
||||
updated: { content: newMessage.cleanContent },
|
||||
},
|
||||
target: newMessage,
|
||||
ticket,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user