Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: expose a lot of typings #96

Merged
merged 4 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
PartialApplicationCommand,
PartialApplicationCommandPermissions
} from './constants';
import SlashCreator from './creator';
import { SlashCreator } from './creator';

/** The API handler for {@link SlashCreator}. */
class SlashCreatorAPI {
export class SlashCreatorAPI {
/** The parent creator. */
private readonly _creator: SlashCreator;

Expand Down Expand Up @@ -150,4 +150,4 @@ class SlashCreatorAPI {
}
}

export default SlashCreatorAPI;
export const API = SlashCreatorAPI;
126 changes: 64 additions & 62 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,12 @@ import {
PartialApplicationCommand,
PermissionNames
} from './constants';
import CommandContext from './structures/interfaces/commandContext';
import SlashCreator from './creator';
import { CommandContext } from './structures/interfaces/commandContext';
import { SlashCreator } from './creator';
import { oneLine, validateOptions } from './util';

/** The options for a {@link SlashCommand}. */
export interface SlashCommandOptions {
/** The type of command this is. Defaults to chat input, or a regular slash command. */
type?: ApplicationCommandType;
/** The name of the command. */
name: string;
/** The description of the command. */
description?: string;
/** The guild ID(s) that this command will be assigned to. */
guildIDs?: string | string[];
/** The required permission(s) for this command. */
requiredPermissions?: Array<string>;
/** The command's options. */
options?: ApplicationCommandOption[];
/** The throttling options for the command. */
throttling?: ThrottlingOptions;
/** Whether this command is used for unknown commands. */
unknown?: boolean;
/** Whether responses from this command should defer ephemeral messages. */
deferEphemeral?: boolean;
/** Whether to enable this command for everyone by default. `true` by default. */
defaultPermission?: boolean;
/** The command permissions per guild */
permissions?: CommandPermissions;
}

/**
* The command permission for a {@link SlashCommand}.
* The object is a guild ID mapped to an array of {@link ApplicationCommandPermissions}.
* @example
* {
* '<guild_id>': [
* {
* type: ApplicationCommandPermissionType.USER,
* id: '<user_id>',
* permission: true
* }
* ]
* }
*/
export interface CommandPermissions {
[guildID: string]: ApplicationCommandPermissions[];
}

/** The throttling options for a {@link SlashCommand}. */
export interface ThrottlingOptions {
/** Maximum number of usages of the command allowed in the time frame. */
usages: number;
/** Amount of time to count the usages of the command within (in seconds). */
duration: number;
}

/** @private */
export interface ThrottleObject {
start: number;
usages: number;
timeout: any;
}

/** Represents a Discord slash command. */
export default class SlashCommand {
export class SlashCommand {
/** The command's name. */
readonly commandName: string;
/** The type of command this is. */
Expand Down Expand Up @@ -331,3 +272,64 @@ export default class SlashCommand {
}
}
}

export const Command = SlashCommand;

/** The options for a {@link SlashCommand}. */
export interface SlashCommandOptions {
/** The type of command this is. Defaults to chat input, or a regular slash command. */
type?: ApplicationCommandType;
/** The name of the command. */
name: string;
/** The description of the command. */
description?: string;
/** The guild ID(s) that this command will be assigned to. */
guildIDs?: string | string[];
/** The required permission(s) for this command. */
requiredPermissions?: Array<string>;
/** The command's options. */
options?: ApplicationCommandOption[];
/** The throttling options for the command. */
throttling?: ThrottlingOptions;
/** Whether this command is used for unknown commands. */
unknown?: boolean;
/** Whether responses from this command should defer ephemeral messages. */
deferEphemeral?: boolean;
/** Whether to enable this command for everyone by default. `true` by default. */
defaultPermission?: boolean;
/** The command permissions per guild */
permissions?: CommandPermissions;
}

/**
* The command permission for a {@link SlashCommand}.
* The object is a guild ID mapped to an array of {@link ApplicationCommandPermissions}.
* @example
* {
* '<guild_id>': [
* {
* type: ApplicationCommandPermissionType.USER,
* id: '<user_id>',
* permission: true
* }
* ]
* }
*/
export interface CommandPermissions {
[guildID: string]: ApplicationCommandPermissions[];
}

/** The throttling options for a {@link SlashCommand}. */
export interface ThrottlingOptions {
/** Maximum number of usages of the command allowed in the time frame. */
usages: number;
/** Amount of time to count the usages of the command within (in seconds). */
duration: number;
}

/** @private */
export interface ThrottleObject {
start: number;
usages: number;
timeout: any;
}
11 changes: 7 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { IncomingMessage } from 'http';
import SlashCommand from './command';
import CommandContext from './structures/interfaces/commandContext';
import SlashCreator from './creator';
import { SlashCommand } from './command';
import { CommandContext } from './structures/interfaces/commandContext';
import { SlashCreator } from './creator';
import { RespondFunction, TransformedRequest } from './server';
import ComponentContext from './structures/interfaces/componentContext';
import { ComponentContext } from './structures/interfaces/componentContext';
import { MessageData } from './structures/message';
import { version } from '../package.json';

export const VERSION: string = version;

export const API_VERSION = 8;
export const INTERACTION_VERSION = 1;
Expand Down
Loading