Skip to content

Commit

Permalink
feat: add user installs (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Oct 27, 2024
1 parent cbfd805 commit 734fff9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/commands/other/waifu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { EmbedBuilder } from '@discordjs/builders';
import { parseURL } from '@sapphire/utilities';
import { Command, RegisterCommand, type InteractionArguments } from '@skyra/http-framework';
import { applyLocalizedBuilder, createSelectMenuChoiceName, resolveKey } from '@skyra/http-framework-i18n';
import { ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';

@RegisterCommand((builder) =>
applyLocalizedBuilder(builder, LanguageKeys.Commands.Waifu.RootName, LanguageKeys.Commands.Waifu.RootDescription).addStringOption((builder) =>
applyLocalizedBuilder(builder, LanguageKeys.Commands.Waifu.OptionRange) //
.addChoices(
applyLocalizedBuilder(builder, LanguageKeys.Commands.Waifu.RootName, LanguageKeys.Commands.Waifu.RootDescription)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
.addStringOption((builder) =>
applyLocalizedBuilder(builder, LanguageKeys.Commands.Waifu.OptionRange).addChoices(
createSelectMenuChoiceName(LanguageKeys.Commands.Waifu.KeyAll, { value: 'all' }),
createSelectMenuChoiceName(LanguageKeys.Commands.Waifu.KeyMediumQuality, { value: 'medium' }),
createSelectMenuChoiceName(LanguageKeys.Commands.Waifu.KeyHighQuality, { value: 'high' }),
createSelectMenuChoiceName(LanguageKeys.Commands.Waifu.KeyLowQuality, { value: 'low' })
)
)
)
)
export class UserCommand extends Command {
/** Potential sizes for the generated faces */
Expand Down
5 changes: 4 additions & 1 deletion src/commands/search/anime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { LanguageKeys } from '#lib/i18n/LanguageKeys';
import { AnimeCommand } from '#lib/structures/AnimeCommand';
import { Command, RegisterCommand } from '@skyra/http-framework';
import { applyLocalizedBuilder } from '@skyra/http-framework-i18n';
import { ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';

const Root = LanguageKeys.Commands.AniList.Anime;

@RegisterCommand((builder) =>
applyLocalizedBuilder(builder, Root.RootName, Root.RootDescription) //
applyLocalizedBuilder(builder, Root.RootName, Root.RootDescription)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
.addIntegerOption((option) => applyLocalizedBuilder(option, Root.OptionsAnime).setRequired(true).setAutocomplete(true))
)
export class UserCommand extends AnimeCommand<'anime'> {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/search/manga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { LanguageKeys } from '#lib/i18n/LanguageKeys';
import { AnimeCommand } from '#lib/structures/AnimeCommand';
import { Command, RegisterCommand } from '@skyra/http-framework';
import { applyLocalizedBuilder } from '@skyra/http-framework-i18n';
import { ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';

const Root = LanguageKeys.Commands.AniList.Manga;

@RegisterCommand((builder) =>
applyLocalizedBuilder(builder, Root.RootName, Root.RootDescription) //
applyLocalizedBuilder(builder, Root.RootName, Root.RootDescription)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
.addIntegerOption((option) => applyLocalizedBuilder(option, Root.OptionsManga).setRequired(true).setAutocomplete(true))
)
export class UserCommand extends AnimeCommand<'manga'> {
Expand Down
13 changes: 7 additions & 6 deletions src/lib/utilities/create-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import { SlashCommandBuilder } from '@discordjs/builders';
import { isNullish } from '@sapphire/utilities';
import { RegisterCommand } from '@skyra/http-framework';
import { applyLocalizedBuilder } from '@skyra/http-framework-i18n';
import { ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';

const Root = LanguageKeys.Commands.Anime;

export function createCommand(options: createCommand.Options): typeof WeebCommand {
const name = new URL(options.path).searchParams.get('name');
if (isNullish(name)) throw new TypeError('The provided path lacks of a "name" querystring parameter.');

const builder = applyLocalizedBuilder(
new SlashCommandBuilder(),
LanguageKeys.Commands.Anime.CommandName(name),
LanguageKeys.Commands.Anime.CommandDescription(name)
);
const builder = applyLocalizedBuilder(new SlashCommandBuilder(), Root.CommandName(name), Root.CommandDescription(name))
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.PrivateChannel);

if (options.user) {
builder.addUserOption((builder) =>
applyLocalizedBuilder(builder, LanguageKeys.Commands.Anime.UserOptionName, LanguageKeys.Commands.Anime.OptionDescription(name)) //
applyLocalizedBuilder(builder, Root.UserOptionName, Root.OptionDescription(name)) //
.setRequired(options.userRequired ?? false)
);
}
Expand Down

0 comments on commit 734fff9

Please # to comment.