-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feedback): add feedback command
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { SteveCommand } from "#lib/structures/commands/SteveCommand"; | ||
import { registerBasicCommand } from "#utils/util"; | ||
import { ApplyOptions } from "@sapphire/decorators"; | ||
import { | ||
ApplicationCommandRegistry, | ||
CommandOptions, | ||
} from "@sapphire/framework"; | ||
import { TFunction, fetchT } from "@sapphire/plugin-i18next"; | ||
import { Time } from "@sapphire/timestamp"; | ||
import { | ||
ActionRowBuilder, | ||
ChatInputCommandInteraction, | ||
ModalBuilder, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
} from "discord.js"; | ||
|
||
@ApplyOptions<CommandOptions>({ | ||
description: "Send feedback to my developers.", | ||
}) | ||
export default class extends SteveCommand { | ||
public override registerApplicationCommands( | ||
registry: ApplicationCommandRegistry, | ||
) { | ||
registerBasicCommand(registry, this.name, this.description); | ||
} | ||
|
||
public override async chatInputRun(interaction: ChatInputCommandInteraction) { | ||
const t = await fetchT(interaction); | ||
|
||
try { | ||
await this.sendFeedbackModal(interaction, t); | ||
|
||
const submissionData = await interaction.awaitModalSubmit({ | ||
time: Time.Minute * 5, | ||
}); | ||
|
||
const feedback = | ||
submissionData.fields.getTextInputValue("feedback_input"); | ||
|
||
await this.container.settings.feedback.addFeedback( | ||
feedback, | ||
submissionData.createdAt, | ||
submissionData.user.id, | ||
); | ||
|
||
return submissionData.reply(t("commands/feedback:submissionSuccess")); | ||
} catch (e) { | ||
console.log(e); // TODO: set up logger plugin | ||
return interaction.reply(t("commands/feedback:submissionFailure")); | ||
} | ||
} | ||
|
||
private sendFeedbackModal( | ||
interaction: ChatInputCommandInteraction, | ||
t: TFunction, | ||
) { | ||
const input = new TextInputBuilder() | ||
.setCustomId("feedback_input") | ||
.setLabel(t("commands/feedback:modal.input.label")) | ||
.setMaxLength(1900) | ||
.setPlaceholder(t("commands/feedback:modal.input.placeholder")) | ||
.setRequired(true) | ||
.setStyle(TextInputStyle.Paragraph); | ||
|
||
const actionRow = new ActionRowBuilder<TextInputBuilder>().addComponents( | ||
input, | ||
); | ||
|
||
const modal = new ModalBuilder() | ||
.setCustomId("feedback_modal") | ||
.setTitle(t("commands/feedback:modal.title")) | ||
.addComponents(actionRow); | ||
|
||
return interaction.showModal(modal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"modal": { | ||
"input": { | ||
"label": "What feedback do you have for us?", | ||
"placeholder": "Help make Steve better!" | ||
}, | ||
"title": "Feedback" | ||
}, | ||
"submissionFailure": "There was a problem submitting your feedback, please try again later!", | ||
"submissionSuccess": "Thanks for your feedback!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { Snowflake } from "discord.js"; | ||
|
||
export default class FeedbackSettings { | ||
private prisma: PrismaClient; | ||
|
||
public constructor(prisma: PrismaClient) { | ||
this.prisma = prisma; | ||
} | ||
|
||
public addFeedback( | ||
content: string, | ||
timestamp: Date, | ||
userSnowflake: Snowflake, | ||
) { | ||
return this.prisma.feedback.create({ | ||
data: { | ||
content, | ||
timestamp, | ||
user: userSnowflake, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import GuildSettings from "./GuildSettings.js"; | ||
import FeedbackSettings from "./FeedbackSettings.js"; | ||
|
||
export default class SettingsProvider { | ||
public feedback: FeedbackSettings; | ||
public guilds: GuildSettings; | ||
|
||
private prisma: PrismaClient; | ||
|
||
public constructor() { | ||
this.prisma = new PrismaClient(); | ||
this.feedback = new FeedbackSettings(this.prisma); | ||
this.guilds = new GuildSettings(this.prisma); | ||
} | ||
} |