diff --git a/package.json b/package.json index 4fa93d318..735eeadfa 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@sapphire/discord.js-utilities": "^4.6.0", "@sapphire/pieces": "^3.2.0", "@sapphire/ratelimits": "^2.3.0", + "@sapphire/result": "^1.0.0", "@sapphire/stopwatch": "^1.3.0", "@sapphire/utilities": "^3.3.0", "lexure": "^0.17.0", diff --git a/src/index.ts b/src/index.ts index 622108efe..ecc6e6e73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,14 +43,13 @@ export { StoreRegistry, StoreRegistryEntries } from '@sapphire/pieces'; +export * from '@sapphire/result'; export type { Awaitable } from '@sapphire/utilities'; export * from './lib/errors/ArgumentError'; export * from './lib/errors/Identifiers'; export * from './lib/errors/PreconditionError'; export * from './lib/errors/UserError'; export * from './lib/parsers/Args'; -export * from './lib/parsers/Maybe'; -export * from './lib/parsers/Result'; export * from './lib/plugins/Plugin'; export * from './lib/plugins/PluginManager'; export * from './lib/plugins/symbols'; diff --git a/src/lib/parsers/Args.ts b/src/lib/parsers/Args.ts index 9b44d85de..f323d2eae 100644 --- a/src/lib/parsers/Args.ts +++ b/src/lib/parsers/Args.ts @@ -1,5 +1,6 @@ import type { ChannelTypes, GuildBasedChannelTypes } from '@sapphire/discord.js-utilities'; import { container } from '@sapphire/pieces'; +import { err, isErr, isOk, isSome, maybe, ok, type Err, type Maybe, type Ok, type Result } from '@sapphire/result'; import type { CategoryChannel, DMChannel, @@ -21,8 +22,6 @@ import { UserError } from '../errors/UserError'; import type { EmojiObject } from '../resolvers'; import type { Argument, IArgument } from '../structures/Argument'; import type { MessageCommand } from '../structures/Command'; -import { isSome, maybe, Maybe } from './Maybe'; -import { Err, err, isErr, isOk, ok, Ok, Result } from './Result'; /** * The argument parser to be used in {@link Command}. @@ -126,7 +125,9 @@ export class Args { ); if (result === null) return this.missingArguments(); if (isOk(result)) return result as Ok; - return result; + + // We need to typecast here because TS doesn't resolve that the type from @sapphire/result is identical to that of Lexure + return result as Result; } /** @@ -299,7 +300,11 @@ export class Args { ); if (result === null) break; if (isErr(result)) { - if (output.length === 0) return result; + if (output.length === 0) { + // We need to typecast here because TS doesn't resolve that the type from @sapphire/result is identical to that of Lexure + return result as Result; + } + break; } diff --git a/src/lib/parsers/Maybe.ts b/src/lib/parsers/Maybe.ts deleted file mode 100644 index ee442edc3..000000000 --- a/src/lib/parsers/Maybe.ts +++ /dev/null @@ -1,98 +0,0 @@ -import type { option } from 'lexure'; - -/** - * A type used to express a value that may or may not exist. - * @typeparam T The value's type. - */ -export type Maybe = Some | None; - -/** - * A value that exists. - * @typeparam T The value's type. - */ -export type Some = option.Some; - -/** - * An empty value. - */ -export type None = option.None; - -/** - * Returns the maybe itself. - * @param value The value to convert. - */ -export function maybe>(value: V): V; -/** - * Creates a {@link None} from an existing {@link None} or a `null`. - * @param value The value to convert. - */ -export function maybe(value: null | None): None; -/** - * Creates a {@link Some} from a non-null value or an existing {@link Some}, or a {@link None} otherwise. - * @param value The value to convert. - */ -export function maybe(value: T | Maybe | null): Maybe; -/** - * Creates a {@link Some} from a non-null value or an existing {@link Some}. - * @param value The value to convert. - */ -export function maybe(value: T | Some): Some; -export function maybe(value: T | Maybe | null): Maybe { - return isMaybe(value) ? value : value === null ? none() : some(value); -} - -/** - * Creates a None with no value. - * @return An existing Maybe. - */ -export function some(): Some; -/** - * Creates a None with a value. - * @typeparam T The value's type. - * @param x Value to use. - * @return An existing Maybe. - */ -export function some(x: T): Some; -export function some(x?: T): Some { - return { exists: true, value: x }; -} - -/** - * Creates a None value. - * @return A non-existing Maybe. - */ -export function none(): None { - return { exists: false }; -} - -/** - * Determines whether or not a Maybe is a Some. - * @typeparam T The value's type. - */ -export function isSome(x: Maybe): x is Some { - return x.exists; -} - -/** - * Determines whether or not a Maybe is a None. - * @typeparam T The value's type. - */ -export function isNone(x: Maybe): x is None { - return !x.exists; -} - -/** - * Type-safe helper to preserve the type parameter's type. - * @param x The value to check. - */ -export function isMaybe(x: Maybe): true; -/** - * Determines whether or not an arbitrary value is a Maybe. - * @param x The value to check. - */ -export function isMaybe(x: unknown): x is Maybe; -export function isMaybe(x: Maybe | unknown): x is Maybe { - return typeof x === 'object' && x !== null && typeof Reflect.get(x, 'exists') === 'boolean'; -} - -export type UnwrapMaybeValue> = T extends Some ? V : never; diff --git a/src/lib/parsers/Result.ts b/src/lib/parsers/Result.ts deleted file mode 100644 index c728d94b1..000000000 --- a/src/lib/parsers/Result.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Awaitable, isFunction } from '@sapphire/utilities'; -import type * as Lexure from 'lexure'; - -/** - * A type used to express computations that can fail. - * @typeparam T The result's type. - * @typeparam E The error's type. - */ -export type Result = Ok | Err; - -/** - * The computation is successful. - * @typeparam T Type of results. - */ -export type Ok = Lexure.Ok; - -/** - * The computation failed. - * @typeparam E Type of errors. - */ -export type Err = Lexure.Err; - -/** - * Creates an Ok with no value. - * @return A successful Result. - */ -export function ok(): Ok; -/** - * Creates an Ok. - * @typeparam T The result's type. - * @param x Value to use. - * @return A successful Result. - */ -export function ok(x: T): Ok; -export function ok(x?: T): Ok { - return { success: true, value: x }; -} - -/** - * Creates an Err with no error. - * @return An erroneous Result. - */ -export function err(): Err; -/** - * Creates an Err. - * @typeparam E The error's type. - * @param x Value to use. - * @return An erroneous Result. - */ -export function err(x: E): Err; -export function err(x?: E): Err { - return { success: false, error: x }; -} - -/** - * Determines whether or not a result is an Ok. - * @typeparam T The result's type. - * @typeparam E The error's type. - */ -export function isOk(x: Result): x is Ok { - return x.success; -} - -/** - * Determines whether or not a result is an Err. - * @typeparam T The result's type. - * @typeparam E The error's type. - */ -export function isErr(x: Result): x is Err { - return !x.success; -} - -/** - * Creates a {@link Result} out of a callback. - * @typeparam T The result's type. - * @typeparam E The error's type. - */ -export function from(cb: (...args: unknown[]) => T): Result { - try { - return ok(cb()); - } catch (error) { - return err(error as E); - } -} - -/** - * Creates a {@link Result} out of a promise or async callback. - * @typeparam T The result's type. - * @typeparam E The error's type. - */ -export async function fromAsync(promiseOrCb: Awaitable | ((...args: unknown[]) => Awaitable)): Promise> { - try { - return ok(await (isFunction(promiseOrCb) ? promiseOrCb() : promiseOrCb)); - } catch (error) { - return err(error as E); - } -} diff --git a/src/lib/resolvers/boolean.ts b/src/lib/resolvers/boolean.ts index 69b78a717..91d6549d0 100644 --- a/src/lib/resolvers/boolean.ts +++ b/src/lib/resolvers/boolean.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; const baseTruths = ['1', 'true', '+', 't', 'yes', 'y'] as const; const baseFalses = ['0', 'false', '-', 'f', 'no', 'n'] as const; diff --git a/src/lib/resolvers/channel.ts b/src/lib/resolvers/channel.ts index 9a0944df9..cd2924f12 100644 --- a/src/lib/resolvers/channel.ts +++ b/src/lib/resolvers/channel.ts @@ -1,8 +1,8 @@ import { ChannelMentionRegex, ChannelTypes } from '@sapphire/discord.js-utilities'; import { container } from '@sapphire/pieces'; +import { err, ok, Result } from '@sapphire/result'; import type { Message, Snowflake } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveChannel(parameter: string, message: Message): Result { const channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake; diff --git a/src/lib/resolvers/date.ts b/src/lib/resolvers/date.ts index 8618c3302..80e92a451 100644 --- a/src/lib/resolvers/date.ts +++ b/src/lib/resolvers/date.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveDate( parameter: string, diff --git a/src/lib/resolvers/dmChannel.ts b/src/lib/resolvers/dmChannel.ts index e59bbf6ac..f702247f4 100644 --- a/src/lib/resolvers/dmChannel.ts +++ b/src/lib/resolvers/dmChannel.ts @@ -1,7 +1,7 @@ import { isDMChannel } from '@sapphire/discord.js-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { DMChannel, Message } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; import { resolveChannel } from './channel'; export function resolveDMChannel( diff --git a/src/lib/resolvers/emoji.ts b/src/lib/resolvers/emoji.ts index bd64c05c5..65a277fc9 100644 --- a/src/lib/resolvers/emoji.ts +++ b/src/lib/resolvers/emoji.ts @@ -1,7 +1,7 @@ import { EmojiRegex, TwemojiRegex } from '@sapphire/discord-utilities'; +import { Err, err, Ok, ok } from '@sapphire/result'; import { Util } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { Err, err, Ok, ok } from '../parsers/Result'; export function resolveEmoji(parameter: string): Ok | Err { const twemoji = TwemojiRegex.exec(parameter)?.[0] ?? null; diff --git a/src/lib/resolvers/enum.ts b/src/lib/resolvers/enum.ts index 4b40286d4..6b60f9db9 100644 --- a/src/lib/resolvers/enum.ts +++ b/src/lib/resolvers/enum.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveEnum( parameter: string, diff --git a/src/lib/resolvers/float.ts b/src/lib/resolvers/float.ts index 5e2ab7de2..1099b3135 100644 --- a/src/lib/resolvers/float.ts +++ b/src/lib/resolvers/float.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveFloat( parameter: string, diff --git a/src/lib/resolvers/guildCategoryChannel.ts b/src/lib/resolvers/guildCategoryChannel.ts index cab5d498a..9600769d3 100644 --- a/src/lib/resolvers/guildCategoryChannel.ts +++ b/src/lib/resolvers/guildCategoryChannel.ts @@ -1,7 +1,7 @@ import { isCategoryChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { CategoryChannel, Guild } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildCategoryChannel( diff --git a/src/lib/resolvers/guildChannel.ts b/src/lib/resolvers/guildChannel.ts index ac0d1f7d7..bc34e485e 100644 --- a/src/lib/resolvers/guildChannel.ts +++ b/src/lib/resolvers/guildChannel.ts @@ -1,8 +1,8 @@ import { ChannelMentionRegex, SnowflakeRegex } from '@sapphire/discord-utilities'; import type { GuildBasedChannelTypes } from '@sapphire/discord.js-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { Guild, Snowflake } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveGuildChannel(parameter: string, guild: Guild): Result { const channel = resolveById(parameter, guild) ?? resolveByQuery(parameter, guild); diff --git a/src/lib/resolvers/guildNewsChannel.ts b/src/lib/resolvers/guildNewsChannel.ts index 389211fe9..06269614e 100644 --- a/src/lib/resolvers/guildNewsChannel.ts +++ b/src/lib/resolvers/guildNewsChannel.ts @@ -1,7 +1,7 @@ import { isNewsChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, NewsChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildNewsChannel( diff --git a/src/lib/resolvers/guildNewsThreadChannel.ts b/src/lib/resolvers/guildNewsThreadChannel.ts index f20c9ecfe..30905f45f 100644 --- a/src/lib/resolvers/guildNewsThreadChannel.ts +++ b/src/lib/resolvers/guildNewsThreadChannel.ts @@ -1,7 +1,7 @@ import { isNewsThreadChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, ThreadChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildNewsThreadChannel( diff --git a/src/lib/resolvers/guildPrivateThreadChannel.ts b/src/lib/resolvers/guildPrivateThreadChannel.ts index 96b5e7c39..97831efd0 100644 --- a/src/lib/resolvers/guildPrivateThreadChannel.ts +++ b/src/lib/resolvers/guildPrivateThreadChannel.ts @@ -1,7 +1,7 @@ import { isPrivateThreadChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, ThreadChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildPrivateThreadChannel( diff --git a/src/lib/resolvers/guildPublicThreadChannel.ts b/src/lib/resolvers/guildPublicThreadChannel.ts index 858dd256a..292751d06 100644 --- a/src/lib/resolvers/guildPublicThreadChannel.ts +++ b/src/lib/resolvers/guildPublicThreadChannel.ts @@ -1,7 +1,7 @@ import { isPublicThreadChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, ThreadChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildPublicThreadChannel( diff --git a/src/lib/resolvers/guildStageVoiceChannel.ts b/src/lib/resolvers/guildStageVoiceChannel.ts index d64234469..c620882c0 100644 --- a/src/lib/resolvers/guildStageVoiceChannel.ts +++ b/src/lib/resolvers/guildStageVoiceChannel.ts @@ -1,7 +1,7 @@ import { isStageChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, StageChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildStageVoiceChannel( diff --git a/src/lib/resolvers/guildTextChannel.ts b/src/lib/resolvers/guildTextChannel.ts index 2953f0000..50743b16d 100644 --- a/src/lib/resolvers/guildTextChannel.ts +++ b/src/lib/resolvers/guildTextChannel.ts @@ -1,7 +1,7 @@ import { isTextChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, TextChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildTextChannel( diff --git a/src/lib/resolvers/guildThreadChannel.ts b/src/lib/resolvers/guildThreadChannel.ts index a77fdf5a5..da1f7168c 100644 --- a/src/lib/resolvers/guildThreadChannel.ts +++ b/src/lib/resolvers/guildThreadChannel.ts @@ -1,7 +1,7 @@ import { isThreadChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, ThreadChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildThreadChannel( diff --git a/src/lib/resolvers/guildVoiceChannel.ts b/src/lib/resolvers/guildVoiceChannel.ts index 2f7e5fb35..42821bb22 100644 --- a/src/lib/resolvers/guildVoiceChannel.ts +++ b/src/lib/resolvers/guildVoiceChannel.ts @@ -1,7 +1,7 @@ import { isVoiceChannel } from '@sapphire/discord.js-utilities'; +import type { Result } from '@sapphire/result'; import type { Guild, VoiceChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import type { Result } from '../parsers/Result'; import { resolveGuildChannelPredicate } from '../utils/resolvers/resolveGuildChannelPredicate'; export function resolveGuildVoiceChannel( diff --git a/src/lib/resolvers/hyperlink.ts b/src/lib/resolvers/hyperlink.ts index cec8946ea..d5b16ab7b 100644 --- a/src/lib/resolvers/hyperlink.ts +++ b/src/lib/resolvers/hyperlink.ts @@ -1,6 +1,6 @@ +import { err, from, isOk, Result } from '@sapphire/result'; import { URL } from 'url'; import { Identifiers } from '../errors/Identifiers'; -import { err, from, isOk, Result } from '../parsers/Result'; export function resolveHyperlink(parameter: string): Result { const result = from(() => new URL(parameter)); diff --git a/src/lib/resolvers/index.ts b/src/lib/resolvers/index.ts index 6e2e15bd9..83fe70df8 100644 --- a/src/lib/resolvers/index.ts +++ b/src/lib/resolvers/index.ts @@ -3,6 +3,7 @@ export * from './channel'; export * from './date'; export * from './dmChannel'; export * from './emoji'; +export * from './enum'; export * from './float'; export * from './guildCategoryChannel'; export * from './guildChannel'; @@ -23,4 +24,3 @@ export * from './partialDMChannel'; export * from './role'; export * from './string'; export * from './user'; -export * from './enum'; diff --git a/src/lib/resolvers/integer.ts b/src/lib/resolvers/integer.ts index 07970f785..949b92409 100644 --- a/src/lib/resolvers/integer.ts +++ b/src/lib/resolvers/integer.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveInteger( parameter: string, diff --git a/src/lib/resolvers/member.ts b/src/lib/resolvers/member.ts index 28138e42b..f052c5cdf 100644 --- a/src/lib/resolvers/member.ts +++ b/src/lib/resolvers/member.ts @@ -1,7 +1,7 @@ import { SnowflakeRegex, UserOrMemberMentionRegex } from '@sapphire/discord-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { Guild, GuildMember, Snowflake } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export async function resolveMember(parameter: string, guild: Guild): Promise> { const member = (await resolveById(parameter, guild)) ?? (await resolveByQuery(parameter, guild)); diff --git a/src/lib/resolvers/message.ts b/src/lib/resolvers/message.ts index d08fd3661..fc132e8b4 100644 --- a/src/lib/resolvers/message.ts +++ b/src/lib/resolvers/message.ts @@ -1,10 +1,10 @@ import { ChannelMessageRegex, MessageLinkRegex, SnowflakeRegex } from '@sapphire/discord-utilities'; import { GuildBasedChannelTypes, isNewsChannel, isTextChannel, TextBasedChannelTypes } from '@sapphire/discord.js-utilities'; import { container } from '@sapphire/pieces'; +import { err, ok, Result } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import { Message, Permissions, Snowflake, User } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; interface MessageResolverOptions { channel?: TextBasedChannelTypes; diff --git a/src/lib/resolvers/number.ts b/src/lib/resolvers/number.ts index 4f2db0b6a..51f52ab83 100644 --- a/src/lib/resolvers/number.ts +++ b/src/lib/resolvers/number.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveNumber( parameter: string, diff --git a/src/lib/resolvers/partialDMChannel.ts b/src/lib/resolvers/partialDMChannel.ts index 46e5deddc..83e377ee9 100644 --- a/src/lib/resolvers/partialDMChannel.ts +++ b/src/lib/resolvers/partialDMChannel.ts @@ -1,7 +1,7 @@ import { isDMChannel } from '@sapphire/discord.js-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { DMChannel, Message, PartialDMChannel } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; import { resolveChannel } from './channel'; export function resolvePartialDMChannel( diff --git a/src/lib/resolvers/role.ts b/src/lib/resolvers/role.ts index 8ca46e56a..116188c7e 100644 --- a/src/lib/resolvers/role.ts +++ b/src/lib/resolvers/role.ts @@ -1,7 +1,7 @@ import { RoleMentionRegex, SnowflakeRegex } from '@sapphire/discord-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { Guild, Role, Snowflake } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export async function resolveRole(parameter: string, guild: Guild): Promise> { const role = (await resolveById(parameter, guild)) ?? resolveByQuery(parameter, guild); diff --git a/src/lib/resolvers/string.ts b/src/lib/resolvers/string.ts index e7058c210..5f6ff982e 100644 --- a/src/lib/resolvers/string.ts +++ b/src/lib/resolvers/string.ts @@ -1,5 +1,5 @@ +import { err, ok, Result } from '@sapphire/result'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export function resolveString( parameter: string, diff --git a/src/lib/resolvers/user.ts b/src/lib/resolvers/user.ts index df139da2f..8fab85703 100644 --- a/src/lib/resolvers/user.ts +++ b/src/lib/resolvers/user.ts @@ -1,8 +1,8 @@ import { SnowflakeRegex, UserOrMemberMentionRegex } from '@sapphire/discord-utilities'; import { container } from '@sapphire/pieces'; +import { err, ok, Result } from '@sapphire/result'; import type { Snowflake, User } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { err, ok, Result } from '../parsers/Result'; export async function resolveUser(parameter: string): Promise> { const userId = UserOrMemberMentionRegex.exec(parameter) ?? SnowflakeRegex.exec(parameter); diff --git a/src/lib/structures/Argument.ts b/src/lib/structures/Argument.ts index 293ad30f7..99f00e3d6 100644 --- a/src/lib/structures/Argument.ts +++ b/src/lib/structures/Argument.ts @@ -1,10 +1,10 @@ import { AliasPiece } from '@sapphire/pieces'; +import type { Result } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import type { Message } from 'discord.js'; import type { ArgumentError } from '../errors/ArgumentError'; import type { UserError } from '../errors/UserError'; import { Args } from '../parsers/Args'; -import type { Result } from '../parsers/Result'; import type { MessageCommand } from './Command'; /** diff --git a/src/lib/structures/ExtendedArgument.ts b/src/lib/structures/ExtendedArgument.ts index c637f89cc..c16a0a7bd 100644 --- a/src/lib/structures/ExtendedArgument.ts +++ b/src/lib/structures/ExtendedArgument.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; +import { isOk } from '@sapphire/result'; import type { ArgType } from '../parsers/Args'; -import { isOk } from '../parsers/Result'; import { Argument, IArgument } from './Argument'; /** diff --git a/src/lib/structures/InteractionHandler.ts b/src/lib/structures/InteractionHandler.ts index 477d437f4..6c1f8e3a9 100644 --- a/src/lib/structures/InteractionHandler.ts +++ b/src/lib/structures/InteractionHandler.ts @@ -1,7 +1,7 @@ import { Piece, PieceContext, PieceJSON, PieceOptions } from '@sapphire/pieces'; +import { Maybe, none, None, some, UnwrapMaybeValue } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import type { Interaction } from 'discord.js'; -import { some, Maybe, none, None, UnwrapMaybeValue } from '../parsers/Maybe'; export abstract class InteractionHandler extends Piece { /** diff --git a/src/lib/structures/InteractionHandlerStore.ts b/src/lib/structures/InteractionHandlerStore.ts index bc5777573..dacf3ff27 100644 --- a/src/lib/structures/InteractionHandlerStore.ts +++ b/src/lib/structures/InteractionHandlerStore.ts @@ -1,7 +1,6 @@ import { Store } from '@sapphire/pieces'; +import { err, fromAsync, isErr, isSome, Result } from '@sapphire/result'; import type { Interaction } from 'discord.js'; -import { isSome } from '../parsers/Maybe'; -import { err, fromAsync, isErr, Result } from '../parsers/Result'; import { Events } from '../types/Events'; import { InteractionHandler, InteractionHandlerTypes } from './InteractionHandler'; diff --git a/src/lib/structures/Listener.ts b/src/lib/structures/Listener.ts index f337af99f..68065635f 100644 --- a/src/lib/structures/Listener.ts +++ b/src/lib/structures/Listener.ts @@ -1,7 +1,7 @@ import { Piece } from '@sapphire/pieces'; +import { fromAsync, isErr } from '@sapphire/result'; import type { Client, ClientEvents } from 'discord.js'; import type { EventEmitter } from 'events'; -import { fromAsync, isErr } from '../parsers/Result'; import { Events } from '../types/Events'; /** diff --git a/src/lib/structures/Precondition.ts b/src/lib/structures/Precondition.ts index 3851642b6..73d89a766 100644 --- a/src/lib/structures/Precondition.ts +++ b/src/lib/structures/Precondition.ts @@ -1,10 +1,10 @@ import { Piece } from '@sapphire/pieces'; +import { err, ok, Result } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import type { BaseCommandInteraction, CommandInteraction, ContextMenuInteraction, Message, Permissions, TextBasedChannel } from 'discord.js'; import type { CooldownPreconditionContext } from '../../preconditions/Cooldown'; import { PreconditionError } from '../errors/PreconditionError'; import type { UserError } from '../errors/UserError'; -import { err, ok, Result } from '../parsers/Result'; import type { ChatInputCommand, ContextMenuCommand, MessageCommand } from './Command'; export type PreconditionResult = Awaitable>; diff --git a/src/lib/structures/PreconditionStore.ts b/src/lib/structures/PreconditionStore.ts index 686b1a507..7b119665a 100644 --- a/src/lib/structures/PreconditionStore.ts +++ b/src/lib/structures/PreconditionStore.ts @@ -1,7 +1,7 @@ import { Store } from '@sapphire/pieces'; +import { ok } from '@sapphire/result'; import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; import { Identifiers } from '../errors/Identifiers'; -import { ok } from '../parsers/Result'; import type { ChatInputCommand, ContextMenuCommand, MessageCommand } from './Command'; import { AsyncPreconditionResult, Precondition, PreconditionContext } from './Precondition'; diff --git a/src/lib/utils/application-commands/ApplicationCommandRegistry.ts b/src/lib/utils/application-commands/ApplicationCommandRegistry.ts index 9bba358ad..1694afb42 100644 --- a/src/lib/utils/application-commands/ApplicationCommandRegistry.ts +++ b/src/lib/utils/application-commands/ApplicationCommandRegistry.ts @@ -1,8 +1,8 @@ import type { ContextMenuCommandBuilder, SlashCommandBuilder, - SlashCommandSubcommandsOnlyBuilder, - SlashCommandOptionsOnlyBuilder + SlashCommandOptionsOnlyBuilder, + SlashCommandSubcommandsOnlyBuilder } from '@discordjs/builders'; import { container } from '@sapphire/pieces'; import { diff --git a/src/lib/utils/application-commands/normalizeInputs.ts b/src/lib/utils/application-commands/normalizeInputs.ts index 3c66b916b..acaff4cfd 100644 --- a/src/lib/utils/application-commands/normalizeInputs.ts +++ b/src/lib/utils/application-commands/normalizeInputs.ts @@ -1,13 +1,13 @@ import { ContextMenuCommandBuilder, SlashCommandBuilder, - SlashCommandSubcommandsOnlyBuilder, - SlashCommandOptionsOnlyBuilder + SlashCommandOptionsOnlyBuilder, + SlashCommandSubcommandsOnlyBuilder } from '@discordjs/builders'; import { isFunction } from '@sapphire/utilities'; import { - ApplicationCommandType, APIApplicationCommandOption, + ApplicationCommandType, RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody diff --git a/src/lib/utils/preconditions/IPreconditionContainer.ts b/src/lib/utils/preconditions/IPreconditionContainer.ts index 84d1c2f48..283a308cf 100644 --- a/src/lib/utils/preconditions/IPreconditionContainer.ts +++ b/src/lib/utils/preconditions/IPreconditionContainer.ts @@ -1,7 +1,7 @@ +import type { Result } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; import type { UserError } from '../../errors/UserError'; -import type { Result } from '../../parsers/Result'; import type { Command } from '../../structures/Command'; import type { PreconditionContext } from '../../structures/Precondition'; diff --git a/src/lib/utils/preconditions/conditions/PreconditionConditionAnd.ts b/src/lib/utils/preconditions/conditions/PreconditionConditionAnd.ts index fb78186fd..67d8d8721 100644 --- a/src/lib/utils/preconditions/conditions/PreconditionConditionAnd.ts +++ b/src/lib/utils/preconditions/conditions/PreconditionConditionAnd.ts @@ -1,4 +1,4 @@ -import { isErr, ok } from '../../../parsers/Result'; +import { isErr, ok } from '@sapphire/result'; import type { IPreconditionCondition } from './IPreconditionCondition'; /** diff --git a/src/lib/utils/preconditions/conditions/PreconditionConditionOr.ts b/src/lib/utils/preconditions/conditions/PreconditionConditionOr.ts index 2cbc02fac..9cd4af4d1 100644 --- a/src/lib/utils/preconditions/conditions/PreconditionConditionOr.ts +++ b/src/lib/utils/preconditions/conditions/PreconditionConditionOr.ts @@ -1,4 +1,4 @@ -import { isOk, ok } from '../../../parsers/Result'; +import { isOk, ok } from '@sapphire/result'; import type { PreconditionContainerResult } from '../IPreconditionContainer'; import type { IPreconditionCondition } from './IPreconditionCondition'; diff --git a/src/lib/utils/resolvers/resolveGuildChannelPredicate.ts b/src/lib/utils/resolvers/resolveGuildChannelPredicate.ts index 54ea13ec8..1b9e8645a 100644 --- a/src/lib/utils/resolvers/resolveGuildChannelPredicate.ts +++ b/src/lib/utils/resolvers/resolveGuildChannelPredicate.ts @@ -1,8 +1,8 @@ import type { ChannelTypes, GuildBasedChannelTypes } from '@sapphire/discord.js-utilities'; +import { err, ok, Result } from '@sapphire/result'; import type { Nullish } from '@sapphire/utilities'; import type { Guild } from 'discord.js'; import type { Identifiers } from '../../errors/Identifiers'; -import { err, ok, Result } from '../../parsers/Result'; import { resolveGuildChannel } from '../../resolvers'; export function resolveGuildChannelPredicate( diff --git a/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts b/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts index 40415a5c0..02e3fd44f 100644 --- a/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts +++ b/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; +import { fromAsync, isErr } from '@sapphire/result'; import { Stopwatch } from '@sapphire/stopwatch'; -import { fromAsync, isErr } from '../../../lib/parsers/Result'; import { Listener } from '../../../lib/structures/Listener'; import { ChatInputCommandAcceptedPayload, Events } from '../../../lib/types/Events'; diff --git a/src/listeners/application-commands/context-menu/CoreContextMenuCommandAccepted.ts b/src/listeners/application-commands/context-menu/CoreContextMenuCommandAccepted.ts index a41eaebbe..50024b430 100644 --- a/src/listeners/application-commands/context-menu/CoreContextMenuCommandAccepted.ts +++ b/src/listeners/application-commands/context-menu/CoreContextMenuCommandAccepted.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; +import { fromAsync, isErr } from '@sapphire/result'; import { Stopwatch } from '@sapphire/stopwatch'; -import { fromAsync, isErr } from '../../../lib/parsers/Result'; import { Listener } from '../../../lib/structures/Listener'; import { ContextMenuCommandAcceptedPayload, Events } from '../../../lib/types/Events'; diff --git a/src/optional-listeners/error-listeners/CoreListenerError.ts b/src/optional-listeners/error-listeners/CoreListenerError.ts index 45a6c050e..7d614d14e 100644 --- a/src/optional-listeners/error-listeners/CoreListenerError.ts +++ b/src/optional-listeners/error-listeners/CoreListenerError.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; import { Listener } from '../../lib/structures/Listener'; -import { ListenerErrorPayload, Events } from '../../lib/types/Events'; +import { Events, ListenerErrorPayload } from '../../lib/types/Events'; export class CoreEvent extends Listener { public constructor(context: PieceContext) { diff --git a/src/optional-listeners/error-listeners/CoreMessageCommandError.ts b/src/optional-listeners/error-listeners/CoreMessageCommandError.ts index bfad8170c..c05488e23 100644 --- a/src/optional-listeners/error-listeners/CoreMessageCommandError.ts +++ b/src/optional-listeners/error-listeners/CoreMessageCommandError.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; import { Listener } from '../../lib/structures/Listener'; -import { MessageCommandErrorPayload, Events } from '../../lib/types/Events'; +import { Events, MessageCommandErrorPayload } from '../../lib/types/Events'; export class CoreEvent extends Listener { public constructor(context: PieceContext) { diff --git a/src/optional-listeners/message-command-listeners/CoreMessageCommandAccepted.ts b/src/optional-listeners/message-command-listeners/CoreMessageCommandAccepted.ts index 3123a53d5..6f35c2bf2 100644 --- a/src/optional-listeners/message-command-listeners/CoreMessageCommandAccepted.ts +++ b/src/optional-listeners/message-command-listeners/CoreMessageCommandAccepted.ts @@ -1,6 +1,6 @@ import type { PieceContext } from '@sapphire/pieces'; +import { fromAsync, isErr } from '@sapphire/result'; import { Stopwatch } from '@sapphire/stopwatch'; -import { fromAsync, isErr } from '../../lib/parsers/Result'; import { Listener } from '../../lib/structures/Listener'; import { Events, MessageCommandAcceptedPayload } from '../../lib/types/Events'; diff --git a/src/optional-listeners/message-command-listeners/CoreMessageCommandTyping.ts b/src/optional-listeners/message-command-listeners/CoreMessageCommandTyping.ts index c61c778a3..4a4930be3 100644 --- a/src/optional-listeners/message-command-listeners/CoreMessageCommandTyping.ts +++ b/src/optional-listeners/message-command-listeners/CoreMessageCommandTyping.ts @@ -1,8 +1,8 @@ -import type { MessageCommand } from '../../lib/structures/Command'; -import type { Message } from 'discord.js'; 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 { MessageCommandRunPayload, Events } from '../../lib/types/Events'; +import { Events, MessageCommandRunPayload } from '../../lib/types/Events'; export class CoreListener extends Listener { public constructor(context: PieceContext) { diff --git a/yarn.lock b/yarn.lock index 2a8b022bc..228873c74 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1096,6 +1096,7 @@ __metadata: "@sapphire/pieces": ^3.2.0 "@sapphire/prettier-config": ^1.3.0 "@sapphire/ratelimits": ^2.3.0 + "@sapphire/result": ^1.0.0 "@sapphire/stopwatch": ^1.3.0 "@sapphire/ts-config": ^3.3.0 "@sapphire/utilities": ^3.3.0 @@ -1159,6 +1160,13 @@ __metadata: languageName: node linkType: hard +"@sapphire/result@npm:^1.0.0": + version: 1.0.0 + resolution: "@sapphire/result@npm:1.0.0" + checksum: d72296438975620309da4248ac67a1e863c706bb1e05755709ba02b4c37ec19c968bdb2ab40ed9c15baeb7a082d1b72936a0d736fe1e18bdc7fce9302bb06207 + languageName: node + linkType: hard + "@sapphire/stopwatch@npm:^1.3.0": version: 1.3.0 resolution: "@sapphire/stopwatch@npm:1.3.0"