mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-05 17:51:27 +03:00
Add message and ticket referencing, fixes
This commit is contained in:
@@ -8,5 +8,37 @@ module.exports = class ReferencesCompleter extends Autocompleter {
|
||||
});
|
||||
}
|
||||
|
||||
async run(value, comamnd, interaction) { }
|
||||
/**
|
||||
* @param {string} value
|
||||
* @param {*} comamnd
|
||||
* @param {import("discord.js").AutocompleteInteraction} interaction
|
||||
*/
|
||||
async run(value, comamnd, interaction) {
|
||||
/** @type {import("client")} */
|
||||
const client = this.client;
|
||||
const settings = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } });
|
||||
const tickets = await client.prisma.ticket.findMany({
|
||||
where: {
|
||||
createdById: interaction.user.id,
|
||||
guildId: interaction.guild.id,
|
||||
open: false,
|
||||
},
|
||||
});
|
||||
const options = value ? tickets.filter(t =>
|
||||
String(t.number).match(new RegExp(value, 'i')) ||
|
||||
t.topic?.match(new RegExp(value, 'i')) ||
|
||||
new Date(t.createdAt).toLocaleString(settings.locale, { dateStyle: 'short' })?.match(new RegExp(value, 'i')),
|
||||
) : tickets;
|
||||
await interaction.respond(
|
||||
options
|
||||
.slice(0, 25)
|
||||
.map(t => {
|
||||
const date = new Date(t.createdAt).toLocaleString(settings.locale, { dateStyle: 'short' });
|
||||
return {
|
||||
name: `#${t.number} - ${date} ${t.topic ? '| ' + t.topic.substring(0, 50) : ''}`,
|
||||
value: t.id,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user