Skip to content

Commit

Permalink
feat: support for djs v14
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jul 27, 2022
1 parent 3a6df4a commit 78aba15
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 333 deletions.
310 changes: 56 additions & 254 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gcommands",
"version": "9.3.0",
"version": "10.0.0",
"description": "Powerful and flexible framework!",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -49,7 +49,6 @@
"license": "ISC",
"dependencies": {
"@discordjs/rest": "^1.0.0",
"discord-api-types": "^0.30.0",
"ms": "^2.1.3",
"tslib": "^2.3.1",
"zod": "^3.11.6"
Expand All @@ -68,7 +67,7 @@
"@typescript-eslint/eslint-plugin": "5.31.0",
"@typescript-eslint/parser": "5.31.0",
"conventional-changelog-cli": "2.2.2",
"discord.js": "13.9.1",
"discord.js": "^14.0.3",
"eslint": "8.20.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/ComponentHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setTimeout } from 'node:timers';
import { Collection, MessageComponentInteraction } from 'discord.js';
import { Collection, InteractionType, MessageComponentInteraction, ModalSubmitInteraction } from 'discord.js';
import { AutoDeferType, GClient } from '../lib/GClient';
import { Components } from '../lib/managers/ComponentManager';
import { Handlers } from '../lib/managers/HandlerManager';
Expand All @@ -11,7 +11,7 @@ import { Events, Logger } from '../lib/util/logger/Logger';
const cooldowns = new Collection<string, Collection<string, number>>();

export async function ComponentHandler(
interaction: MessageComponentInteraction,
interaction: MessageComponentInteraction | ModalSubmitInteraction,
) {
const client = interaction.client as GClient;

Expand Down Expand Up @@ -66,9 +66,9 @@ export async function ComponentHandler(
customId: interaction.customId,
arguments: args,
values: interaction.isSelectMenu() ? interaction.values : undefined,
fields: interaction.isModalSubmit() ? interaction.fields : undefined,
fields: interaction.type === InteractionType.ModalSubmit ? interaction.fields : undefined,
deferReply: interaction.deferReply.bind(interaction),
deferUpdate: interaction.deferUpdate.bind(interaction),
deferUpdate: interaction.type !== InteractionType.ModalSubmit ? interaction.deferUpdate.bind(interaction): () => { throw new Error('Cannot defer update in modal submit interaction'); },
deleteReply: interaction.deleteReply.bind(interaction),
editReply: interaction.editReply.bind(interaction),
fetchReply: interaction.fetchReply.bind(interaction),
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/InteractionCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { setTimeout } from 'node:timers';
import {
Collection,
CommandInteraction,
ContextMenuInteraction,
ContextMenuCommandInteraction,
} from 'discord.js';
import { AutoDeferType, GClient } from '../lib/GClient';
import { Commands } from '../lib/managers/CommandManager';
Expand All @@ -14,7 +14,7 @@ import { Events, Logger } from '../lib/util/logger/Logger';
const cooldowns = new Collection<string, Collection<string, number>>();

export async function InteractionCommandHandler(
interaction: CommandInteraction | ContextMenuInteraction,
interaction: CommandInteraction | ContextMenuCommandInteraction,
) {
const client = interaction.client as GClient;

Expand Down
7 changes: 4 additions & 3 deletions src/handlers/MessageCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
CommandInteractionOptionResolver,
Guild,
Message,
MessageAttachment,
MessagePayload,
ReplyMessageOptions,
SelectMenuInteraction,
TextChannel,
User,
ComponentType,
Attachment,
} from 'discord.js';
import type { GClient } from '../lib/GClient';
import { Commands } from '../lib/managers/CommandManager';
Expand All @@ -30,7 +31,7 @@ const cooldowns = new Collection<string, Collection<string, number>>();

const checkValidation = async (
arg: MessageArgumentTypes,
content: string | MessageAttachment,
content: string | Attachment,
client: Client,
guild: Guild,
argument: Argument,
Expand Down Expand Up @@ -75,7 +76,7 @@ const checkValidation = async (
const component: SelectMenuInteraction =
(await channel.awaitMessageComponent({
filter: m =>
m.componentType === 'SELECT_MENU' &&
m.componentType === ComponentType.SelectMenu &&
m.user.id === user.id &&
m.channelId === channel.id &&
m.message.id === message.id &&
Expand Down
6 changes: 3 additions & 3 deletions src/lib/managers/HandlerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
AutocompleteInteraction,
Collection,
CommandInteraction,
ContextMenuInteraction,
ContextMenuCommandInteraction,
Message,
MessageComponentInteraction,
ModalSubmitInteraction,
Expand All @@ -17,7 +17,7 @@ import type { Component } from '../structures/Component';

export class HandlerManager {
public interactionCommandHandler: (
interaction: CommandInteraction | ContextMenuInteraction,
interaction: CommandInteraction | ContextMenuCommandInteraction,
) => any;
public messageCommandHandler: (
message: Message,
Expand All @@ -43,7 +43,7 @@ export class HandlerManager {
}

public setInteractionCommandHandler(
handler: (interaction: CommandInteraction | ContextMenuInteraction) => any,
handler: (interaction: CommandInteraction | ContextMenuCommandInteraction) => any,
): HandlerManager {
this.interactionCommandHandler = handler;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/managers/ListenerManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientEvents, Collection, WSEventType } from 'discord.js';
import { ClientEvents, Collection, GatewayDispatchEvents } from 'discord.js';
import { Plugins } from './PluginManager';
import type { GClient } from '../GClient';
import { Listener } from '../structures/Listener';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ListenerManager extends Collection<string, Listener> {
if (maxListeners !== 0) this.client.setMaxListeners(maxListeners - 1);

listener.ws
? this.client.ws.off(listener.event as WSEventType, listener._run)
? this.client.ws.off(listener.event as GatewayDispatchEvents, listener._run)
: this.client.off(
listener.event as keyof ClientEvents,
listener._run,
Expand Down
3 changes: 1 addition & 2 deletions src/lib/structures/Argument.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ApplicationCommandOptionType } from 'discord-api-types/v9';
import { ApplicationCommandOptionType, Locale, LocaleString } from 'discord.js';
import { z } from 'zod';
import type { AutocompleteContext } from './contexts/AutocompleteContext';
import { Locale, LocaleString } from '../util/common';
import { Logger } from '../util/logger/Logger';
import { commandAndOptionNameRegexp } from '../util/regexes';

Expand Down
5 changes: 2 additions & 3 deletions src/lib/structures/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { Argument, ArgumentOptions } from './Argument';
import type { CommandContext } from './contexts/CommandContext';
import { AutoDeferType, GClient } from '../GClient';
import { Commands } from '../managers/CommandManager';
import { Locale, LocaleString } from '../util/common';
import { Logger } from '../util/logger/Logger';
import { commandAndOptionNameRegexp } from '../util/regexes';
import { PermissionResolvable, Permissions } from 'discord.js';
import { PermissionResolvable, PermissionsBitField, Locale, LocaleString } from 'discord.js';
import { Util } from '../util/Util';

export enum CommandType {
Expand Down Expand Up @@ -221,7 +220,7 @@ export class Command {
description_localizations: this.descriptionLocalizations,
dm_permission: this.dmPermission,
default_member_permissions: this.defaultMemberPermissions
? new Permissions(
? new PermissionsBitField(
this.defaultMemberPermissions,
).bitfield.toString()
: null,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/structures/Listener.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ClientEvents, WSEventType } from 'discord.js';
import type { ClientEvents, GatewayDispatchEvents } from 'discord.js';
import { z } from 'zod';
import type { GClient } from '../GClient';
import { Listeners } from '../managers/ListenerManager';
import { Logger } from '../util/logger/Logger';

export interface ListenerOptions<
WS extends boolean,
Event extends WS extends true ? WSEventType : keyof ClientEvents,
Event extends WS extends true ? GatewayDispatchEvents : keyof ClientEvents,
> {
event: Event | string;
name: string;
Expand All @@ -32,8 +32,8 @@ const validationSchema = z
export class Listener<
WS extends boolean = boolean,
Event extends WS extends true
? WSEventType
: keyof ClientEvents = WS extends true ? WSEventType : keyof ClientEvents,
? GatewayDispatchEvents
: keyof ClientEvents = WS extends true ? GatewayDispatchEvents : keyof ClientEvents,
> {
public client: GClient;
public event: Event | string;
Expand Down Expand Up @@ -77,7 +77,7 @@ export class Listener<

if (this.ws)
client.ws[this.once ? 'once' : 'on'](
this.event as WSEventType,
this.event as GatewayDispatchEvents,
this._run.bind(this),
);
else
Expand Down
6 changes: 3 additions & 3 deletions src/lib/structures/arguments/Attachment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MessageAttachment } from 'discord.js';
import { Attachment } from 'discord.js';
import { MessageArgumentTypeBase } from './base';
import { Argument, ArgumentType } from '../Argument';

export class AttachmentType extends MessageArgumentTypeBase {
value;

validate(attachment: string | MessageAttachment) {
if (attachment instanceof MessageAttachment) {
validate(attachment: string | Attachment) {
if (attachment instanceof Attachment) {
this.value = attachment;
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/structures/contexts/CommandContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
CacheType,
CommandInteraction,
CommandInteractionOptionResolver,
ContextMenuInteraction,
ContextMenuCommandInteraction,
GuildCacheMessage,
InteractionDeferReplyOptions,
InteractionReplyOptions,
Expand All @@ -16,7 +16,7 @@ import type { Command } from '../Command';

export interface CommandContextOptions<Cached extends CacheType = CacheType>
extends ContextOptions<Cached> {
interaction?: CommandInteraction | ContextMenuInteraction;
interaction?: CommandInteraction | ContextMenuCommandInteraction;
message?: Message;
command: Command;
arguments: CommandInteractionOptionResolver<Cached>;
Expand Down Expand Up @@ -44,7 +44,7 @@ export class CommandContext<
Cached extends CacheType = CacheType,
> extends Context<Cached> {
[key: string]: any;
public interaction?: CommandInteraction | ContextMenuInteraction;
public interaction?: CommandInteraction | ContextMenuCommandInteraction;
public message?: Message;
public readonly command: Command;
public readonly commandName: string;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/structures/contexts/ComponentContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
InteractionReplyOptions,
MessageComponentInteraction,
MessagePayload,
ModalSubmitFieldsResolver,
ModalSubmitFields,
ModalSubmitInteraction,
WebhookEditMessageOptions,
} from 'discord.js';
Expand All @@ -21,7 +21,7 @@ export interface ComponentContextOptions<Cached extends CacheType = CacheType>
customId: string;
arguments: Array<string>;
values?: Array<string>;
fields?: ModalSubmitFieldsResolver;
fields?: ModalSubmitFields;
deferReply: <Fetch extends boolean = boolean>(
options?: InteractionDeferReplyOptions & { fetchReply?: Fetch },
) => Promise<Fetch extends true ? GuildCacheMessage<Cached> : void>;
Expand Down Expand Up @@ -55,7 +55,7 @@ export class ComponentContext<
public readonly customId: string;
public arguments: Array<string>;
public values?: Array<string>;
public fields?: ModalSubmitFieldsResolver;
public fields?: ModalSubmitFields;
public deferred = false;
public replied = false;
public deferReply: <Fetch extends boolean = boolean>(
Expand Down
8 changes: 4 additions & 4 deletions src/lib/structures/contexts/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Guild,
GuildMember,
GuildTextBasedChannel,
Permissions,
PermissionsBitField,
Snowflake,
TextBasedChannel,
User,
Expand All @@ -13,7 +13,7 @@ import type { AutocompleteContext } from './AutocompleteContext';
import type { CommandContext } from './CommandContext';
import type { ComponentContext } from './ComponentContext';
import type { GClient } from '../../GClient';
import type { APIInteractionGuildMember } from 'discord-api-types/v9';
import type { APIInteractionGuildMember } from 'discord.js';

export interface ContextOptions<Cached extends CacheType = CacheType> {
channel: CacheTypeReducer<
Expand All @@ -28,7 +28,7 @@ export interface ContextOptions<Cached extends CacheType = CacheType> {
guild: CacheTypeReducer<Cached, Guild, null>;
guildId: CacheTypeReducer<Cached, Snowflake>;
member: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
memberPermissions: CacheTypeReducer<Cached, Readonly<PermissionsBitField>>;
user: User;
}

Expand All @@ -54,7 +54,7 @@ export class Context<Cached extends CacheType = CacheType> {
>;
public user: User;
public userId: Snowflake;
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
public memberPermissions: CacheTypeReducer<Cached, Readonly<PermissionsBitField>>;
public type: 'COMMAND' | 'BUTTON' | 'SELECT_MENU' | 'AUTOCOMPLETE';

constructor(client: GClient, options: ContextOptions<Cached>) {
Expand Down
38 changes: 0 additions & 38 deletions src/lib/util/common.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/util/sync.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setTimeout } from 'node:timers';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { Routes } from 'discord.js';
import { Logger } from './logger/Logger';
import type { GClient } from '../GClient';
import { Commands } from '../managers/CommandManager';
Expand Down

0 comments on commit 78aba15

Please sign in to comment.