-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace channel type guards with getChannelByName function
- Loading branch information
Showing
7 changed files
with
157 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"printWidth": 140, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { APIPartialChannel, BaseChannel, CategoryChannel, ChannelType, TextChannel } from 'discord.js' | ||
import { ChannelType, NonThreadGuildBasedChannel } from 'discord.js' | ||
import getGuildCache from './guildCache.js' | ||
|
||
function isTextChannel(channel: BaseChannel | APIPartialChannel): channel is TextChannel { | ||
return channel.type === ChannelType.GuildText | ||
} | ||
type NonThreadGuildBasedChannelType = | ||
| ChannelType.GuildText | ||
| ChannelType.GuildVoice | ||
| ChannelType.GuildNews | ||
| ChannelType.GuildStageVoice | ||
| ChannelType.GuildCategory | ||
|
||
async function getChannelByName<T extends NonThreadGuildBasedChannel>( | ||
channelName: string, | ||
channelType: NonThreadGuildBasedChannelType, | ||
): Promise<T | undefined> { | ||
const { channels } = (await getGuildCache()) || throwError('Unable to get guild cache.') | ||
const channel = channels.find((channel) => channel.name === channelName) | ||
|
||
function isCategoryChannel(channel: BaseChannel): channel is CategoryChannel { | ||
return channel.type === ChannelType.GuildCategory | ||
return channel && channel.type === channelType ? (channel as T) : undefined | ||
} | ||
|
||
function throwError(error: string): never { | ||
throw new Error(error) | ||
} | ||
|
||
export { isTextChannel, isCategoryChannel, throwError } | ||
export { getChannelByName, throwError } |