Skip to content

Commit 457ca51

Browse files
committed
docs: add jsdoc for project
1 parent 4af3843 commit 457ca51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+459
-5
lines changed

src/commands/command.discovery.ts

+18
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,39 @@ export interface BaseCommandMeta extends BaseApplicationCommandData {
55
guilds?: Snowflake[];
66
}
77

8+
/**
9+
* Represents a command discovery.
10+
* @abstract
11+
* @url https://necord.org/interactions/slash-commands
12+
*/
813
export abstract class CommandDiscovery<
914
T extends BaseCommandMeta = BaseCommandMeta
1015
> extends NecordBaseDiscovery<T> {
16+
/**
17+
* Returns the command name.
18+
*/
1119
public getName() {
1220
return this.meta.name;
1321
}
1422

23+
/**
24+
* Sets the command guilds for register.
25+
* @param guilds
26+
*/
1527
public setGuilds(guilds: Snowflake[]) {
1628
this.meta.guilds = guilds;
1729
}
1830

31+
/**
32+
* Checks if the command has a guild.
33+
*/
1934
public hasGuild(guild: Snowflake) {
2035
return this.meta.guilds?.includes(guild);
2136
}
2237

38+
/**
39+
* Returns the guilds.
40+
*/
2341
public getGuilds(): Snowflake[] {
2442
return this.meta.guilds;
2543
}

src/commands/commands.service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { CommandDiscovery } from './command.discovery';
44
import { ContextMenusService } from './context-menus';
55
import { SlashCommandsService } from './slash-commands';
66

7+
/**
8+
* Represents a service that manages commands.
9+
* @url https://necord.org/interactions/slash-commands
10+
*/
711
@Injectable()
812
export class CommandsService {
913
private readonly logger = new Logger(CommandsService.name);
@@ -14,6 +18,10 @@ export class CommandsService {
1418
private readonly slashCommandsService: SlashCommandsService
1519
) {}
1620

21+
/**
22+
* Registers all commands.
23+
*
24+
*/
1725
public async registerAllCommands() {
1826
const guilds = new Set(this.getCommandsByGuilds().keys());
1927

@@ -24,6 +32,10 @@ export class CommandsService {
2432
this.logger.log(`Successfully reloaded application commands.`);
2533
}
2634

35+
/**
36+
* Registers commands in a guild.
37+
* @param guildId
38+
*/
2739
public async registerInGuild(guildId: string) {
2840
const commands = this.getGuildCommands(guildId);
2941

src/commands/context-menus/context-menu.discovery.ts

+21
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,44 @@ import {
66
} from 'discord.js';
77
import { CommandDiscovery } from '../command.discovery';
88

9+
/**
10+
* The context menu metadata.
11+
*/
912
export type ContextMenuMeta = (MessageApplicationCommandData | UserApplicationCommandData) & {
1013
guilds?: Snowflake[];
1114
};
1215

16+
/**
17+
* The context menu discovery.
18+
* @see CommandDiscovery
19+
* @see ContextMenuMeta
20+
*/
1321
export class ContextMenuDiscovery extends CommandDiscovery<ContextMenuMeta> {
22+
/**
23+
* Gets the discovery type.
24+
*/
1425
public getType() {
1526
return this.meta.type;
1627
}
1728

29+
/**
30+
* Type guard for the context menu discovery.
31+
*/
1832
public isContextMenu(): this is ContextMenuDiscovery {
1933
return true;
2034
}
2135

36+
/**
37+
* Executes the context menu discovery.
38+
* @param interaction The interaction to execute.
39+
*/
2240
public execute(interaction: ContextMenuCommandInteraction): any {
2341
return super.execute([interaction]);
2442
}
2543

44+
/**
45+
* Converts the context menu discovery to JSON.
46+
*/
2647
public override toJSON() {
2748
return this.meta;
2849
}

src/commands/context-menus/context-menus.service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import { Collection } from 'discord.js';
22
import { Injectable, Logger } from '@nestjs/common';
33
import { ContextMenuDiscovery, ContextMenuMeta } from './context-menu.discovery';
44

5+
/**
6+
* Service that manages context menus.
7+
* @see ContextMenuDiscovery
8+
* @see ContextMenuMeta
9+
* @see ContextMenu
10+
* @see MessageCommand
11+
* @see UserCommand
12+
*/
513
@Injectable()
614
export class ContextMenusService {
715
private readonly logger = new Logger(ContextMenusService.name);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { ContextMenuDiscovery, ContextMenuMeta } from '../context-menu.discovery';
22
import { Reflector } from '@nestjs/core';
33

4+
/**
5+
* Decorator that marks a method as a context menu.
6+
* @param options The context menu options.
7+
* @returns The decorated method.
8+
* @see ContextMenuDiscovery
9+
* @see ContextMenuMeta
10+
* @see MessageCommand
11+
* @see UserCommand
12+
* @url https://necord.org/interactions/context-menus
13+
*/
414
export const ContextMenu = Reflector.createDecorator<ContextMenuMeta, ContextMenuDiscovery>({
515
transform: options => new ContextMenuDiscovery(options)
616
});

src/commands/context-menus/decorators/message-command.decorator.ts

+16
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,21 @@ import { ContextMenuMeta } from '../context-menu.discovery';
22
import { ApplicationCommandType } from 'discord.js';
33
import { ContextMenu } from './context-menu.decorator';
44

5+
/**
6+
* Decorator that marks a method as a message context menu.
7+
* @param options The context menu options.
8+
* @returns The decorated method.
9+
* @see ContextMenu
10+
* @see ContextMenuMeta
11+
* @see TargetMessage
12+
* @url https://necord.org/interactions/context-menus#message-commands
13+
* @example
14+
* ```ts
15+
* @MessageCommand({ name: 'quote', type: 'MESSAGE' })
16+
* public async quote(@TargetMessage() message: Message) {
17+
* message.reply('Quoting...');
18+
* }
19+
* ```
20+
*/
521
export const MessageCommand = (options: Omit<ContextMenuMeta, 'type'>) =>
622
ContextMenu({ type: ApplicationCommandType.Message, ...options });

src/commands/context-menus/decorators/target.decorator.ts

+42
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ export const Target = createParamDecorator((_, context) => {
1515
: interaction.options.getUser('user');
1616
});
1717

18+
/**
19+
* Decorator that injects the target message of a message context menu command.
20+
* @see TargetUser
21+
* @see TargetMember
22+
* @see MessageCommand
23+
* @returns The target message.
24+
* @example
25+
* ```ts
26+
* @MessageCommand({ name: 'quote', type: 'MESSAGE' })
27+
* public async quote(@TargetMessage() message: Message) {
28+
* message.reply('Quoting...');
29+
* }
30+
* ```
31+
*/
1832
export const TargetMessage = createParamDecorator((_, context) => {
1933
const necordContext = NecordExecutionContext.create(context);
2034
const [interaction] = necordContext.getContext<'interactionCreate'>();
@@ -24,6 +38,20 @@ export const TargetMessage = createParamDecorator((_, context) => {
2438
return interaction.targetMessage;
2539
});
2640

41+
/**
42+
* Decorator that injects the target user of a user context menu command.
43+
* @see TargetMessage
44+
* @see TargetMember
45+
* @see UserCommand
46+
* @returns The target user.
47+
* @example
48+
* ```ts
49+
* @UserCommand({ name: 'kick', type: 'USER' })
50+
* public async avatar(@TargetUser() user: User) {
51+
* user.avatarURL();
52+
* }
53+
* ```
54+
*/
2755
export const TargetUser = createParamDecorator((_, context) => {
2856
const necordContext = NecordExecutionContext.create(context);
2957
const [interaction] = necordContext.getContext<'interactionCreate'>();
@@ -33,6 +61,20 @@ export const TargetUser = createParamDecorator((_, context) => {
3361
return interaction.targetUser;
3462
});
3563

64+
/**
65+
* Decorator that injects the target member of a user context menu command.
66+
* @see TargetMessage
67+
* @see TargetUser
68+
* @see UserCommand
69+
* @returns The target member.
70+
* @example
71+
* ```ts
72+
* @UserCommand({ name: 'ban', type: 'USER' })
73+
* public async ban(@TargetMember() member: GuildMember) {
74+
* member.ban();
75+
* }
76+
* ```
77+
*/
3678
export const TargetMember = createParamDecorator((_, context) => {
3779
const necordContext = NecordExecutionContext.create(context);
3880
const [interaction] = necordContext.getContext<'interactionCreate'>();

src/commands/context-menus/decorators/user-command.decorator.ts

+17
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,22 @@ import { ApplicationCommandType } from 'discord.js';
22
import { ContextMenuMeta } from '../context-menu.discovery';
33
import { ContextMenu } from './context-menu.decorator';
44

5+
/**
6+
* Decorator that marks a method as a user context menu.
7+
* @param options The context menu options.
8+
* @returns The decorated method.
9+
* @see ContextMenu
10+
* @see ContextMenuMeta
11+
* @see TargetUser
12+
* @see TargetMessage
13+
* @url https://necord.org/interactions/context-menus#user-commands
14+
* @example
15+
* ```ts
16+
* @UserCommand({ name: 'ping' })
17+
* public async ping(@TargetUser() user: User) {
18+
* user.send('Pong!');
19+
* }
20+
* ```
21+
*/
522
export const UserCommand = (options: Omit<ContextMenuMeta, 'type'>) =>
623
ContextMenu({ type: ApplicationCommandType.User, ...options });

src/commands/slash-commands/autocomplete/autocomplete.interceptor.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { Observable, of } from 'rxjs';
33
import { AutocompleteContext, NecordExecutionContext } from '../../../context';
44
import { AutocompleteInteraction } from 'discord.js';
55

6+
/**
7+
* The autocomplete interceptor.
8+
* @see AutocompleteContext
9+
* @see AutocompleteInteraction
10+
* @url https://necord.org/interactions/slash-commands#autocomplete
11+
*/
612
@Injectable()
713
export abstract class AutocompleteInterceptor implements NestInterceptor {
814
public abstract transformOptions(interaction: AutocompleteInteraction): void | Promise<void>;

src/commands/slash-commands/decorators/slash-command.decorator.ts

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import { SlashCommandDiscovery, SlashCommandMeta } from '../slash-command.discov
22
import { ApplicationCommandType } from 'discord.js';
33
import { Reflector } from '@nestjs/core';
44

5+
/**
6+
* Decorator that marks a method as a slash command.
7+
* @param options The slash command options.
8+
* @returns The decorated method.
9+
* @see SlashCommandDiscovery
10+
* @see SlashCommandMeta
11+
* @url https://necord.org/interactions/slash-commands
12+
*
13+
*/
514
export const SlashCommand = Reflector.createDecorator<
615
Omit<SlashCommandMeta, 'type' | 'options'>,
716
SlashCommandDiscovery

src/commands/slash-commands/decorators/subcommand-group.decorator.ts

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { SlashCommand } from './slash-command.decorator';
55
import { noop } from 'rxjs';
66
import { Reflector } from '@nestjs/core';
77

8+
/**
9+
* Decorator that marks a method as a subcommand.
10+
* @param options The subcommand options.
11+
* @returns The decorated method.
12+
* @see SlashCommandDiscovery
13+
* @url https://necord.org/interactions/slash-commands#groups
14+
*/
815
export const SubcommandGroup = Reflector.createDecorator<
916
Omit<SlashCommandMeta, 'type' | 'options' | 'guilds' | 'defaultMemberPermissions'>,
1017
SlashCommandDiscovery
@@ -16,6 +23,14 @@ export const SubcommandGroup = Reflector.createDecorator<
1623
})
1724
});
1825

26+
/**
27+
* Factory that creates a decorator that marks a class as a slash command group.
28+
* @param rootOptions
29+
* @returns The decorator.
30+
* @see SlashCommand
31+
* @see SubcommandGroup
32+
* @url https://necord.org/interactions/slash-commands#groups
33+
*/
1934
export const createCommandGroupDecorator = (rootOptions: Omit<SlashCommandMeta, 'type'>) => {
2035
const rootCommand = SlashCommand(rootOptions);
2136

src/commands/slash-commands/decorators/subcommand.decorator.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { SlashCommandDiscovery, SlashCommandMeta } from '../slash-command.discovery';
22
import { ApplicationCommandOptionType } from 'discord.js';
33
import { Reflector } from '@nestjs/core';
4+
import { SlashCommand } from './slash-command.decorator';
45

6+
/**
7+
* Decorator that marks a method as a subcommand.
8+
* @param options The subcommand options.
9+
* @returns The decorated method.
10+
* @see SlashCommandDiscovery
11+
* @url https://necord.org/interactions/slash-commands#groups
12+
*/
513
export const Subcommand = Reflector.createDecorator<
614
Omit<SlashCommandMeta, 'type' | 'options' | 'guilds' | 'defaultMemberPermissions'>,
715
SlashCommandDiscovery

src/commands/slash-commands/options/attachment-option.decorator.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApplicationCommandOptionType, APIApplicationCommandAttachmentOption } from 'discord.js';
22
import { createOptionDecorator } from './option.util';
33

4+
/**
5+
* Param decorator that marks a method as an attachment option.
6+
* @param options The attachment options.
7+
* @returns The decorated method.
8+
* @url https://necord.org/interactions/slash-commands#options
9+
*/
410
export const AttachmentOption = createOptionDecorator<APIApplicationCommandAttachmentOption>(
511
ApplicationCommandOptionType.Attachment,
612
'getAttachment'

src/commands/slash-commands/options/boolean-option.decorator.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApplicationCommandOptionType, APIApplicationCommandBooleanOption } from 'discord.js';
22
import { createOptionDecorator } from './option.util';
33

4+
/**
5+
* Param decorator that marks a method as a boolean option.
6+
* @param options The boolean options.
7+
* @returns The decorated method.
8+
* @url https://necord.org/interactions/slash-commands#options
9+
*/
410
export const BooleanOption = createOptionDecorator<APIApplicationCommandBooleanOption>(
511
ApplicationCommandOptionType.Boolean,
612
'getBoolean'

src/commands/slash-commands/options/channel-option.decorator.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApplicationCommandOptionType, APIApplicationCommandChannelOption } from 'discord.js';
22
import { createOptionDecorator } from './option.util';
33

4+
/**
5+
* Param decorator that marks a method as a channel option.
6+
* @param options The channel options.
7+
* @returns The decorated method.
8+
* @url https://necord.org/interactions/slash-commands#options
9+
*/
410
export const ChannelOption = createOptionDecorator<APIApplicationCommandChannelOption>(
511
ApplicationCommandOptionType.Channel,
612
'getChannel'

src/commands/slash-commands/options/integer-option.decorator.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApplicationCommandOptionType, APIApplicationCommandIntegerOption } from 'discord.js';
22
import { createOptionDecorator } from './option.util';
33

4+
/**
5+
* Param decorator that marks a method as an integer option.
6+
* @param options The integer options.
7+
* @returns The decorated method.
8+
* @url https://necord.org/interactions/slash-commands#options
9+
*/
410
export const IntegerOption = createOptionDecorator<APIApplicationCommandIntegerOption>(
511
ApplicationCommandOptionType.Integer,
612
'getInteger'

src/commands/slash-commands/options/member-option.decorator.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { ApplicationCommandOptionType, APIApplicationCommandUserOption } from 'discord.js';
22
import { createOptionDecorator } from './option.util';
33

4+
/**
5+
* Param decorator that marks a method as a member option.
6+
* @param options The member options.
7+
* @returns The decorated method.
8+
* @url https://necord.org/interactions/slash-commands#options
9+
*/
410
export const MemberOption = createOptionDecorator<APIApplicationCommandUserOption>(
511
ApplicationCommandOptionType.User,
612
'getMember'

0 commit comments

Comments
 (0)