diff --git a/mod.ts b/mod.ts index fb958fb..cf02b7c 100644 --- a/mod.ts +++ b/mod.ts @@ -96,7 +96,7 @@ export { Intents } from './src/utils/intents.ts' export * from './src/utils/permissions.ts' export { UserFlagsManager } from './src/utils/userFlags.ts' export { HarmonyEventEmitter } from './src/utils/events.ts' -export type { EveryChannelTypes } from './src/utils/getChannelByType.ts' +export type { EveryChannelTypes } from './src/utils/channel.ts' export * from './src/utils/bitfield.ts' export type { ActivityGame, @@ -175,3 +175,5 @@ export type { Dict } from './src/utils/dict.ts' export * from './src/cache/redis.ts' export { ColorUtil } from './src/utils/colorutil.ts' export type { Colors } from './src/utils/colorutil.ts' +export { StoreChannel } from './src/structures/guildStoreChannel.ts' +export { StageVoiceChannel } from './src/structures/guildStageVoiceChannel.ts' diff --git a/src/gateway/handlers/channelCreate.ts b/src/gateway/handlers/channelCreate.ts index 4d63f8f..400457d 100644 --- a/src/gateway/handlers/channelCreate.ts +++ b/src/gateway/handlers/channelCreate.ts @@ -1,5 +1,5 @@ import type { Gateway, GatewayEventHandler } from '../mod.ts' -import getChannelByType from '../../utils/getChannelByType.ts' +import getChannelByType from '../../utils/channel.ts' import type { ChannelPayload, GuildChannelPayload diff --git a/src/gateway/handlers/mod.ts b/src/gateway/handlers/mod.ts index 748ebe4..0bb7cb0 100644 --- a/src/gateway/handlers/mod.ts +++ b/src/gateway/handlers/mod.ts @@ -57,7 +57,7 @@ import type { Presence } from '../../structures/presence.ts' import type { EveryChannelTypes, EveryTextChannelTypes -} from '../../utils/getChannelByType.ts' +} from '../../utils/channel.ts' import { interactionCreate } from './interactionCreate.ts' import type { Interaction } from '../../structures/slash.ts' import type { CommandContext } from '../../commands/command.ts' diff --git a/src/managers/channels.ts b/src/managers/channels.ts index 7738900..b949440 100644 --- a/src/managers/channels.ts +++ b/src/managers/channels.ts @@ -9,7 +9,7 @@ import type { MessageOptions } from '../types/channel.ts' import { CHANNEL } from '../types/endpoint.ts' -import getChannelByType from '../utils/getChannelByType.ts' +import getChannelByType from '../utils/channel.ts' import { BaseManager } from './base.ts' export type AllMessageOptions = MessageOptions | Embed diff --git a/src/structures/channel.ts b/src/structures/channel.ts index eea3074..96cd4ba 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -11,7 +11,7 @@ import type { import { OverrideType } from '../types/channel.ts' import { CHANNEL } from '../types/endpoint.ts' import type { GuildChannelPayloads, GuildChannels } from '../types/guild.ts' -import getChannelByType from '../utils/getChannelByType.ts' +import getChannelByType from '../utils/channel.ts' import { Permissions } from '../utils/permissions.ts' import { SnowflakeBase } from './base.ts' import type { Guild } from './guild.ts' diff --git a/src/structures/guildStageVoiceChannel.ts b/src/structures/guildStageVoiceChannel.ts new file mode 100644 index 0000000..6c0b1ea --- /dev/null +++ b/src/structures/guildStageVoiceChannel.ts @@ -0,0 +1,3 @@ +import { VoiceChannel } from './guildVoiceChannel.ts' + +export class StageVoiceChannel extends VoiceChannel {} diff --git a/src/structures/guildStoreChannel.ts b/src/structures/guildStoreChannel.ts new file mode 100644 index 0000000..e753a2e --- /dev/null +++ b/src/structures/guildStoreChannel.ts @@ -0,0 +1,3 @@ +import { GuildChannel } from './channel.ts' + +export class StoreChannel extends GuildChannel {} diff --git a/src/types/channel.ts b/src/types/channel.ts index 39e792c..8db4e5e 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -157,7 +157,8 @@ export enum ChannelTypes { GROUP_DM = 3, GUILD_CATEGORY = 4, GUILD_NEWS = 5, - GUILD_STORE = 6 + GUILD_STORE = 6, + GUILD_STAGE_VOICE = 13 } export interface MessagePayload { @@ -336,7 +337,11 @@ export enum MessageTypes { USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, CHANNEL_FOLLOW_ADD = 12, GUILD_DISCOVERY_DISQUALIFIED = 14, - GUILD_DISCOVERY_REQUALIFIED = 15 + GUILD_DISCOVERY_REQUALIFIED = 15, + GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = 16, + GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING = 17, + REPLY = 19, + APPLICATION_COMMAND = 20 } export enum MessageActivityTypes { diff --git a/src/types/permissionFlags.ts b/src/types/permissionFlags.ts index 928a16f..7f9a542 100644 --- a/src/types/permissionFlags.ts +++ b/src/types/permissionFlags.ts @@ -32,5 +32,7 @@ export const PermissionFlags: { [key: string]: bigint } = { MANAGE_ROLES: 1n << 28n, MANAGE_WEBHOOKS: 1n << 29n, MANAGE_EMOJIS: 1n << 30n, - USE_SLASH_COMMANDS: 1n << 31n + USE_SLASH_COMMANDS: 1n << 31n, + // Might be removed (as PR says) + REQUEST_TO_SPEAK: 0x100000000n } diff --git a/src/types/voice.ts b/src/types/voice.ts index 6bb6ffc..a9e5c3f 100644 --- a/src/types/voice.ts +++ b/src/types/voice.ts @@ -41,6 +41,7 @@ export interface VoiceStatePayload { self_stream?: boolean self_video: boolean suppress: boolean + request_to_speak_timestamp: string | null } /** Voice Region Structure */ diff --git a/src/utils/getChannelByType.ts b/src/utils/channel.ts similarity index 53% rename from src/utils/getChannelByType.ts rename to src/utils/channel.ts index 9ee4c7e..2bc062f 100644 --- a/src/utils/getChannelByType.ts +++ b/src/utils/channel.ts @@ -23,6 +23,8 @@ import { VoiceChannel } from '../structures/guildVoiceChannel.ts' import { Guild } from '../structures/guild.ts' import { TextChannel } from '../structures/textChannel.ts' import { Channel, GuildChannel } from '../structures/channel.ts' +import { StoreChannel } from '../structures/guildStoreChannel.ts' +import { StageVoiceChannel } from '../structures/guildStageVoiceChannel.ts' export type EveryTextChannelTypes = | TextChannel @@ -80,10 +82,22 @@ const getChannelByType = ( data as GuildTextChannelPayload, guild ) + case ChannelTypes.GUILD_STORE: + if (guild === undefined) + throw new Error('No Guild was provided to construct Channel') + return new StoreChannel(client, data as GuildTextChannelPayload, guild) case ChannelTypes.GUILD_VOICE: if (guild === undefined) throw new Error('No Guild was provided to construct Channel') return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild) + case ChannelTypes.GUILD_STAGE_VOICE: + if (guild === undefined) + throw new Error('No Guild was provided to construct Channel') + return new StageVoiceChannel( + client, + data as GuildVoiceChannelPayload, + guild + ) case ChannelTypes.DM: return new DMChannel(client, data as DMChannelPayload) case ChannelTypes.GROUP_DM: @@ -92,3 +106,70 @@ const getChannelByType = ( } export default getChannelByType + +export function isTextChannel(channel: Channel): channel is TextChannel { + return ( + channel.type === ChannelTypes.DM || + channel.type === ChannelTypes.GROUP_DM || + channel.type === ChannelTypes.GUILD_TEXT || + channel.type === ChannelTypes.GUILD_NEWS + ) +} + +export function isDMChannel(channel: Channel): channel is DMChannel { + return channel.type === ChannelTypes.DM +} + +export function isGroupDMChannel(channel: Channel): channel is GroupDMChannel { + return channel.type === ChannelTypes.GROUP_DM +} + +export function isGuildTextChannel( + channel: Channel +): channel is GuildTextChannel { + return channel.type === ChannelTypes.GUILD_TEXT +} + +export function isGuildBasedTextChannel( + channel: Channel +): channel is GuildTextBasedChannel { + return ( + channel.type === ChannelTypes.GUILD_TEXT || + channel.type === ChannelTypes.GUILD_NEWS + ) +} + +export function isCategoryChannel( + channel: Channel +): channel is CategoryChannel { + return channel.type === ChannelTypes.GUILD_CATEGORY +} + +export function isNewsChannel(channel: Channel): channel is NewsChannel { + return channel.type === ChannelTypes.GUILD_NEWS +} + +export function isVoiceChannel(channel: Channel): channel is VoiceChannel { + return channel.type === ChannelTypes.GUILD_VOICE +} + +export function isStageVoiceChannel( + channel: Channel +): channel is StageVoiceChannel { + return channel.type === ChannelTypes.GUILD_STAGE_VOICE +} + +export function isStoreChannel(channel: Channel): channel is StoreChannel { + return channel.type === ChannelTypes.GUILD_STORE +} + +export function isGuildChannel(channel: Channel): channel is GuildChannel { + return ( + channel.type === ChannelTypes.GUILD_CATEGORY || + channel.type === ChannelTypes.GUILD_NEWS || + channel.type === ChannelTypes.GUILD_STORE || + channel.type === ChannelTypes.GUILD_TEXT || + channel.type === ChannelTypes.GUILD_VOICE || + channel.type === ChannelTypes.GUILD_STAGE_VOICE + ) +}