-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make errors take objects instead of many params (#144)
- Loading branch information
Showing
31 changed files
with
372 additions
and
170 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
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,22 +1,22 @@ | ||
import { isDMChannel } from '@sapphire/discord.js-utilities'; | ||
import type { PieceContext } from '@sapphire/pieces'; | ||
import type { DMChannel } from 'discord.js'; | ||
import { Argument, ArgumentResult } from '../lib/structures/Argument'; | ||
import type { Channel, DMChannel } from 'discord.js'; | ||
import type { ArgumentResult } from '../lib/structures/Argument'; | ||
import { ExtendedArgument, ExtendedArgumentContext } from '../lib/structures/ExtendedArgument'; | ||
|
||
export class CoreArgument extends Argument<DMChannel> { | ||
export class CoreArgument extends ExtendedArgument<'channel', DMChannel> { | ||
public constructor(context: PieceContext) { | ||
super(context, { name: 'dmChannel' }); | ||
super(context, { baseArgument: 'channel', name: 'dmChannel' }); | ||
} | ||
|
||
public run(argument: string): ArgumentResult<DMChannel> { | ||
const channel = this.context.client.channels.cache.get(argument); | ||
|
||
if (!channel) { | ||
return this.error(argument, 'ArgumentChannelMissingChannel', 'The argument did not resolve to a channel.'); | ||
} | ||
|
||
public handle(channel: Channel, context: ExtendedArgumentContext): ArgumentResult<DMChannel> { | ||
return isDMChannel(channel) | ||
? this.ok(channel) | ||
: this.error(argument, 'ArgumentDMChannelInvalidChannel', 'The argument did not resolve to a DM channel.'); | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentDMChannelInvalidChannel', | ||
message: 'The argument did not resolve to a DM channel.', | ||
context | ||
}); | ||
} | ||
} |
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,17 +1,22 @@ | ||
import type { PieceContext } from '@sapphire/pieces'; | ||
import { URL } from 'url'; | ||
import { Argument, ArgumentResult } from '../lib/structures/Argument'; | ||
import { Argument, ArgumentContext, ArgumentResult } from '../lib/structures/Argument'; | ||
|
||
export class CoreArgument extends Argument<URL> { | ||
public constructor(context: PieceContext) { | ||
super(context, { name: 'hyperlink', aliases: ['url'] }); | ||
} | ||
|
||
public run(argument: string): ArgumentResult<URL> { | ||
public run(parameter: string, context: ArgumentContext): ArgumentResult<URL> { | ||
try { | ||
return this.ok(new URL(argument)); | ||
return this.ok(new URL(parameter)); | ||
} catch { | ||
return this.error(argument, 'ArgumentHyperlinkInvalidURL', 'The argument did not resolve to a valid URL.'); | ||
return this.error({ | ||
parameter, | ||
identifier: 'ArgumentHyperlinkInvalidURL', | ||
message: 'The argument did not resolve to a valid URL.', | ||
context | ||
}); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.