Skip to content

Commit

Permalink
feat: feedback, start of close requests
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Jan 13, 2023
1 parent d7e1b05 commit 8bf01aa
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 56 deletions.
6 changes: 2 additions & 4 deletions db/mysql/schema.prisma
Expand Up @@ -101,10 +101,9 @@ model Feedback {
createdAt DateTime @default(now())
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String @db.VarChar(19)
id Int @id @default(autoincrement())
rating Int
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @unique @db.VarChar(19)
ticketId String @id @db.VarChar(19)
user User? @relation(fields: [userId], references: [id])
userId String? @db.VarChar(19)
Expand Down Expand Up @@ -199,10 +198,9 @@ model Ticket {
createdAt DateTime @default(now())
createdBy User @relation(name: "TicketsCreatedByUser", fields: [createdById], references: [id])
createdById String @db.VarChar(19)
deleted Boolean @default(false)
feedback Feedback?
feedbackId Int?
firstResponseAt DateTime?
deleted Boolean @default(false)
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String @db.VarChar(19)
id String @id @db.VarChar(19)
Expand Down
6 changes: 2 additions & 4 deletions db/postgresql/schema.prisma
Expand Up @@ -101,10 +101,9 @@ model Feedback {
createdAt DateTime @default(now())
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String @db.VarChar(19)
id Int @id @default(autoincrement())
rating Int
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @unique @db.VarChar(19)
ticketId String @id @db.VarChar(19)
user User? @relation(fields: [userId], references: [id])
userId String? @db.VarChar(19)
Expand Down Expand Up @@ -199,10 +198,9 @@ model Ticket {
createdAt DateTime @default(now())
createdBy User @relation(name: "TicketsCreatedByUser", fields: [createdById], references: [id])
createdById String @db.VarChar(19)
deleted Boolean @default(false)
feedback Feedback?
feedbackId Int?
firstResponseAt DateTime?
deleted Boolean @default(false)
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String @db.VarChar(19)
id String @id @db.VarChar(19)
Expand Down
6 changes: 2 additions & 4 deletions db/sqlite/schema.prisma
Expand Up @@ -101,10 +101,9 @@ model Feedback {
createdAt DateTime @default(now())
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String
id Int @id @default(autoincrement())
rating Int
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @unique
ticketId String @id
user User? @relation(fields: [userId], references: [id])
userId String?
Expand Down Expand Up @@ -199,10 +198,9 @@ model Ticket {
createdAt DateTime @default(now())
createdBy User @relation(name: "TicketsCreatedByUser", fields: [createdById], references: [id])
createdById String
deleted Boolean @default(false)
feedback Feedback?
feedbackId Int?
firstResponseAt DateTime?
deleted Boolean @default(false)
guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
guildId String
id String @id
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -43,8 +43,8 @@
"@fastify/http-proxy": "^8.4.0",
"@fastify/jwt": "^5.0.1",
"@fastify/oauth2": "^5.1.0",
"@prisma/client": "^4.8.0",
"cryptr": "^6.0.3",
"@prisma/client": "^4.8.1",
"cryptr": "^6.1.0",
"discord.js": "^14.7.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand All @@ -60,7 +60,7 @@
"node-emoji": "^1.11.0",
"object-diffy": "^1.0.4",
"pad": "^3.2.0",
"prisma": "^4.8.0",
"prisma": "^4.8.1",
"semver": "^7.3.8",
"terminal-link": "^2.1.1",
"yaml": "^1.10.2"
Expand Down
26 changes: 25 additions & 1 deletion src/buttons/close.js
@@ -1,4 +1,5 @@
const { Button } = require('@eartharoid/dbf');
const { isStaff } = require('../lib/users');

module.exports = class CloseButton extends Button {
constructor(client, options) {
Expand All @@ -16,6 +17,29 @@ module.exports = class CloseButton extends Button {
/** @type {import("client")} */
const client = this.client;

await interaction.deferReply();
if (id.accepted === undefined) {
await client.tickets.beforeRequestClose(interaction);
} else {
// {
// action: 'close',
// expect: staff ? 'user' : 'staff',
// reason: interaction.options?.getString('reason', false) || null, // ?. because it could be a button interaction
// requestedBy: interaction.user.id,
// }

await interaction.deferReply();
const ticket = await client.prisma.ticket.findUnique({
include: { guild: true },
where: { id: interaction.channel.id },
});

if (id.expect === 'staff' && !await isStaff(interaction.guild, interaction.user.id)) {
return;
} else if (interaction.user.id !== ticket.createdById) {
return;
// if user and expect user (or is creator), feedback modal (if enabled)
// otherwise add "Give feedback" button in DM message (if enabled)
}
}
}
};
8 changes: 4 additions & 4 deletions src/buttons/edit.js
Expand Up @@ -2,8 +2,8 @@ const { Button } = require('@eartharoid/dbf');
const {
ActionRowBuilder,
ModalBuilder,
SelectMenuBuilder,
SelectMenuOptionBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
TextInputBuilder,
TextInputStyle,
} = require('discord.js');
Expand Down Expand Up @@ -86,14 +86,14 @@ module.exports = class EditButton extends Button {
} else if (a.question.type === 'MENU') {
return new ActionRowBuilder()
.setComponents(
new SelectMenuBuilder()
new StringSelectMenuBuilder()
.setCustomId(a.question.id)
.setPlaceholder(a.question.placeholder || a.question.label)
.setMaxValues(a.question.maxLength)
.setMinValues(a.question.minLength)
.setOptions(
a.question.options.map((o, i) => {
const builder = new SelectMenuOptionBuilder()
const builder = new StringSelectMenuOptionBuilder()
.setValue(String(i))
.setLabel(o.label);
if (o.description) builder.setDescription(o.description);
Expand Down
3 changes: 2 additions & 1 deletion src/client.js
@@ -1,6 +1,7 @@
const { FrameworkClient } = require('@eartharoid/dbf');
const {
GatewayIntentBits, Partials,
GatewayIntentBits,
Partials,
} = require('discord.js');
const { PrismaClient } = require('@prisma/client');
const Keyv = require('keyv');
Expand Down
4 changes: 3 additions & 1 deletion src/commands/slash/close.js
Expand Up @@ -30,6 +30,8 @@ module.exports = class CloseSlashCommand extends SlashCommand {
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async run(interaction) {

/** @type {import("client")} */
const client = this.client;
await client.tickets.beforeRequestClose(interaction);
}
};
2 changes: 0 additions & 2 deletions src/commands/slash/force-close.js
Expand Up @@ -228,7 +228,5 @@ module.exports = class ForceCloseSlashCommand extends SlashCommand {
});
}
}

// TODO: close (reason)
}
};
4 changes: 2 additions & 2 deletions src/commands/slash/move.js
Expand Up @@ -85,8 +85,8 @@ module.exports = class MoveSlashCommand extends SlashCommand {
where: { id: ticket.id },
});

const $oldCategory = client.tickets.$.categories[ticket.categoryId];
const $newCategory = client.tickets.$.categories[newCategory.id];
const $oldCategory = client.tickets.$count.categories[ticket.categoryId];
const $newCategory = client.tickets.$count.categories[newCategory.id];

$oldCategory.total--;
$oldCategory[ticket.createdById]--;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/slash/transfer.js
Expand Up @@ -44,7 +44,7 @@ module.exports = class TransferSlashCommand extends SlashCommand {

let ticket = await client.prisma.ticket.findUnique({ where: { id: interaction.channel.id } });
const from = ticket.createdById;
console.log(1)

ticket = await client.prisma.ticket.update({
data: {
createdBy: {
Expand Down
30 changes: 28 additions & 2 deletions src/i18n/en-GB.yml
@@ -1,6 +1,9 @@
buttons:
accept_close_request:
emoji:
text: Accept
cancel:
emoji: 🚫
emoji: ✖️
text: Cancel
claim:
emoji: 🙌
Expand All @@ -17,6 +20,9 @@ buttons:
edit:
emoji: ✏️
text: Edit
reject_close_request:
emoji: ✖️
text: Reject
unclaim:
emoji: ♻️
text: Release
Expand Down Expand Up @@ -328,14 +334,34 @@ misc:
title: ❌ That ticket category doesn't exist
modals:
feedback:
title: Feedback
comment:
label: Comment
placeholder: Do you have any additional feedback?
rating:
label: Rating
placeholder: 1-5
title: How did we do?
topic:
label: Topic
placeholder: What is this ticket about?
ticket:
answers:
no_value: "*No response*"
claimed: 🙌 {user} has claimed this ticket.
close:
forbidden:
description: You don't have permission to close this ticket.
title: ❌ Error
staff_request:
archived: |
The messages in this channel will be archived for future reference.
description: |
{requestedBy} wants to close this ticket.
Click "Accept" to close it now, or "Reject" if you still need help.
title: ❓ Can this ticket be closed?
user_request:
title: ❓ {requestedBy} wants to close this ticket
created:
description: "Your ticket channel has been created: {channel}."
title: ✅ Ticket created
Expand Down
6 changes: 3 additions & 3 deletions src/lib/sync.js
Expand Up @@ -22,10 +22,10 @@ module.exports = async client => {
let cooldowns = 0;
for (const category of categories) {
ticketCount += category.tickets.length;
client.tickets.$.categories[category.id] = { total: category.tickets.length };
client.tickets.$count.categories[category.id] = { total: category.tickets.length };
for (const ticket of category.tickets) {
if (client.tickets.$.categories[category.id][ticket.createdById]) client.tickets.$.categories[category.id][ticket.createdById]++;
else client.tickets.$.categories[category.id][ticket.createdById] = 1;
if (client.tickets.$count.categories[category.id][ticket.createdById]) client.tickets.$count.categories[category.id][ticket.createdById]++;
else client.tickets.$count.categories[category.id][ticket.createdById] = 1;
/** @type {import("discord.js").Guild} */
const guild = client.guilds.cache.get(ticket.guildId);
if (guild && guild.available && !client.channels.cache.has(ticket.id)) {
Expand Down

0 comments on commit 8bf01aa

Please sign in to comment.