-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b09e6c5
commit 343df6d
Showing
12 changed files
with
233 additions
and
35 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
scripts/api_docs | ||
.DS_Store | ||
.idea/ | ||
**/dummy.ts |
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,9 +1,12 @@ | ||
import type { EveryChannels } from "../../types/channel.ts"; | ||
import type { Guild } from "../structures/guilds/guild.ts"; | ||
import type { Message } from "../structures/mod.ts"; | ||
|
||
// ...this is gonna be very painful to fix | ||
export type ClientEvents = { | ||
messageCreate: [Message]; | ||
messageCreate: [message: Message]; | ||
ready: []; | ||
guildCreate: [Guild]; | ||
guildCreate: [guild: Guild]; | ||
channelCreate: [channel: EveryChannels]; | ||
channelDelete: [channel: EveryChannels]; | ||
}; |
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,12 @@ | ||
import { GatewayHandler } from "../../../types/mod.ts"; | ||
|
||
const channelCreate: GatewayHandler<"CHANNEL_CREATE"> = ( | ||
client, | ||
[_, channel], | ||
) => { | ||
client.channels.set(channel.id, channel); | ||
const channelObj = client.channels.get(channel.id)!; | ||
client.emit("channelCreate", channelObj); | ||
}; | ||
|
||
export default channelCreate; |
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,12 @@ | ||
import { GatewayHandler } from "../../../types/mod.ts"; | ||
|
||
const channelDelete: GatewayHandler<"CHANNEL_DELETE"> = ( | ||
client, | ||
[_, channel], | ||
) => { | ||
const channelObj = client.channels.get(channel.id)!; | ||
client.channels.delete(channel.id); | ||
client.emit("channelDelete", channelObj); | ||
}; | ||
|
||
export default channelDelete; |
5 changes: 3 additions & 2 deletions
5
framework/src/gateway/guildCreate.ts → ...ework/src/gateway/handlers/guildCreate.ts
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
8 changes: 4 additions & 4 deletions
8
framework/src/gateway/messageCreate.ts → ...ork/src/gateway/handlers/messageCreate.ts
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
8 changes: 4 additions & 4 deletions
8
framework/src/gateway/ready.ts → framework/src/gateway/handlers/ready.ts
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,11 +1,15 @@ | ||
import type { GatewayHandler } from "../../types/gateway.ts"; | ||
import guildCreate from "./guildCreate.ts"; | ||
import messageCreate from "./messageCreate.ts"; | ||
import ready from "./ready.ts"; | ||
import channelCreate from "./handlers/channelCreate.ts"; | ||
import channelDelete from "./handlers/channelDelete.ts"; | ||
import guildCreate from "./handlers/guildCreate.ts"; | ||
import messageCreate from "./handlers/messageCreate.ts"; | ||
import ready from "./handlers/ready.ts"; | ||
|
||
// deno-lint-ignore no-explicit-any | ||
export const GatewayHandlers: { [K: string]: GatewayHandler<any> } = { | ||
MESSAGE_CREATE: messageCreate, | ||
READY: ready, | ||
GUILD_CREATE: guildCreate, | ||
CHANNEL_CREATE: channelCreate, | ||
CHANNEL_DELETE: channelDelete, | ||
}; |
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,80 @@ | ||
import { ChannelType } from "../../../types/mod.ts"; | ||
import type { | ||
ChannelPayload, | ||
DMChannelPayload, | ||
GroupDMChannelPayload, | ||
GuildAnnouncementChannelPayload, | ||
GuildCategoryPayload, | ||
GuildForumChannelPayload, | ||
GuildStageChannelPayload, | ||
GuildTextChannelPayload, | ||
GuildVoiceChannelPayload, | ||
} from "../../../types/mod.ts"; | ||
import type { Client } from "../client/mod.ts"; | ||
import { EveryChannels } from "../../types/channel.ts"; | ||
import { | ||
DMChannel, | ||
GroupDMChannel, | ||
GuildAnnouncementChannel, | ||
GuildCategory, | ||
GuildForumChannel, | ||
GuildStageChannel, | ||
GuildTextChannel, | ||
GuildVoiceChannel, | ||
} from "../structures/channels/mod.ts"; | ||
|
||
export const createChannel = <P extends ChannelPayload>( | ||
client: Client, | ||
payload: P, | ||
): EveryChannels => { | ||
switch (payload.type) { | ||
case ChannelType.GUILD_TEXT: | ||
return new GuildTextChannel( | ||
client, | ||
payload as unknown as GuildTextChannelPayload, | ||
); | ||
case ChannelType.DM: | ||
return new DMChannel( | ||
client, | ||
payload as unknown as DMChannelPayload, | ||
); | ||
case ChannelType.GUILD_VOICE: | ||
return new GuildVoiceChannel( | ||
client, | ||
payload as unknown as GuildVoiceChannelPayload, | ||
); | ||
case ChannelType.GROUP_DM: | ||
return new GroupDMChannel( | ||
client, | ||
payload as unknown as GroupDMChannelPayload, | ||
); | ||
case ChannelType.GUILD_CATEGORY: | ||
return new GuildCategory( | ||
client, | ||
payload as unknown as GuildCategoryPayload, | ||
); | ||
case ChannelType.GUILD_ANNOUNCEMENT: | ||
return new GuildAnnouncementChannel( | ||
client, | ||
payload as unknown as GuildAnnouncementChannelPayload, | ||
); | ||
// case ChannelType.ANNOUNCEMENT_THREAD: | ||
// case ChannelType.GUILD_PUBLIC_THREAD: | ||
// case ChannelType.GUILD_PRIVATE_THREAD: | ||
case ChannelType.GUILD_STAGE_VOICE: | ||
return new GuildStageChannel( | ||
client, | ||
payload as unknown as GuildStageChannelPayload, | ||
); | ||
// case ChannelType.GUILD_DIRECTORY: | ||
case ChannelType.GUILD_FORUM: | ||
return new GuildForumChannel( | ||
client, | ||
payload as unknown as GuildForumChannelPayload, | ||
); | ||
// case ChannelType.GUILD_MEDIA: | ||
default: | ||
// TODO: make a proper error type | ||
throw new Error("Unknown channel type"); | ||
} | ||
}; |
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,100 @@ | ||
import { ChannelType } from "../../mod.ts"; | ||
import type { | ||
DMChannel, | ||
GroupDMChannel, | ||
GuildAnnouncementChannel, | ||
GuildCategory, | ||
GuildForumChannel, | ||
GuildStageChannel, | ||
GuildTextChannel, | ||
GuildVoiceChannel, | ||
} from "../src/structures/channels/mod.ts"; | ||
|
||
export type GuildTextBasedChannels = | ||
| GuildAnnouncementChannel | ||
| GuildForumChannel | ||
| GuildTextChannel | ||
| GuildVoiceChannel; | ||
|
||
export type GuildThreadAvailableChannels = | ||
| GuildAnnouncementChannel | ||
| GuildForumChannel | ||
| GuildTextChannel; | ||
|
||
export type GuildVoiceBasedChannels = | ||
| GuildStageChannel | ||
| GuildVoiceChannel; | ||
|
||
export type GuildChannels = | ||
| GuildTextBasedChannels | ||
| GuildVoiceBasedChannels | ||
| GuildThreadAvailableChannels | ||
| GuildCategory; | ||
|
||
export type DMChannels = DMChannel | GroupDMChannel; | ||
|
||
export type VoiceChannels = GuildVoiceBasedChannels | DMChannels; | ||
|
||
export type TextChannels = GuildTextBasedChannels | DMChannels; | ||
|
||
export type EveryChannels = GuildChannels | DMChannels; | ||
|
||
export const isGuildChannel = ( | ||
channel: EveryChannels, | ||
): channel is GuildChannels => { | ||
return [ | ||
ChannelType.ANNOUNCEMENT_THREAD, | ||
ChannelType.GUILD_ANNOUNCEMENT, | ||
ChannelType.GUILD_CATEGORY, | ||
ChannelType.GUILD_DIRECTORY, | ||
ChannelType.GUILD_FORUM, | ||
ChannelType.GUILD_PRIVATE_THREAD, | ||
ChannelType.GUILD_PUBLIC_THREAD, | ||
ChannelType.GUILD_STAGE_VOICE, | ||
ChannelType.GUILD_TEXT, | ||
ChannelType.GUILD_VOICE, | ||
].includes(channel.type); | ||
}; | ||
|
||
export const isDMChannel = (channel: EveryChannels): channel is DMChannels => { | ||
return [ChannelType.DM, ChannelType.GROUP_DM].includes(channel.type); | ||
}; | ||
|
||
export const isTextChannel = ( | ||
channel: EveryChannels, | ||
): channel is TextChannels => { | ||
return [ | ||
ChannelType.DM, | ||
ChannelType.GROUP_DM, | ||
ChannelType.ANNOUNCEMENT_THREAD, | ||
ChannelType.GUILD_ANNOUNCEMENT, | ||
ChannelType.GUILD_FORUM, | ||
ChannelType.GUILD_PRIVATE_THREAD, | ||
ChannelType.GUILD_PUBLIC_THREAD, | ||
ChannelType.GUILD_TEXT, | ||
ChannelType.GUILD_VOICE, | ||
].includes( | ||
channel.type, | ||
); | ||
}; | ||
|
||
export const isThreadAvailableChannel = ( | ||
channel: EveryChannels, | ||
): channel is GuildThreadAvailableChannels => { | ||
return [ | ||
ChannelType.GUILD_ANNOUNCEMENT, | ||
ChannelType.GUILD_FORUM, | ||
ChannelType.GUILD_TEXT, | ||
].includes(channel.type); | ||
}; | ||
|
||
export const isVoiceChannel = ( | ||
channel: EveryChannels, | ||
): channel is VoiceChannels => { | ||
return [ | ||
ChannelType.DM, | ||
ChannelType.GROUP_DM, | ||
ChannelType.GUILD_STAGE_VOICE, | ||
ChannelType.GUILD_VOICE, | ||
].includes(channel.type); | ||
}; |
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