Skip to content

Commit

Permalink
feat(deps)!: support for djs v14 (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Jan 8, 2023
1 parent a5c93ef commit 7674782
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 704 deletions.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -19,10 +19,10 @@
"@actions/core": "^1.10.0",
"@commitlint/cli": "^17.4.0",
"@commitlint/config-conventional": "^17.4.0",
"@favware/cliff-jumper": "^1.9.0",
"@favware/cliff-jumper": "^1.10.0",
"@favware/npm-deprecate": "^1.0.7",
"@sapphire/eslint-config": "^4.3.8",
"@sapphire/framework": "^3.2.0",
"@sapphire/framework": "4.0.0",
"@sapphire/pieces": "^3.6.0",
"@sapphire/prettier-config": "^1.4.4",
"@sapphire/stopwatch": "^1.5.0",
Expand All @@ -35,8 +35,8 @@
"@typescript-eslint/parser": "^5.48.0",
"@vitest/coverage-c8": "^0.26.3",
"cz-conventional-changelog": "^3.3.0",
"discord-api-types": "^0.33.5",
"discord.js": "^13.12.0",
"discord-api-types": "^0.37.26",
"discord.js": "^14.7.1",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/README.md
Expand Up @@ -73,7 +73,7 @@ Then, you can use the following configuration options in your SapphireClient ext
// The URL that users should be redirected to after a successful authentication
redirect: '',
// The scopes that should be given to the authentication.
scopes: ['identify'],
scopes: [OAuth2Scopes.Identify],
// Transformers to transform the raw data from Discord to a different structure.
transformers: []
},
Expand Down
27 changes: 16 additions & 11 deletions packages/api/src/lib/structures/http/Auth.ts
@@ -1,13 +1,14 @@
import { Awaitable, isThenable } from '@sapphire/utilities';
import { createCipheriv, createDecipheriv, randomBytes } from 'crypto';
import {
OAuth2Scopes,
RESTGetAPICurrentUserConnectionsResult,
RESTGetAPICurrentUserGuildsResult,
RESTGetAPICurrentUserResult,
Snowflake,
RouteBases,
Routes,
RouteBases
} from 'discord-api-types/v9';
Snowflake
} from 'discord.js';
import fetch from 'node-fetch';

