Skip to content

Commit

Permalink
feat(deps): support for discord.js v14
Browse files Browse the repository at this point in the history
fix(normalizeInputs): should not default default_permission anymore

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jeroen Claassens <support@favware.tech>
Co-authored-by: Hezekiah Hendry <hezekiah.hendry@gmail.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: Ben <34194692+BenSegal855@users.noreply.github.com>
Co-authored-by: Urcute <75350256+itsUrcute@users.noreply.github.com>
Co-authored-by: Lioness100 <jchickmm2@gmail.com>
  • Loading branch information
7 people committed Dec 30, 2022
1 parent e358a5b commit c15cf8a
Show file tree
Hide file tree
Showing 47 changed files with 625 additions and 594 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
@@ -0,0 +1,2 @@
CHANGELOG.md
.yarn
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -28,9 +28,9 @@
"postpack": "pinst --enable"
},
"dependencies": {
"@discordjs/builders": "^0.16.0",
"@discordjs/builders": "^1.4.0",
"@sapphire/discord-utilities": "^2.12.0",
"@sapphire/discord.js-utilities": "^5.1.2",
"@sapphire/discord.js-utilities": "pr-434",
"@sapphire/lexure": "^1.1.2",
"@sapphire/pieces": "^3.6.0",
"@sapphire/ratelimits": "^2.4.5",
Expand All @@ -53,7 +53,7 @@
"@typescript-eslint/parser": "^5.47.1",
"@vitest/coverage-c8": "^0.26.2",
"cz-conventional-changelog": "^3.3.0",
"discord.js": "^13.12.0",
"discord.js": "^14.7.1",
"esbuild-plugin-file-path-extensions": "^1.0.0",
"esbuild-plugin-version-injector": "^1.0.2",
"eslint": "^8.30.0",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/SapphireClient.ts
Expand Up @@ -40,14 +40,14 @@ export interface SapphireClientOptions {
baseUserDirectory?: URL | string | null;

/**
* Whether commands can be case insensitive
* Whether commands can be case-insensitive
* @since 1.0.0
* @default false
*/
caseInsensitiveCommands?: boolean | null;

/**
* Whether prefixes can be case insensitive
* Whether prefixes can be case-insensitive
* @since 1.0.0
* @default false
*/
Expand Down Expand Up @@ -100,7 +100,7 @@ export interface SapphireClientOptions {
logger?: ClientLoggerOptions;

/**
* Whether or not trace logging should be enabled.
* Whether trace logging should be enabled.
* @since 2.0.0
* @default container.logger.has(LogLevel.Trace)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors/Identifiers.ts
@@ -1,4 +1,4 @@
export const enum Identifiers {
export enum Identifiers {
ArgsMissing = 'argsMissing',
ArgsUnavailable = 'argsUnavailable',

Expand Down
3 changes: 1 addition & 2 deletions src/lib/errors/UserError.ts
Expand Up @@ -15,8 +15,7 @@ export class UserError extends Error {

/**
* Constructs an UserError.
* @param type The identifier, useful to localize emitted errors.
* @param message The error message.
* @param options The UserError options
*/
public constructor(options: UserError.Options) {
super(options.message);
Expand Down
21 changes: 19 additions & 2 deletions src/lib/parsers/Args.ts
Expand Up @@ -73,6 +73,7 @@ export class Args {
/**
* Retrieves the next parameter and parses it. Advances index on success.
* @param type The type of the argument.
* @param options The pickResult options.
* @example
* ```typescript
* // !square 5
Expand All @@ -92,6 +93,7 @@ export class Args {
/**
* Retrieves the next parameter and parses it. Advances index on success.
* @param type The type of the argument.
* @param options The pickResult options.
* @example
* ```typescript
* // !add 1 2
Expand Down Expand Up @@ -130,6 +132,7 @@ export class Args {
/**
* Similar to {@link Args.pickResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The pick options.
* @example
* ```typescript
* // !square 5
Expand All @@ -148,6 +151,7 @@ export class Args {
/**
* Similar to {@link Args.pickResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The pick options.
* @example
* ```typescript
* // !add 1 2
Expand All @@ -166,6 +170,7 @@ export class Args {
/**
* Retrieves all the following arguments.
* @param type The type of the argument.
* @param options The restResult options.
* @example
* ```typescript
* // !reverse Hello world!
Expand All @@ -181,6 +186,7 @@ export class Args {
/**
* Retrieves all the following arguments.
* @param type The type of the argument.
* @param options The restResult options.
* @example
* ```typescript
* // !add 2 Hello World!
Expand Down Expand Up @@ -217,6 +223,7 @@ export class Args {
/**
* Similar to {@link Args.restResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The rest options.
* @example
* ```typescript
* // !reverse Hello world!
Expand All @@ -230,6 +237,7 @@ export class Args {
/**
* Similar to {@link Args.restResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The rest options.
* @example
* ```typescript
* // !add 2 Hello World!
Expand All @@ -248,6 +256,7 @@ export class Args {
/**
* Retrieves all the following arguments.
* @param type The type of the argument.
* @param options The repeatResult options.
* @example
* ```typescript
* // !add 2 Hello World!
Expand All @@ -263,6 +272,7 @@ export class Args {
/**
* Retrieves all the following arguments.
* @param type The type of the argument.
* @param options The repeatResult options.
* @example
* ```typescript
* // !reverse-each 2 Hello World!
Expand Down Expand Up @@ -311,6 +321,7 @@ export class Args {
/**
* Similar to {@link Args.repeatResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The repeat options.
* @example
* ```typescript
* // !reverse-each 2 Hello World!
Expand All @@ -324,6 +335,7 @@ export class Args {
/**
* Similar to {@link Args.repeatResult} but returns the value on success, throwing otherwise.
* @param type The type of the argument.
* @param options The repeat options.
* @example
* ```typescript
* // !add 2 Hello World!
Expand Down Expand Up @@ -367,6 +379,7 @@ export class Args {
* or {@link Args.restResult}; otherwise, passing the custom argument or the argument type with options
* will use {@link Args.pickResult} and only peek a single argument.
* @param type The function, custom argument, or argument name.
* @param options The peekResult options.
* @example
* ```typescript
* // !reverseandscreamfirst sapphire community
Expand All @@ -386,6 +399,7 @@ export class Args {
* or {@link Args.restResult}; otherwise, passing the custom argument or the argument type with options
* will use {@link Args.pickResult} and only peek a single argument.
* @param type The function, custom argument, or argument name.
* @param options The peekResult options.
* @example
* ```typescript
* // !datethenaddtwo 1608867472611
Expand Down Expand Up @@ -440,6 +454,7 @@ export class Args {
/**
* Similar to {@link Args.peekResult} but returns the value on success, throwing otherwise.
* @param type The function, custom argument, or argument name.
* @param options The peek options.
* @example
* ```typescript
* // !createdat 730159185517477900
Expand All @@ -463,6 +478,7 @@ export class Args {
/**
* Similar to {@link Args.peekResult} but returns the value on success, throwing otherwise.
* @param type The function, custom argument, or argument name.
* @param options The peek options.
* @example
* ```typescript
* // !messagelink https://discord.com/channels/737141877803057244/737142209639350343/791843123898089483
Expand Down Expand Up @@ -494,7 +510,7 @@ export class Args {
public nextMaybe(): Option<string>;
/**
* Retrieves the value of the next unused ordered token, but only if it could be transformed.
* That token will now be consider used if the transformation succeeds.
* That token will now be used if the transformation succeeds.
* @typeparam T Output type of the {@link ArgsNextCallback callback}.
* @param cb Gives an option of either the resulting value, or nothing if failed.
* @example
Expand Down Expand Up @@ -709,8 +725,9 @@ export class Args {
}

/**
* Converts a callback into an usable argument.
* Converts a callback into a usable argument.
* @param cb The callback to convert into an {@link IArgument}.
* @param name The name of the argument.
*/
public static make<T>(cb: IArgument<T>['run'], name = ''): IArgument<T> {
return { run: cb, name };
Expand Down
4 changes: 2 additions & 2 deletions src/lib/resolvers/channel.ts
@@ -1,12 +1,12 @@
import { ChannelMentionRegex, type ChannelTypes } from '@sapphire/discord.js-utilities';
import { container } from '@sapphire/pieces';
import { Result } from '@sapphire/result';
import type { BaseCommandInteraction, Message, Snowflake } from 'discord.js';
import type { CommandInteraction, Message, Snowflake } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';

export function resolveChannel(
parameter: string,
messageOrInteraction: Message | BaseCommandInteraction
messageOrInteraction: Message | CommandInteraction
): Result<ChannelTypes, Identifiers.ArgumentChannelError> {
const channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake;
const channel = (messageOrInteraction.guild ? messageOrInteraction.guild.channels : container.client.channels).cache.get(channelId);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/resolvers/dmChannel.ts
@@ -1,12 +1,12 @@
import { isDMChannel } from '@sapphire/discord.js-utilities';
import { Result } from '@sapphire/result';
import type { BaseCommandInteraction, DMChannel, Message } from 'discord.js';
import type { CommandInteraction, DMChannel, Message } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { resolveChannel } from './channel';

export function resolveDMChannel(
parameter: string,
messageOrInteraction: Message | BaseCommandInteraction
messageOrInteraction: Message | CommandInteraction
): Result<DMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> {
const result = resolveChannel(parameter, messageOrInteraction);
return result.mapInto((value) => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/resolvers/emoji.ts
@@ -1,6 +1,6 @@
import { EmojiRegex, TwemojiRegex } from '@sapphire/discord-utilities';
import { Result } from '@sapphire/result';
import { Util } from 'discord.js';
import { parseEmoji } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';

export function resolveEmoji(parameter: string): Result<EmojiObject, Identifiers> {
Expand All @@ -16,7 +16,7 @@ export function resolveEmoji(parameter: string): Result<EmojiObject, Identifiers
const emojiId = EmojiRegex.test(parameter);

if (emojiId) {
const resolved = Util.parseEmoji(parameter) as EmojiObject | null;
const resolved = parseEmoji(parameter) as EmojiObject | null;

if (resolved) {
return Result.ok(resolved);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/resolvers/message.ts
Expand Up @@ -12,7 +12,7 @@ import {
import { container } from '@sapphire/pieces';
import { Result } from '@sapphire/result';
import type { Awaitable } from '@sapphire/utilities';
import { Permissions, type Message, type Snowflake, type User } from 'discord.js';
import { type Message, type Snowflake, type User, PermissionFlagsBits } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ async function getMessageFromChannel(channelId: Snowflake, messageId: Snowflake,
return null;
}

if (!channel.permissionsFor(originalAuthor)?.has(Permissions.FLAGS.VIEW_CHANNEL)) {
if (!channel.permissionsFor(originalAuthor)?.has(PermissionFlagsBits.ViewChannel)) {
return null;
}

Expand Down

0 comments on commit c15cf8a

Please sign in to comment.