Skip to content

Commit

Permalink
feat(deps)!: support for djs v14 (#512)
Browse files Browse the repository at this point in the history
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: 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 Jan 8, 2023
1 parent cbead4d commit e81cba2
Show file tree
Hide file tree
Showing 48 changed files with 814 additions and 816 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
@@ -0,0 +1,2 @@
CHANGELOG.md
.yarn
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -28,9 +28,9 @@
"postpack": "pinst --enable"
},
"dependencies": {
"@discordjs/builders": "^0.16.0",
"@sapphire/discord-utilities": "^2.12.0",
"@sapphire/discord.js-utilities": "^5.1.2",
"@discordjs/builders": "^1.4.0",
"@sapphire/discord-utilities": "^3.0.0",
"@sapphire/discord.js-utilities": "6.0.0",
"@sapphire/lexure": "^1.1.2",
"@sapphire/pieces": "^3.6.0",
"@sapphire/ratelimits": "^2.4.5",
Expand All @@ -41,7 +41,7 @@
"devDependencies": {
"@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",
"@favware/rollup-type-bundler": "^2.0.0",
"@sapphire/eslint-config": "^4.3.8",
Expand All @@ -53,7 +53,7 @@
"@typescript-eslint/parser": "^5.48.0",
"@vitest/coverage-c8": "^0.26.3",
"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.31.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
89 changes: 60 additions & 29 deletions src/lib/parsers/Args.ts
Expand Up @@ -73,14 +73,19 @@ 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
* const resolver = Args.make((arg) => {
* const parsed = Number(arg);
* if (Number.isNaN(parsed)) return err(new UserError('ArgumentNumberNaN', 'You must write a valid number.'));
* return ok(parsed);
* const resolver = Args.make((parameter, { argument }) => {
* const parsed = Number(parameter);
* if (Number.isNaN(parsed)) {
* return Args.error({ argument, parameter, identifier: 'ArgumentNumberNaN', message: 'You must write a valid number.' });
* }
*
* return Args.ok(parsed);
* });
*
* const a = await args.pickResult(resolver);
* if (!a.success) throw new UserError('ArgumentNumberNaN', 'You must write a valid number.');
*
Expand All @@ -92,6 +97,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,14 +136,19 @@ 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
* const resolver = Args.make((arg) => {
* const parsed = Number(arg);
* if (Number.isNaN(parsed)) return err(new UserError('ArgumentNumberNaN', 'You must write a valid number.'));
* return ok(parsed);
* const resolver = Args.make((parameter, { argument }) => {
* const parsed = Number(parameter);
* if (Number.isNaN(parsed)) {
* return Args.error({ argument, parameter, identifier: 'ArgumentNumberNaN', message: 'You must write a valid number.' });
* }
*
* return Args.ok(parsed);
* });
*
* const a = await args.pick(resolver);
*
* await message.channel.send(`The result is: ${a ** 2}!`);
Expand All @@ -148,6 +159,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,10 +178,12 @@ 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!
* const resolver = Args.make((arg) => ok(arg.split('').reverse()));
* const resolver = Args.make((parameter) => Args.ok(parameter.split('').reverse()));
*
* const a = await args.restResult(resolver);
* if (!a.success) throw new UserError('AddArgumentError', 'You must write some text.');
*
Expand All @@ -181,6 +195,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,10 +232,11 @@ 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!
* const resolver = Args.make((arg) => ok(arg.split('').reverse()));
* const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
* const a = await args.rest(resolver);
* await message.channel.send(`The reversed value is... ${a}`);
* // Sends "The reversed value is... !dlrow olleH"
Expand All @@ -230,6 +246,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,10 +265,11 @@ 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!
* const resolver = Args.make((arg) => ok(arg.split('').reverse()));
* const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
* const result = await args.repeatResult(resolver, { times: 5 });
* if (!result.success) throw new UserError('CountArgumentError', 'You must write up to 5 words.');
*
Expand All @@ -263,6 +281,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,10 +330,11 @@ 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!
* const resolver = Args.make((arg) => ok(arg.split('').reverse()));
* const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
* const result = await args.repeat(resolver, { times: 5 });
* await message.channel.send(`You have written ${result.length} word(s): ${result.join(' ')}`);
* // Sends "You have written 2 word(s): Hello World!"
Expand All @@ -324,6 +344,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 All @@ -347,9 +368,9 @@ export class Args {
* @example
* ```typescript
* // !reversedandscreamfirst hello world
* const resolver = Args.make((arg) => ok(arg.split('').reverse().join('')));
* const resolver = Args.make((arg) => Args.ok(arg.split('').reverse().join('')));
*
* const result = await args.peekResult(() => args.repeatResult(resolver));
* const result = await args.repeatResult(resolver);
* await result.inspectAsync((value) =>
* message.channel.send(`Reversed ${value.length} word(s): ${value.join(' ')}`)
* ); // Reversed 2 word(s): olleh dlrow
Expand All @@ -367,13 +388,14 @@ 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
* const resolver = Args.make((arg) => ok(arg.split('').reverse().join('')));
* const resolver = Args.make((arg) => Args.ok(arg.split('').reverse().join('')));
*
* const peekedWord = await args.peekResult(resolver);
* await peekedWord.inspectAsync((value) => message.channel.send(peekedWord.value)); // erihppas
* await peekedWord.inspectAsync((value) => message.channel.send(value)); // erihppas
*
* const firstWord = await args.pickResult('string');
* await firstWord.inspectAsync((value) => message.channel.send(value.toUpperCase())); // SAPPHIRE
Expand All @@ -386,17 +408,18 @@ 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
* const date = await args.peekResult('date');
* await date.inspectAsync((value) =>
* message.channel.send(`Your date (in UTC): ${date.value.toUTCString()}`)
* message.channel.send(`Your date (in UTC): ${value.toUTCString()}`)
* ); // Your date (in UTC): Fri, 25 Dec 2020 03:37:52 GMT
*
* const result = await args.pickResult('number', { maximum: Number.MAX_SAFE_INTEGER - 2 });
* await result.inspectAsync((value) =>
* message.channel.send(`Your number plus two: ${result.value + 2}`)
* message.channel.send(`Your number plus two: ${value + 2}`)
* ); // Your number plus two: 1608867472613
* ```
*/
Expand All @@ -421,16 +444,16 @@ export class Args {
* @example
* ```typescript
* // !bigintsumthensquarefirst 25 50 75
* const resolver = Args.make((arg) => {
* const resolver = Args.make((arg, { argument }) => {
* try {
* return ok(BigInt(arg));
* return Args.ok(BigInt(arg));
* } catch {
* return err(new UserError('InvalidBigInt', 'You must specify a valid number for a bigint.'));
* return Args.error({ parameter: arg, argument, identifier: 'InvalidBigInt', message: 'You must specify a valid number for a bigint.' })
* }
* });
*
* const peeked = await args.peek(() => args.repeatResult(resolver));
* await message.channel.send(`Sum: **${peeked.reduce((x, y) => x + y, 0)}**`); // Sum: 150
* const peeked = await args.repeatResult(resolver);
* await peeked.inspectAsync((value) => message.channel.send(`Sum: **${value.reduce((x, y) => x + y, 0n)}**`)); // Sum: 150n
*
* const first = await args.pick(resolver);
* await message.channel.send(`First bigint squared: ${first**2n}`); // First bigint squared: 625
Expand All @@ -440,15 +463,21 @@ 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
* import { SnowflakeRegex } from '@sapphire/discord.js-utilities';
* import { DiscordSnowflake } from '@sapphire/snowflake';
*
* // !createdat 730159185517477900
* const snowflakeResolver = Args.make((arg) =>
* SnowflakeRegex.test(arg) ? ok(BigInt(arg)) : err(new UserError('InvalidSnowflake', 'You must specify a valid snowflake.'));
* );
* const snowflakeResolver = Args.make<bigint>((arg, { argument }) => {
* return SnowflakeRegex.test(arg)
* ? Args.ok(BigInt(arg))
* : Args.error({ parameter: arg, argument, identifier: 'InvalidSnowflake', message: 'You must specify a valid snowflake.' });
* });
*
* const snowflake = await args.peek(snowflakeResolver);
* const timestamp = Number((snowflake >> 22n) + DiscordSnowflake.Epoch);
* const timestamp = Number((snowflake >> 22n) + DiscordSnowflake.epoch);
* const createdAt = new Date(timestamp);
*
* await message.channel.send(
Expand All @@ -463,6 +492,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 +524,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 +739,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

0 comments on commit e81cba2

Please sign in to comment.