-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
329 additions
and
5 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
52 changes: 52 additions & 0 deletions
52
src/database/managers/aliceDb/SupportTicketPresetCollectionManager.ts
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,52 @@ | ||
import { DatabaseSupportTicketPreset } from "@alice-structures/database/aliceDb/DatabaseSupportTicketPreset"; | ||
import { DatabaseCollectionManager } from "../DatabaseCollectionManager"; | ||
import { SupportTicketPreset } from "@alice-database/utils/aliceDb/SupportTicketPreset"; | ||
import { ApplicationCommandOptionChoiceData } from "discord.js"; | ||
|
||
export class SupportTicketPresetCollectionManager extends DatabaseCollectionManager< | ||
DatabaseSupportTicketPreset, | ||
SupportTicketPreset | ||
> { | ||
protected override readonly utilityInstance = SupportTicketPreset; | ||
|
||
override get defaultDocument(): DatabaseSupportTicketPreset { | ||
return { | ||
id: 0, | ||
name: "", | ||
title: "", | ||
description: "", | ||
}; | ||
} | ||
|
||
/** | ||
* Searches presets based on its name for autocomplete response. | ||
* | ||
* @param name The name to search. | ||
* @param amount The maximum amount of names to return. Defaults to 25. | ||
* @returns The name of the presets that match the query. | ||
*/ | ||
async searchPresets( | ||
name: string | RegExp, | ||
amount: number = 25, | ||
): Promise<ApplicationCommandOptionChoiceData<string>[]> { | ||
let regExp: RegExp; | ||
|
||
try { | ||
regExp = new RegExp(name, "i"); | ||
} catch { | ||
return []; | ||
} | ||
|
||
const result = await this.collection | ||
.find({ name: regExp }, { projection: { _id: 0, name: 1 } }) | ||
.limit(amount) | ||
.toArray(); | ||
|
||
return result.map((v) => { | ||
return { | ||
name: v.name, | ||
value: v.name, | ||
}; | ||
}); | ||
} | ||
} |
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 { DatabaseSupportTicketPreset } from "@alice-structures/database/aliceDb/DatabaseSupportTicketPreset"; | ||
import { Manager } from "@alice-utils/base/Manager"; | ||
import { ObjectId } from "mongodb"; | ||
|
||
export class SupportTicketPreset | ||
extends Manager | ||
implements DatabaseSupportTicketPreset | ||
{ | ||
readonly id: number; | ||
readonly name: string; | ||
readonly title: string; | ||
readonly description: string; | ||
readonly _id?: ObjectId; | ||
|
||
constructor(data: DatabaseSupportTicketPreset) { | ||
super(); | ||
|
||
this._id = data._id; | ||
this.id = data.id; | ||
this.name = data.name; | ||
this.title = data.title; | ||
this.description = data.description; | ||
} | ||
} |
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,14 @@ | ||
import { DatabaseManager } from "@alice-database/DatabaseManager"; | ||
import { AutocompleteHandler } from "@alice-structures/core/AutocompleteHandler"; | ||
|
||
export const run: AutocompleteHandler["run"] = async (_, interaction) => { | ||
interaction.respond( | ||
await DatabaseManager.aliceDb.collections.supportTicketPreset.searchPresets( | ||
interaction.options.getFocused(), | ||
), | ||
); | ||
}; | ||
|
||
export const config: AutocompleteHandler["config"] = { | ||
name: "ticket", | ||
}; |
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
103 changes: 103 additions & 0 deletions
103
src/interactions/buttons/Support Ticket/createSupportTicketWithPreset.ts
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,103 @@ | ||
import { DatabaseManager } from "@alice-database/DatabaseManager"; | ||
import { CreateSupportTicketWithPresetLocalization } from "@alice-localization/interactions/buttons/Support Ticket/createSupportTicketWithPreset/CreateSupportTicketWithPresetLocalization"; | ||
import { ButtonCommand } from "@alice-structures/core/ButtonCommand"; | ||
import { MessageCreator } from "@alice-utils/creators/MessageCreator"; | ||
import { ModalCreator } from "@alice-utils/creators/ModalCreator"; | ||
import { SelectMenuCreator } from "@alice-utils/creators/SelectMenuCreator"; | ||
import { CommandHelper } from "@alice-utils/helpers/CommandHelper"; | ||
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper"; | ||
import { TextInputBuilder, TextInputStyle } from "discord.js"; | ||
|
||
export const run: ButtonCommand["run"] = async (_, interaction) => { | ||
const dbManager = DatabaseManager.aliceDb.collections.supportTicketPreset; | ||
const language = await CommandHelper.getLocale(interaction); | ||
const localization = new CreateSupportTicketWithPresetLocalization( | ||
language, | ||
); | ||
|
||
await InteractionHelper.deferReply(interaction); | ||
|
||
const ticketPresetsSearch = await dbManager.get( | ||
"id", | ||
{}, | ||
{ projection: { _id: 0, id: 1, name: 1 } }, | ||
); | ||
|
||
if (ticketPresetsSearch.size === 0) { | ||
return InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createReject( | ||
localization.getTranslation("noTicketPresetsExist"), | ||
), | ||
}); | ||
} | ||
|
||
const selectMenuInteraction = | ||
await SelectMenuCreator.createStringSelectMenu( | ||
interaction, | ||
{ | ||
content: MessageCreator.createWarn( | ||
localization.getTranslation("selectPresetPrompt"), | ||
), | ||
}, | ||
ticketPresetsSearch.map((v) => { | ||
return { | ||
value: v.id.toString(), | ||
label: v.name, | ||
}; | ||
}), | ||
[interaction.user.id], | ||
60, | ||
); | ||
|
||
if (!selectMenuInteraction) { | ||
return; | ||
} | ||
|
||
const preset = await dbManager.getOne( | ||
{ | ||
id: parseInt(selectMenuInteraction.values[0]), | ||
}, | ||
{ projection: { _id: 0, title: 1, description: 1 } }, | ||
); | ||
if (!preset) { | ||
return InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createReject( | ||
localization.getTranslation("presetNotFound"), | ||
), | ||
}); | ||
} | ||
|
||
await ModalCreator.createModal( | ||
selectMenuInteraction, | ||
"ticket-create", | ||
localization.getTranslation("modalTitle"), | ||
new TextInputBuilder() | ||
.setCustomId("title") | ||
.setRequired(true) | ||
.setStyle(TextInputStyle.Short) | ||
.setMaxLength(100) | ||
.setPlaceholder( | ||
localization.getTranslation("modalTitlePlaceholder"), | ||
) | ||
.setLabel(localization.getTranslation("modalTitleLabel")) | ||
.setValue(preset.title), | ||
new TextInputBuilder() | ||
.setCustomId("description") | ||
.setRequired(true) | ||
.setStyle(TextInputStyle.Paragraph) | ||
.setMaxLength(1500) | ||
.setPlaceholder( | ||
localization.getTranslation("modalDescriptionPlaceholder"), | ||
) | ||
.setLabel(localization.getTranslation("modalDescriptionLabel")) | ||
.setValue(preset.description), | ||
); | ||
|
||
// Delete the left-over select menu, which is a reply to the original interaction. | ||
await interaction.deleteReply(); | ||
}; | ||
|
||
export const config: ButtonCommand["config"] = { | ||
cooldown: 300, | ||
replyEphemeral: true, | ||
}; |
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
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
25 changes: 25 additions & 0 deletions
25
...Support Ticket/createSupportTicketWithPreset/CreateSupportTicketWithPresetLocalization.ts
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,25 @@ | ||
import { Localization } from "@alice-localization/base/Localization"; | ||
import { Translations } from "@alice-localization/base/Translations"; | ||
import { CreateSupportTicketWithPresetENTranslation } from "./translations/CreateSupportTicketWithPresetENTranslation"; | ||
|
||
export interface CreateSupportTicketWithPresetStrings { | ||
readonly noTicketPresetsExist: string; | ||
readonly selectPresetPrompt: string; | ||
readonly presetNotFound: string; | ||
readonly modalTitle: string; | ||
readonly modalTitleLabel: string; | ||
readonly modalTitlePlaceholder: string; | ||
readonly modalDescriptionLabel: string; | ||
readonly modalDescriptionPlaceholder: string; | ||
} | ||
|
||
/** | ||
* Localizations for the `createSupportTicketWithPreset` button command. | ||
*/ | ||
export class CreateSupportTicketWithPresetLocalization extends Localization<CreateSupportTicketWithPresetStrings> { | ||
protected override readonly localizations: Readonly< | ||
Translations<CreateSupportTicketWithPresetStrings> | ||
> = { | ||
en: new CreateSupportTicketWithPresetENTranslation(), | ||
}; | ||
} |
Oops, something went wrong.