#303 and other stuff

This commit is contained in:
Isaac 2022-08-13 23:58:41 +01:00
parent c64b18a397
commit 4c176d082f
No known key found for this signature in database
GPG Key ID: F4EAABEB0FFCC06A
10 changed files with 70 additions and 27 deletions

View File

@ -8,5 +8,37 @@ module.exports = class TicketCompleter 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,
};
}),
);
}
}; };

View File

@ -10,21 +10,17 @@ module.exports = class CloseSlashCommand extends SlashCommand {
client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.close.name'))); client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.close.name')));
let opts = [ let opts = [
{
name: 'channel',
required: false,
type: ApplicationCommandOptionType.Channel,
},
{
name: 'number',
required: false,
type: ApplicationCommandOptionType.Integer,
},
{ {
name: 'reason', name: 'reason',
required: false, required: false,
type: ApplicationCommandOptionType.String, type: ApplicationCommandOptionType.String,
}, },
{
autocomplete: true,
name: 'ticket',
required: false,
type: ApplicationCommandOptionType.String,
},
{ {
name: 'time', name: 'time',
required: false, required: false,

View File

@ -50,6 +50,5 @@ module.exports = class NewSlashCommand extends SlashCommand {
*/ */
async run(interaction) { async run(interaction) {
await useGuild(this.client, interaction, { referencesTicketId: interaction.options.getString('references', false) }); await useGuild(this.client, interaction, { referencesTicketId: interaction.options.getString('references', false) });
} }
}; };

View File

@ -13,5 +13,8 @@ module.exports = class CreateUserCommand extends UserCommand {
}); });
} }
async run(interaction) { } async run(interaction) {
// select category
// send button
}
}; };

View File

@ -41,15 +41,12 @@ commands:
description: Close a ticket description: Close a ticket
name: close name: close
options: options:
channel:
description: The ticket channel to close
name: channel
number:
description: The number of the ticket to close
name: number
reason: reason:
description: The reason for closing the ticket(s) description: The reason for closing the ticket(s)
name: reason name: reason
ticket:
description: The ticket to close
name: ticket
time: time:
description: Close all tickets that have been inactive for the specific time description: Close all tickets that have been inactive for the specific time
name: time name: time

View File

@ -386,6 +386,20 @@ module.exports = class TicketManager {
if (category.image) await channel.send(category.image); if (category.image) await channel.send(category.image);
const statsCacheKey = `cache/category-stats/${categoryId}`;
let stats = await this.client.keyv.get(statsCacheKey);
if (!stats) {
const { tickets } = await this.client.prisma.category.findUnique({
select: { tickets: { where: { open: false } } },
where: { id: categoryId },
});
stats = {
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
avgResponseTime: ms(tickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / tickets.length),
};
this.client.keyv.set(statsCacheKey, stats, ms('1h'));
}
const embeds = [ const embeds = [
new ExtendedEmbedBuilder() new ExtendedEmbedBuilder()
.setColor(category.guild.primaryColour) .setColor(category.guild.primaryColour)
@ -395,11 +409,14 @@ module.exports = class TicketManager {
}) })
.setDescription( .setDescription(
category.openingMessage category.openingMessage
.replace(/{+\s?(user)?name\s?}+/gi, creator.user.toString()), .replace(/{+\s?(user)?name\s?}+/gi, creator.user.toString())
.replace(/{+\s?avgResponseTime\s?}+/gi, stats.avgResponseTime)
.replace(/{+\s?avgResolutionTime\s?}+/gi, stats.avgResolutionTime),
), ),
]; ];
// TODO: !staff || workingHours
if (answers) { if (answers) {
embeds.push( embeds.push(
new ExtendedEmbedBuilder() new ExtendedEmbedBuilder()

View File

@ -11,5 +11,6 @@ module.exports = class extends Listener {
run(message) { run(message) {
// TODO: archive messages in tickets // TODO: archive messages in tickets
// TODO: log channel
} }
}; };

View File

@ -11,5 +11,6 @@ module.exports = class extends Listener {
run(oldMessage, newMessage) { run(oldMessage, newMessage) {
// TODO: archive messages in tickets // TODO: archive messages in tickets
// TODO: log channel
} }
}; };

View File

@ -21,7 +21,7 @@ module.exports.get = fastify => ({
name: true, name: true,
requiredRoles: true, requiredRoles: true,
staffRoles: true, staffRoles: true,
tickets: true, tickets: { where: { open: false } },
}, },
}, },
}, },

View File

@ -12,11 +12,8 @@ module.exports = class Commands extends StdinCommand {
switch (args[0]) { switch (args[0]) {
case 'publish': { case 'publish': {
this.client.commands.publish() this.client.commands.publish()
.then(commands => { .then(commands => this.client.log.success('Published %d commands', commands?.size))
if (!commands) return console.log('None published'); .catch(this.client.log.error);
console.log('Published %d commands', commands.size);
})
.catch(console.error);
break; break;
} }
} }