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: cleanup and proper /pieces@3.4.0 support #500

Merged
merged 1 commit into from
Aug 5, 2022
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@sapphire/discord-utilities": "^2.11.5",
"@sapphire/discord.js-utilities": "^4.11.3",
"@sapphire/lexure": "^1.0.1",
"@sapphire/pieces": "^3.4.0",
"@sapphire/pieces": "^3.4.1",
"@sapphire/ratelimits": "^2.4.4",
"@sapphire/result": "^2.2.0",
"@sapphire/stopwatch": "^1.4.1",
"@sapphire/utilities": "^3.8.0",
"@sapphire/utilities": "^3.9.0",
"@types/object-hash": "^2.2.1",
"object-hash": "^3.0.0",
"tslib": "^2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/SapphireClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface SapphireClientOptions {
* @since 1.0.0
* @default undefined
*/
baseUserDirectory?: string | null;
baseUserDirectory?: URL | string | null;

/**
* Whether commands can be case insensitive
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/ArgumentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Argument } from './Argument';

export class ArgumentStore extends AliasStore<Argument> {
public constructor() {
super(Argument as any, { name: 'arguments' });
super(Argument, { name: 'arguments' });
}
}
6 changes: 3 additions & 3 deletions src/lib/structures/Command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AliasPiece, AliasPieceJSON, AliasStore, PieceContext } from '@sapphire/pieces';
import { ArgumentStream, IUnorderedStrategy, Lexer, Parser } from '@sapphire/lexure';
import { AliasPiece, AliasPieceJSON, AliasStore } from '@sapphire/pieces';
import { Awaitable, isNullish, NonNullObject } from '@sapphire/utilities';
import type { LocalizationMap } from 'discord-api-types/v10';
import {
Expand All @@ -10,7 +11,6 @@ import {
Permissions,
Snowflake
} from 'discord.js';
import { ArgumentStream, IUnorderedStrategy, Lexer, Parser } from '@sapphire/lexure';
import { Args } from '../parsers/Args';
import { BucketScope, RegisterBehavior } from '../types/Enums';
import { acquire } from '../utils/application-commands/ApplicationCommandRegistries';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Command<PreParseReturn = Args, O extends Command.Options = Command.
* @param context The context.
* @param options Optional Command settings.
*/
protected constructor(context: PieceContext, options: O = {} as O) {
public constructor(context: AliasPiece.Context, options: O = {} as O) {
super(context, { ...options, name: (options.name ?? context.name).toLowerCase() });
this.description = options.description ?? '';
this.detailedDescription = options.detailedDescription ?? '';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/CommandStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Command } from './Command';
*/
export class CommandStore extends AliasStore<Command> {
public constructor() {
super(Command as any, { name: 'commands' });
super(Command, { name: 'commands' });
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/structures/InteractionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Piece, PieceContext, PieceJSON, PieceOptions } from '@sapphire/pieces';
import { Piece, PieceJSON, PieceOptions } from '@sapphire/pieces';
import { Option } from '@sapphire/result';
import type { Awaitable } from '@sapphire/utilities';
import type { Interaction } from 'discord.js';
Expand All @@ -10,7 +10,7 @@ export abstract class InteractionHandler<O extends InteractionHandler.Options =
*/
public readonly interactionHandlerType: InteractionHandlerTypes;

public constructor(context: PieceContext, options: InteractionHandlerOptions) {
public constructor(context: Piece.Context, options: InteractionHandlerOptions) {
super(context, options);

this.interactionHandlerType = options.interactionHandlerType;
Expand Down Expand Up @@ -97,7 +97,7 @@ export interface InteractionHandlerJSON extends PieceJSON {
export type InteractionHandlerParseResult<Instance extends InteractionHandler> = Option.UnwrapSome<Awaited<ReturnType<Instance['parse']>>>;

export namespace InteractionHandler {
export type Context = PieceContext;
export type Context = Piece.Context;
export type Options = InteractionHandlerOptions;
export type JSON = InteractionHandlerJSON;
export type ParseResult<Instance extends InteractionHandler> = InteractionHandlerParseResult<Instance>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/InteractionHandlerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InteractionHandler, InteractionHandlerTypes, type InteractionHandlerOpt

export class InteractionHandlerStore extends Store<InteractionHandler> {
public constructor() {
super(InteractionHandler as any, { name: 'interaction-handlers' });
super(InteractionHandler, { name: 'interaction-handlers' });
}

public async run(interaction: Interaction) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/ListenerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Listener } from './Listener';

export class ListenerStore extends Store<Listener> {
public constructor() {
super(Listener as any, { name: 'listeners' });
super(Listener, { name: 'listeners' });
}
}
2 changes: 1 addition & 1 deletion src/lib/structures/PreconditionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PreconditionStore extends Store<Precondition> {
private readonly globalPreconditions: Precondition[] = [];

public constructor() {
super(Precondition as any, { name: 'preconditions' });
super(Precondition, { name: 'preconditions' });
}

public async messageRun(message: Message, command: MessageCommand, context: PreconditionContext = {}): AsyncPreconditionResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PreconditionSingleResolvableDetails } from '../PreconditionContain
* @example
* ```typescript
* export class CoreCommand extends Command {
* public constructor(context: PieceContext) {
* public constructor(context: Command.Context) {
* super(context, {
* preconditions: [
* 'GuildOnly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PreconditionSingleResolvableDetails } from '../PreconditionContain
* @example
* ```typescript
* export class CoreCommand extends Command {
* public constructor(context: PieceContext) {
* public constructor(context: Command.Context) {
* super(context, {
* preconditions: [
* 'GuildOnly',
Expand Down
3 changes: 1 addition & 2 deletions src/listeners/CoreInteractionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PieceContext } from '@sapphire/pieces';
import type { Interaction } from 'discord.js';
import { Listener } from '../lib/structures/Listener';
import { Events } from '../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.InteractionCreate> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.InteractionCreate });
}

Expand Down
3 changes: 1 addition & 2 deletions src/listeners/CoreReady.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../lib/structures/Listener';
import { Events } from '../lib/types/Events';
import { handleRegistryAPICalls } from '../lib/utils/application-commands/ApplicationCommandRegistries';

export class CoreEvent extends Listener {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ClientReady, once: true });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import type { AutocompleteInteraction } from 'discord.js';
import type { AutocompleteCommand } from '../../lib/structures/Command';
import { Listener } from '../../lib/structures/Listener';
import { Events } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PossibleAutocompleteInteraction> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PossibleAutocompleteInteraction });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import { Result } from '@sapphire/result';
import { Stopwatch } from '@sapphire/stopwatch';
import { Listener } from '../../../lib/structures/Listener';
import { ChatInputCommandAcceptedPayload, Events } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.ChatInputCommandAccepted> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ChatInputCommandAccepted });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import type { CommandInteraction } from 'discord.js';
import type { ChatInputCommand } from '../../../lib/structures/Command';
import { Listener } from '../../../lib/structures/Listener';
import { Events } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PossibleChatInputCommand> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PossibleChatInputCommand });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../../lib/structures/Listener';
import { Events, PreChatInputCommandRunPayload } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PreChatInputCommandRun> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PreChatInputCommandRun });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import { Result } from '@sapphire/result';
import { Stopwatch } from '@sapphire/stopwatch';
import { Listener } from '../../../lib/structures/Listener';
import { ContextMenuCommandAcceptedPayload, Events } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.ContextMenuCommandAccepted> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ContextMenuCommandAccepted });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import type { ContextMenuInteraction } from 'discord.js';
import type { ContextMenuCommand } from '../../../lib/structures/Command';
import { Listener } from '../../../lib/structures/Listener';
import { Events } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PossibleContextMenuCommand> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PossibleContextMenuCommand });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../../lib/structures/Listener';
import { Events, PreContextMenuCommandRunPayload } from '../../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PreContextMenuCommandRun> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PreContextMenuCommandRun });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { ChatInputCommandErrorPayload, Events } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.ChatInputCommandError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ChatInputCommandError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PieceContext } from '@sapphire/pieces';
import type { Command } from '../../lib/structures/Command';
import { Listener } from '../../lib/structures/Listener';
import { Events } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.CommandApplicationCommandRegistryError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.CommandApplicationCommandRegistryError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { AutocompleteInteractionPayload, Events } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.CommandAutocompleteInteractionError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.CommandAutocompleteInteractionError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { ContextMenuCommandErrorPayload, Events } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.ContextMenuCommandError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ContextMenuCommandError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { Events, InteractionHandlerError } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.InteractionHandlerError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.InteractionHandlerError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { Events, InteractionHandlerParseError as InteractionHandlerParseErrorPayload } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.InteractionHandlerParseError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.InteractionHandlerParseError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { Events, ListenerErrorPayload } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.ListenerError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.ListenerError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { Events, MessageCommandErrorPayload } from '../../lib/types/Events';

