-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(unicode): add pagination (#271)
- Loading branch information
Showing
10 changed files
with
325 additions
and
218 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
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,23 @@ | ||
import { getUnicodeInformationEmbeds } from '#lib/unicode'; | ||
import { displaySelectMenuIndex, makeActionRow } from '#lib/utilities/discord-utilities'; | ||
import { InteractionHandler, type Interactions } from '@skyra/http-framework'; | ||
import { getSupportedLanguageT } from '@skyra/http-framework-i18n'; | ||
import type { APIActionRowComponent, APIStringSelectComponent } from 'discord-api-types/v10'; | ||
|
||
export class UserHandler extends InteractionHandler { | ||
public async run(interaction: Interactions.MessageComponentStringSelect) { | ||
const parameters = interaction.values[0].split('.') as Parameters; | ||
const pageIndex = Number(parameters[0]); | ||
const characters = [...Buffer.from(parameters[1], 'base64').toString('utf8')]; | ||
|
||
const { content } = interaction.message; | ||
const row = interaction.message.components![0] as APIActionRowComponent<APIStringSelectComponent>; | ||
|
||
const t = getSupportedLanguageT(interaction); | ||
const component = displaySelectMenuIndex(row.components[0], pageIndex); | ||
const embeds = getUnicodeInformationEmbeds(t, characters); | ||
return interaction.update({ content, embeds, components: [makeActionRow([component])] }); | ||
} | ||
} | ||
|
||
type Parameters = [pageIndex: `${number}`, characters: string]; |
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 |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import type { APIChannel } from 'discord-api-types/v10'; | ||
import { | ||
ComponentType, | ||
type APIActionRowComponent, | ||
type APIChannel, | ||
type APIMessageActionRowComponent, | ||
type APIStringSelectComponent | ||
} from 'discord-api-types/v10'; | ||
|
||
export function isNsfwChannel(channel: Partial<APIChannel>): boolean { | ||
return 'nsfw' in channel ? (channel.nsfw ?? false) : false; | ||
} | ||
|
||
export function makeActionRow<Component extends APIMessageActionRowComponent>( | ||
components: Component[] | ||
): APIActionRowComponent<APIMessageActionRowComponent> { | ||
return { type: ComponentType.ActionRow, components }; | ||
} | ||
|
||
export function displaySelectMenuIndex(component: APIStringSelectComponent, index: number): APIStringSelectComponent { | ||
return { | ||
...component, | ||
options: component.options.map((option, optionIndex) => ({ | ||
...option, | ||
default: optionIndex === index | ||
})) | ||
}; | ||
} |
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
Oops, something went wrong.