export class Auth {
Expand All @@ -27,7 +28,7 @@ export class Auth {
* The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.
* @since 1.0.0
*/
public scopes: readonly string[];
public scopes: readonly OAuth2Scopes[];

/**
* The redirect uri.
Expand All @@ -48,7 +49,7 @@ export class Auth {
private constructor(options: ServerOptionsAuth) {
this.id = options.id as Snowflake;
this.cookie = options.cookie ?? 'SAPPHIRE_AUTH';
this.scopes = options.scopes ?? ['identify'];
this.scopes = options.scopes ?? [OAuth2Scopes.Identify];
this.redirect = options.redirect;
this.#secret = options.secret;
this.transformers = options.transformers ?? [];
Expand Down Expand Up @@ -102,9 +103,13 @@ export class Auth {
public async fetchData(token: string): Promise<LoginData> {
// Fetch the information:
const [user, guilds, connections] = await Promise.all([
this.fetchInformation<RESTGetAPICurrentUserResult>('identify', token, `${RouteBases.api}${Routes.user()}`),
this.fetchInformation<RESTGetAPICurrentUserGuildsResult>('guilds', token, `${RouteBases.api}${Routes.userGuilds()}`),
this.fetchInformation<RESTGetAPICurrentUserConnectionsResult>('connections', token, `${RouteBases.api}${Routes.userConnections()}`)
this.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),
this.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),
this.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(
OAuth2Scopes.Connections,
token,
`${RouteBases.api}${Routes.userConnections()}`
)
]);

// Transform the information:
Expand All @@ -118,7 +123,7 @@ export class Auth {
return data;
}

private async fetchInformation<T>(scope: string, token: string, url: string): Promise<T | null | undefined> {
private async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {
if (!this.scopes.includes(scope)) return undefined;

const result = await fetch(url, {
Expand Down Expand Up @@ -193,9 +198,9 @@ export interface ServerOptionsAuth {
/**
* The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.
* @since 1.0.0
* @default ['identify']
* @default [OAuth2Scopes.Identify]
*/
scopes?: string[];
scopes?: OAuth2Scopes[];

/**
* The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/oauth/callback.ts
@@ -1,5 +1,5 @@
import type { PieceContext } from '@sapphire/pieces';
import { OAuth2Routes, RESTPostOAuth2AccessTokenResult, RESTPostOAuth2AccessTokenURLEncodedData } from 'discord-api-types/v9';
import { OAuth2Routes, RESTPostOAuth2AccessTokenResult, RESTPostOAuth2AccessTokenURLEncodedData } from 'discord.js';
import fetch from 'node-fetch';
import { stringify } from 'querystring';
import type { ApiRequest } from '../../lib/structures/api/ApiRequest';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/oauth/logout.ts
@@ -1,4 +1,4 @@
import { OAuth2Routes } from 'discord-api-types/v9';
import { OAuth2Routes } from 'discord.js';
import fetch from 'node-fetch';
import { stringify } from 'querystring';
import { promisify } from 'util';
Expand Down
4 changes: 2 additions & 2 deletions packages/editable-commands/package.json
Expand Up @@ -36,7 +36,7 @@
"check-update": "cliff-jumper --dry-run"
},
"dependencies": {
"@skyra/editable-commands": "^2.1.4",
"@skyra/editable-commands": "^3.0.0",
"tslib": "^2.4.1"
},
"repository": {
Expand Down Expand Up @@ -71,7 +71,7 @@
"access": "public"
},
"devDependencies": {
"@favware/cliff-jumper": "^1.9.0",
"@favware/cliff-jumper": "^1.10.0",
"gen-esm-wrapper": "^1.1.3",
"typedoc": "^0.23.24",
"typedoc-json-parser": "^7.1.0",
Expand Down
16 changes: 12 additions & 4 deletions packages/i18next/src/lib/functions.ts
@@ -1,7 +1,15 @@
import { container } from '@sapphire/pieces';
import { lazy, type NonNullObject } from '@sapphire/utilities';
import { APIApplicationCommandOptionChoice, Locale, type LocaleString } from 'discord-api-types/v10';
import { BaseCommandInteraction, Guild, Message, MessageComponentInteraction } from 'discord.js';
import {
APIApplicationCommandOptionChoice,
ChannelType,
CommandInteraction,
Guild,
Locale,
Message,
MessageComponentInteraction,
type LocaleString
} from 'discord.js';
import type { TFuncKey, TOptions } from 'i18next';
import type {
BuilderWithDescription,
Expand Down Expand Up @@ -29,7 +37,7 @@ import type {
*/
export function fetchLanguage(target: Target): Promise<string> {
// Handle Interactions:
if (target instanceof BaseCommandInteraction || target instanceof MessageComponentInteraction) {
if (target instanceof CommandInteraction || target instanceof MessageComponentInteraction) {
return resolveLanguage({
user: target.user,
channel: target.channel,
Expand All @@ -50,7 +58,7 @@ export function fetchLanguage(target: Target): Promise<string> {
}

// Handle DMChannel:
if (target.type === 'DM') {
if (target.type === ChannelType.DM) {
return resolveLanguage({ user: null, channel: target, guild: null });
}

Expand Down
9 changes: 4 additions & 5 deletions packages/i18next/src/lib/types.ts
@@ -1,15 +1,14 @@
import type { Awaitable } from '@sapphire/utilities';
import type { Backend } from '@skyra/i18next-backend';
import type { WatchOptions } from 'chokidar';
import type { LocalizationMap } from 'discord-api-types/v10';
import type {
BaseCommandInteraction,
CommandInteraction,
Guild,
Interaction,
LocalizationMap,
Message,
MessageComponentInteraction,
StageChannel,
StoreChannel,
User,
VoiceChannel
} from 'discord.js';
Expand Down Expand Up @@ -137,7 +136,7 @@ export interface InternationalizationOptions {
}

export type TextBasedDiscordChannel = Message['channel'];
export type DiscordChannel = TextBasedDiscordChannel | StoreChannel | StageChannel | VoiceChannel;
export type DiscordChannel = TextBasedDiscordChannel | StageChannel | VoiceChannel;

/**
* Context for {@link InternationalizationHandler.fetchLanguage} functions.
Expand Down Expand Up @@ -180,4 +179,4 @@ export interface BuilderWithDescription {

export type BuilderWithNameAndDescription = BuilderWithName & BuilderWithDescription;
export type ChannelTarget = Message | DiscordChannel;
export type Target = BaseCommandInteraction | ChannelTarget | Guild | MessageComponentInteraction;
export type Target = CommandInteraction | ChannelTarget | Guild | MessageComponentInteraction;
6 changes: 3 additions & 3 deletions packages/pattern-commands/src/listeners/PluginMessageParse.ts
@@ -1,13 +1,13 @@
import { GuildBasedChannelTypes, isDMChannel } from '@sapphire/discord.js-utilities';
import { Events, Listener } from '@sapphire/framework';
import type { PieceContext } from '@sapphire/pieces';
import { Message, Permissions } from 'discord.js';
import { Message, PermissionFlagsBits, PermissionsBitField } from 'discord.js';
import type { PatternCommandStore } from '../lib/structures/PaternCommandStore';
import { PatternCommandEvents } from '../lib/utils/PaternCommandEvents';
import type { PossiblePatternCommand } from '../lib/utils/PatternCommandInterfaces';

export class MessageParseListener extends Listener<typeof Events.PreMessageParsed> {
private readonly requiredPermissions = new Permissions(['VIEW_CHANNEL', 'SEND_MESSAGES']).freeze();
private readonly requiredPermissions = new PermissionsBitField([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages]).freeze();
public constructor(context: PieceContext) {
super(context, { event: Events.PreMessageParsed });
}
Expand Down Expand Up @@ -89,7 +89,7 @@ export class MessageParseListener extends Listener<typeof Events.PreMessageParse
private async canRunInChannel(message: Message): Promise<boolean> {
if (isDMChannel(message.channel)) return true;

const me = message.guild!.me ?? (message.client.id ? await message.guild!.members.fetch(message.client.id) : null);
const me = await message.guild?.members.fetchMe();
if (!me) return false;

const channel = message.channel as GuildBasedChannelTypes;
Expand Down
4 changes: 2 additions & 2 deletions packages/subcommands/src/lib/Subcommand.ts
Expand Up @@ -384,8 +384,8 @@ export namespace Subcommand {
export type JSON = Command.JSON;
export type Context = Command.Context;
export type RunInTypes = Command.RunInTypes;
export type ChatInputInteraction<Cached extends CacheType = CacheType> = Command.ChatInputInteraction<Cached>;
export type ContextMenuInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuInteraction<Cached>;
export type ChatInputCommandInteraction<Cached extends CacheType = CacheType> = Command.ChatInputCommandInteraction<Cached>;
export type ContextMenuCommandInteraction<Cached extends CacheType = CacheType> = Command.ContextMenuCommandInteraction<Cached>;
export type AutocompleteInteraction<Cached extends CacheType = CacheType> = Command.AutocompleteInteraction<Cached>;
export type Registry = Command.Registry;
}

0 comments on commit 7674782

Please sign in to comment.