export class CoreEvent extends Listener<typeof Events.MessageCommandError> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.MessageCommandError });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import { Result } from '@sapphire/result';
import { Stopwatch } from '@sapphire/stopwatch';
import { Listener } from '../../lib/structures/Listener';
import { Events, MessageCommandAcceptedPayload } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.MessageCommandAccepted> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.MessageCommandAccepted });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PieceContext } from '@sapphire/pieces';
import type { Message } from 'discord.js';
import type { MessageCommand } from '../../lib/structures/Command';
import { Listener } from '../../lib/structures/Listener';
import { Events, MessageCommandRunPayload } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.MessageCommandRun> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.MessageCommandRun });
this.enabled = this.container.client.options.typing ?? false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PieceContext } from '@sapphire/pieces';
import type { Message } from 'discord.js';
import { Listener } from '../../lib/structures/Listener';
import { Events } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.MessageCreate> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.MessageCreate });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { PieceContext } from '@sapphire/pieces';
import { Listener } from '../../lib/structures/Listener';
import { Events, PreMessageCommandRunPayload } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PreMessageCommandRun> {
public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PreMessageCommandRun });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { GuildBasedChannelTypes, isDMChannel } from '@sapphire/discord.js-utilities';
import type { PieceContext } from '@sapphire/pieces';
import { Message, Permissions } from 'discord.js';
import { Listener } from '../../lib/structures/Listener';
import { Events } from '../../lib/types/Events';

export class CoreListener extends Listener<typeof Events.PreMessageParsed> {
private readonly requiredPermissions = new Permissions(['VIEW_CHANNEL', 'SEND_MESSAGES']).freeze();

public constructor(context: PieceContext) {
public constructor(context: Listener.Context) {
super(context, { event: Events.PreMessageParsed });
}

Expand Down
Loading