-
-
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.
Co-authored-by: Jeroen Claassens <support@favware.tech>
- Loading branch information
Showing
16 changed files
with
248 additions
and
133 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,12 +1,19 @@ | ||
import { ChannelMentionRegex, ChannelTypes } from '@sapphire/discord.js-utilities'; | ||
import { container } from '@sapphire/pieces'; | ||
import { Result } from '@sapphire/result'; | ||
import type { Message, Snowflake } from 'discord.js'; | ||
import type { BaseCommandInteraction, Message, Snowflake } from 'discord.js'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
|
||
export function resolveChannel(parameter: string, message: Message): Result<ChannelTypes, Identifiers.ArgumentChannelError> { | ||
export function resolveChannel( | ||
parameter: string, | ||
messageOrInteraction: Message | BaseCommandInteraction | ||
): 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 Result.ok(channel as ChannelTypes); | ||
const channel = (messageOrInteraction.guild ? messageOrInteraction.guild.channels : container.client.channels).cache.get(channelId); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { isDMChannel } from '@sapphire/discord.js-utilities'; | ||
import { Result } from '@sapphire/result'; | ||
import type { DMChannel, Message } from 'discord.js'; | ||
import type { BaseCommandInteraction, DMChannel, Message } from 'discord.js'; | ||
import { Identifiers } from '../errors/Identifiers'; | ||
import { resolveChannel } from './channel'; | ||
|
||
export function resolveDMChannel( | ||
parameter: string, | ||
message: Message | ||
messageOrInteraction: Message | BaseCommandInteraction | ||
): Result<DMChannel, Identifiers.ArgumentChannelError | Identifiers.ArgumentDMChannelError> { | ||
const result = resolveChannel(parameter, message); | ||
const result = resolveChannel(parameter, messageOrInteraction); | ||
return result.mapInto((value) => { | ||
if (isDMChannel(value) && !value.partial) return Result.ok(value); | ||
if (isDMChannel(value) && !value.partial) { | ||
return Result.ok(value); | ||
} | ||
|
||
return Result.err<Identifiers.ArgumentDMChannelError>(Identifiers.ArgumentDMChannelError); | ||
}); | ||
} |
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
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.