-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
139 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { ChannelMentionRegex, ChannelTypes } from '@sapphire/discord.js-utilities'; | ||
import { container } from '@sapphire/pieces'; | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import type { Message, Snowflake } from 'discord.js'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveChannel(parameter: string, message: Message): Result<ChannelTypes, Identifiers.ArgumentChannelError> { | ||
const channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake; | ||
const channel = (message.guild ? message.guild.channels : container.client.channels).cache.get(channelId); | ||
if (channel) return ok(channel as ChannelTypes); | ||
return err(Identifiers.ArgumentChannelError); | ||
if (channel) return Result.ok(channel as ChannelTypes); | ||
return Result.err(Identifiers.ArgumentChannelError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveEnum( | ||
parameter: string, | ||
options?: { enum?: string[]; caseInsensitive?: boolean } | ||
): Result<string, Identifiers.ArgumentEnumEmptyError | Identifiers.ArgumentEnumError> { | ||
if (!options?.enum?.length) { | ||
return err(Identifiers.ArgumentEnumEmptyError); | ||
return Result.err(Identifiers.ArgumentEnumEmptyError); | ||
} | ||
|
||
if (!options.caseInsensitive && !options.enum.includes(parameter)) { | ||
return err(Identifiers.ArgumentEnumError); | ||
return Result.err(Identifiers.ArgumentEnumError); | ||
} | ||
|
||
if (options.caseInsensitive && !options.enum.some((v) => v.toLowerCase() === parameter.toLowerCase())) { | ||
return err(Identifiers.ArgumentEnumError); | ||
return Result.err(Identifiers.ArgumentEnumError); | ||
} | ||
|
||
return ok(parameter); | ||
return Result.ok(parameter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveFloat( | ||
parameter: string, | ||
options?: { minimum?: number; maximum?: number } | ||
): Result<number, Identifiers.ArgumentFloatError | Identifiers.ArgumentFloatTooSmall | Identifiers.ArgumentFloatTooLarge> { | ||
const parsed = Number(parameter); | ||
if (Number.isNaN(parsed)) return err(Identifiers.ArgumentFloatError); | ||
if (Number.isNaN(parsed)) return Result.err(Identifiers.ArgumentFloatError); | ||
|
||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return err(Identifiers.ArgumentFloatTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return err(Identifiers.ArgumentFloatTooLarge); | ||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return Result.err(Identifiers.ArgumentFloatTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return Result.err(Identifiers.ArgumentFloatTooLarge); | ||
|
||
return ok(parsed); | ||
return Result.ok(parsed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { err, from, isOk, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { URL } from 'url'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveHyperlink(parameter: string): Result<URL, Identifiers.ArgumentHyperlinkError> { | ||
const result = from(() => new URL(parameter)); | ||
return isOk(result) ? result : err(Identifiers.ArgumentHyperlinkError); | ||
const result = Result.from(() => new URL(parameter)); | ||
return result.isOk() ? result : Result.err(Identifiers.ArgumentHyperlinkError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveInteger( | ||
parameter: string, | ||
options?: { minimum?: number; maximum?: number } | ||
): Result<number, Identifiers.ArgumentIntegerError | Identifiers.ArgumentIntegerTooSmall | Identifiers.ArgumentIntegerTooLarge> { | ||
const parsed = Number(parameter); | ||
if (!Number.isInteger(parsed)) return err(Identifiers.ArgumentIntegerError); | ||
if (!Number.isInteger(parsed)) return Result.err(Identifiers.ArgumentIntegerError); | ||
|
||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return err(Identifiers.ArgumentIntegerTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return err(Identifiers.ArgumentIntegerTooLarge); | ||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return Result.err(Identifiers.ArgumentIntegerTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return Result.err(Identifiers.ArgumentIntegerTooLarge); | ||
|
||
return ok(parsed); | ||
return Result.ok(parsed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveNumber( | ||
parameter: string, | ||
options?: { minimum?: number; maximum?: number } | ||
): Result<number, Identifiers.ArgumentNumberError | Identifiers.ArgumentNumberTooSmall | Identifiers.ArgumentNumberTooLarge> { | ||
const parsed = Number(parameter); | ||
if (Number.isNaN(parsed)) return err(Identifiers.ArgumentNumberError); | ||
if (Number.isNaN(parsed)) return Result.err(Identifiers.ArgumentNumberError); | ||
|
||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return err(Identifiers.ArgumentNumberTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return err(Identifiers.ArgumentNumberTooLarge); | ||
if (typeof options?.minimum === 'number' && parsed < options.minimum) return Result.err(Identifiers.ArgumentNumberTooSmall); | ||
if (typeof options?.maximum === 'number' && parsed > options.maximum) return Result.err(Identifiers.ArgumentNumberTooLarge); | ||
|
||
return ok(parsed); | ||
return Result.ok(parsed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveString( | ||
parameter: string, | ||
options?: { minimum?: number; maximum?: number } | ||
): Result<string, Identifiers.ArgumentStringTooShort | Identifiers.ArgumentStringTooLong> { | ||
if (typeof options?.minimum === 'number' && parameter.length < options.minimum) { | ||
return err(Identifiers.ArgumentStringTooShort); | ||
return Result.err(Identifiers.ArgumentStringTooShort); | ||
} | ||
|
||
if (typeof options?.maximum === 'number' && parameter.length > options.maximum) { | ||
return err(Identifiers.ArgumentStringTooLong); | ||
return Result.err(Identifiers.ArgumentStringTooLong); | ||
} | ||
|
||
return ok(parameter); | ||
return Result.ok(parameter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { SnowflakeRegex, UserOrMemberMentionRegex } from '@sapphire/discord-utilities'; | ||
import { container } from '@sapphire/pieces'; | ||
import { err, ok, Result } from '@sapphire/result'; | ||
import { Result } from '@sapphire/result'; | ||
import type { Snowflake, User } from 'discord.js'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export async function resolveUser(parameter: string): Promise<Result<User, Identifiers.ArgumentUserError>> { | ||
const userId = UserOrMemberMentionRegex.exec(parameter) ?? SnowflakeRegex.exec(parameter); | ||
const user = userId ? await container.client.users.fetch(userId[1] as Snowflake).catch(() => null) : null; | ||
if (user) return ok(user); | ||
return err(Identifiers.ArgumentUserError); | ||
if (user) return Result.ok(user); | ||
return Result.err(Identifiers.ArgumentUserError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.