-
-
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.
feat: add partial dm channel argument (#288)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
- Loading branch information
1 parent
30ee759
commit c8c74de
Showing
6 changed files
with
543 additions
and
401 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { PieceContext } from '@sapphire/pieces'; | ||
import type { DMChannel, PartialDMChannel } from 'discord.js'; | ||
import { resolvePartialDMChannel } from '../lib/resolvers'; | ||
import { Argument, ArgumentContext, ArgumentResult } from '../lib/structures/Argument'; | ||
|
||
export class CoreArgument extends Argument<DMChannel | PartialDMChannel> { | ||
public constructor(context: PieceContext) { | ||
super(context, { name: 'partialDMChannel' }); | ||
} | ||
|
||
public run(parameter: string, context: ArgumentContext): ArgumentResult<DMChannel | PartialDMChannel> { | ||
const resolved = resolvePartialDMChannel(parameter, context.message); | ||
if (resolved.success) return this.ok(resolved.value); | ||
return this.error({ | ||
parameter, | ||
identifier: resolved.error, | ||
message: 'The argument did not resolve to a Partial 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isDMChannel } from '@sapphire/discord.js-utilities'; | ||
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( | ||
parameter: string, | ||
message: Message | ||
): Result<DMChannel | PartialDMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> { | ||
const result = resolveChannel(parameter, message); | ||
if (!result.success) return result; | ||
if (isDMChannel(result.value)) return ok(result.value); | ||
return err(Identifiers.ArgumentDMChannelError); | ||
} |
Oops, something went wrong.