diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 358558525..7d24bee7b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -15,9 +15,11 @@ Examples of good PR title: -- fix(controllers/interactions): cache member from INTERACTION_CREATE payload +- fix(handlers/INTERACTION_CREATE): cache member object - docs: improve wording -- feat(handlers/guild): add editGuild() function Examples of bad PR title: +- feat: add cache manager module +- feat(helpers): add editGuild() +- refactor(ws/shard): remove redundant checks Examples of bad PR title: diff --git a/docs/src/advanced/customizations.md b/docs/src/advanced/customizations.md index 02bd667cc..ebc98490a 100644 --- a/docs/src/advanced/customizations.md +++ b/docs/src/advanced/customizations.md @@ -347,10 +347,10 @@ methods on the cacheHandlers. The current list of methods available are: - set - forEach -## Custom Gateway Payload Handling (Controllers) +## Custom Gateway Payload Handling (Handlers) -Controllers are one of the most powerful features of Discordeno. They allow you -to take control of how Discordeno handles the Discord payloads from the gateway. +Handlers are one of the most powerful features of Discordeno. They allow you to +take control of how Discordeno handles the Discord payloads from the gateway. When an event comes in, you can override and control how you want it to work. For example, if your bot does not use emojis at all, you could simply just take control over the GUILD_EMOJIS_UPDATE event and prevent anyone from caching any @@ -362,14 +362,10 @@ Someone once asked if it was possible to make Discordeno, show the number of users currently typing in the server. He had managed to build this himself in his bot, but he wanted to do it inside the library itself. In order to keep Discordeno minimalistic and memory efficient I avoided adding this. So let's see -how we could achieve this same thing with Controllers. +how we could achieve this same thing: ```ts -import { - controllers, - eventHandlers, - TypingStartPayload, -} from "../../../deps.ts"; +import { eventHandlers, handlers, TypingStartPayload } from "../../../deps.ts"; const typingUsers = new Map(); @@ -379,7 +375,7 @@ function createTimeout(userID: String) { }, 10000); } -controllers.TYPING_START = function (data) { +handlers.TYPING_START = function (data) { const payload = data.d as TypingStartPayload; eventHandlers.typingStart?.(payload); @@ -391,18 +387,16 @@ controllers.TYPING_START = function (data) { }; ``` -Controllers are amazing in so many ways. This is just a basic example but it's -true potential is only limited by your imagination. I would love to see what you -all can create with controllers. +This is just a basic example but it's true potential is only limited by your +imagination. I would love to see what you all can create. -Something worth noting about why Discordeno controllers are so amazing is that -it allows you to never depend on me. When Discord releases something new, you -don't need to wait for me to update the library to access it. Without -controllers, if you wanted access to a feature you would need to wait for the -library to be updated or have to fork it, modify it and modify your code for it. -Then when the library does get updated, you need to switch back to it and modify -your code again possibly to how the lib designed it. With controllers, you never -have to fork or anything. Just take control! +Something worth noting about why Discordeno handlers are so amazing is that it +allows you to never depend on me. When Discord releases something new, you don't +need to wait for me to update the library to access it. Without handlers, if you +wanted access to a feature you would need to wait for the library to be updated +or have to fork it, modify it and modify your code for it. Then when the library +does get updated, you need to switch back to it and modify your code again +possibly to how the lib designed it. With handlers, you never have to fork or +anything. Just take control! -Controllers are extremely powerful. **Remember with great power comes great -bugs!** +Remember with great power comes great bugs! diff --git a/mod.ts b/mod.ts index 412b757e7..dab4f8b45 100644 --- a/mod.ts +++ b/mod.ts @@ -1,16 +1,16 @@ export * from "./src/cache.ts"; -export * from "./src/api/handlers/channel.ts"; -export * from "./src/api/handlers/guild.ts"; -export * from "./src/api/handlers/member.ts"; -export * from "./src/api/handlers/message.ts"; -export * from "./src/api/handlers/oauth.ts"; -export * from "./src/api/handlers/webhook.ts"; -export * from "./src/api/structures/channel.ts"; -export * from "./src/api/structures/guild.ts"; -export * from "./src/api/structures/member.ts"; -export * from "./src/api/structures/message.ts"; -export * from "./src/api/structures/mod.ts"; -export * from "./src/api/structures/role.ts"; +export * from "./src/helpers/channel.ts"; +export * from "./src/helpers/guild.ts"; +export * from "./src/helpers/member.ts"; +export * from "./src/helpers/message.ts"; +export * from "./src/helpers/oauth.ts"; +export * from "./src/helpers/webhook.ts"; +export * from "./src/structures/channel.ts"; +export * from "./src/structures/guild.ts"; +export * from "./src/structures/member.ts"; +export * from "./src/structures/message.ts"; +export * from "./src/structures/mod.ts"; +export * from "./src/structures/role.ts"; export * from "./src/bot.ts"; export * from "./src/rest/mod.ts"; export * from "./src/types/mod.ts"; @@ -19,4 +19,4 @@ export * from "./src/util/collection.ts"; export * from "./src/util/permissions.ts"; export * from "./src/util/utils.ts"; export * from "./src/ws/mod.ts"; -export * from "./src/api/controllers/mod.ts"; +export * from "./src/handlers/mod.ts"; diff --git a/src/api/controllers/presence/TYPING_START.ts b/src/api/controllers/presence/TYPING_START.ts deleted file mode 100644 index f221c6fe4..000000000 --- a/src/api/controllers/presence/TYPING_START.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, TypingStartPayload } from "../../../types/mod.ts"; - -export function handleTypingStart(data: DiscordPayload) { - eventHandlers.typingStart?.(data.d as TypingStartPayload); -} diff --git a/src/bot.ts b/src/bot.ts index 2dce72716..a965aa89b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,4 +1,4 @@ -import { getGatewayBot } from "./api/handlers/gateway.ts"; +import { getGatewayBot } from "./helpers/gateway.ts"; import { BotConfig, DiscordBotGatewayData, diff --git a/src/cache.ts b/src/cache.ts index 82ae7daf8..98c741d7e 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,7 +3,7 @@ import { PresenceUpdatePayload } from "./types/mod.ts"; import { cache } from "./util/cache.ts"; import { Collection } from "./util/collection.ts"; -import { Channel, Guild, Member, Message } from "./api/structures/mod.ts"; +import { Channel, Guild, Member, Message } from "./structures/mod.ts"; export type TableName = | "guilds" diff --git a/src/api/controllers/READY.ts b/src/handlers/READY.ts similarity index 90% rename from src/api/controllers/READY.ts rename to src/handlers/READY.ts index 0d6f176a9..0192c696b 100644 --- a/src/api/controllers/READY.ts +++ b/src/handlers/READY.ts @@ -3,14 +3,14 @@ import { lastShardID, setApplicationID, setBotID, -} from "../../bot.ts"; -import { DiscordPayload, ReadyPayload } from "../../types/discord.ts"; -import { cache } from "../../util/cache.ts"; -import { delay } from "../../util/utils.ts"; -import { allowNextShard, basicShards } from "../../ws/mod.ts"; +} from "../bot.ts"; +import { DiscordPayload, ReadyPayload } from "../types/discord.ts"; +import { cache } from "../util/cache.ts"; +import { delay } from "../util/utils.ts"; +import { allowNextShard, basicShards } from "../ws/mod.ts"; import { initialMemberLoadQueue } from "../structures/guild.ts"; import { structures } from "../structures/mod.ts"; -import { cacheHandlers } from "../../cache.ts"; +import { cacheHandlers } from "../cache.ts"; export async function handleReady( data: DiscordPayload, diff --git a/src/api/controllers/channels/CHANNEL_CREATE.ts b/src/handlers/channels/CHANNEL_CREATE.ts similarity index 67% rename from src/api/controllers/channels/CHANNEL_CREATE.ts rename to src/handlers/channels/CHANNEL_CREATE.ts index a2770aaf9..d173000db 100644 --- a/src/api/controllers/channels/CHANNEL_CREATE.ts +++ b/src/handlers/channels/CHANNEL_CREATE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { ChannelCreatePayload, DiscordPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleChannelCreate(data: DiscordPayload) { const payload = data.d as ChannelCreatePayload; diff --git a/src/api/controllers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts similarity index 89% rename from src/api/controllers/channels/CHANNEL_DELETE.ts rename to src/handlers/channels/CHANNEL_DELETE.ts index a6c66bc41..0ddea96e2 100644 --- a/src/api/controllers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -1,10 +1,10 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { ChannelCreatePayload, ChannelTypes, DiscordPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleChannelDelete(data: DiscordPayload) { const payload = data.d as ChannelCreatePayload; diff --git a/src/api/controllers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts similarity index 78% rename from src/api/controllers/channels/CHANNEL_PINS_UPDATE.ts rename to src/handlers/channels/CHANNEL_PINS_UPDATE.ts index e32db1a7e..a1d3f2c3e 100644 --- a/src/api/controllers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,9 +1,9 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordChannelPinsUpdateEvent, DiscordPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleChannelPinsUpdate(data: DiscordPayload) { const payload = data.d as DiscordChannelPinsUpdateEvent; diff --git a/src/api/controllers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts similarity index 73% rename from src/api/controllers/channels/CHANNEL_UPDATE.ts rename to src/handlers/channels/CHANNEL_UPDATE.ts index 288e4d4f8..bed067acf 100644 --- a/src/api/controllers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { ChannelCreatePayload, DiscordPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleChannelUpdate(data: DiscordPayload) { const payload = data.d as ChannelCreatePayload; diff --git a/src/api/controllers/commands/APPLICATION_COMMAND_CREATE.ts b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts similarity index 69% rename from src/api/controllers/commands/APPLICATION_COMMAND_CREATE.ts rename to src/handlers/commands/APPLICATION_COMMAND_CREATE.ts index 344bcdfd0..d60db03a9 100644 --- a/src/api/controllers/commands/APPLICATION_COMMAND_CREATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts"; export function handleApplicationCommandCreate( data: DiscordPayload, diff --git a/src/api/controllers/commands/APPLICATION_COMMAND_DELETE.ts b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts similarity index 69% rename from src/api/controllers/commands/APPLICATION_COMMAND_DELETE.ts rename to src/handlers/commands/APPLICATION_COMMAND_DELETE.ts index e85069148..6636003e1 100644 --- a/src/api/controllers/commands/APPLICATION_COMMAND_DELETE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts"; export function handleApplicationCommandDelete(data: DiscordPayload) { const { diff --git a/src/api/controllers/commands/APPLICATION_COMMAND_UPDATE.ts b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts similarity index 69% rename from src/api/controllers/commands/APPLICATION_COMMAND_UPDATE.ts rename to src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts index c1bf97ba0..5ac3fbde3 100644 --- a/src/api/controllers/commands/APPLICATION_COMMAND_UPDATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts"; export function handleApplicationCommandUpdate(data: DiscordPayload) { const { diff --git a/src/api/controllers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts similarity index 65% rename from src/api/controllers/guilds/GUILD_BAN_ADD.ts rename to src/handlers/guilds/GUILD_BAN_ADD.ts index ab3b00119..4b77fa613 100644 --- a/src/api/controllers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildBanAdd(data: DiscordPayload) { const payload = data.d as GuildBanPayload; diff --git a/src/api/controllers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts similarity index 66% rename from src/api/controllers/guilds/GUILD_BAN_REMOVE.ts rename to src/handlers/guilds/GUILD_BAN_REMOVE.ts index 4f4c0c25f..740791baf 100644 --- a/src/api/controllers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildBanRemove(data: DiscordPayload) { const payload = data.d as GuildBanPayload; diff --git a/src/api/controllers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts similarity index 74% rename from src/api/controllers/guilds/GUILD_CREATE.ts rename to src/handlers/guilds/GUILD_CREATE.ts index 56b9a4455..302d42e48 100644 --- a/src/api/controllers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -1,9 +1,9 @@ -import { eventHandlers } from "../../../bot.ts"; -import { CreateGuildPayload, DiscordPayload } from "../../../types/mod.ts"; -import { cache } from "../../../util/cache.ts"; -import { basicShards } from "../../../ws/shard.ts"; +import { eventHandlers } from "../../bot.ts"; +import { CreateGuildPayload, DiscordPayload } from "../../types/mod.ts"; +import { cache } from "../../util/cache.ts"; +import { basicShards } from "../../ws/shard.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildCreate( data: DiscordPayload, diff --git a/src/api/controllers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts similarity index 83% rename from src/api/controllers/guilds/GUILD_DELETE.ts rename to src/handlers/guilds/GUILD_DELETE.ts index 6cdcc06f4..1c5d5ed94 100644 --- a/src/api/controllers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildDeletePayload } from "../../../types/mod.ts"; -import { basicShards } from "../../../ws/shard.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildDeletePayload } from "../../types/mod.ts"; +import { basicShards } from "../../ws/shard.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildDelete( data: DiscordPayload, diff --git a/src/api/controllers/guilds/GUILD_EMOJIS_UPDATE.ts b/src/handlers/guilds/GUILD_EMOJIS_UPDATE.ts similarity index 67% rename from src/api/controllers/guilds/GUILD_EMOJIS_UPDATE.ts rename to src/handlers/guilds/GUILD_EMOJIS_UPDATE.ts index 111c6f7e0..9b6527cc6 100644 --- a/src/api/controllers/guilds/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_EMOJIS_UPDATE.ts @@ -1,10 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { - DiscordPayload, - GuildEmojisUpdatePayload, -} from "../../../types/mod.ts"; -import { Collection } from "../../../util/collection.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildEmojisUpdatePayload } from "../../types/mod.ts"; +import { Collection } from "../../util/collection.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildEmojisUpdate(data: DiscordPayload) { const payload = data.d as GuildEmojisUpdatePayload; diff --git a/src/api/controllers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts similarity index 73% rename from src/api/controllers/guilds/GUILD_INTEGRATIONS_UPDATE.ts rename to src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 17568a2ff..560b64de9 100644 --- a/src/api/controllers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,9 +1,9 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordGuildIntegrationsUpdateEvent, DiscordPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildIntegrationsUpdate( data: DiscordPayload, diff --git a/src/api/controllers/guilds/GUILD_MEMBERS_CHUNK.ts b/src/handlers/guilds/GUILD_MEMBERS_CHUNK.ts similarity index 83% rename from src/api/controllers/guilds/GUILD_MEMBERS_CHUNK.ts rename to src/handlers/guilds/GUILD_MEMBERS_CHUNK.ts index e4d985302..bb2bf8702 100644 --- a/src/api/controllers/guilds/GUILD_MEMBERS_CHUNK.ts +++ b/src/handlers/guilds/GUILD_MEMBERS_CHUNK.ts @@ -1,8 +1,8 @@ -import { DiscordPayload, GuildMemberChunkPayload } from "../../../types/mod.ts"; -import { cache } from "../../../util/cache.ts"; -import { Collection } from "../../../util/collection.ts"; +import { DiscordPayload, GuildMemberChunkPayload } from "../../types/mod.ts"; +import { cache } from "../../util/cache.ts"; +import { Collection } from "../../util/collection.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildMembersChunk(data: DiscordPayload) { const payload = data.d as GuildMemberChunkPayload; diff --git a/src/api/controllers/guilds/GUILD_MEMBER_ADD.ts b/src/handlers/guilds/GUILD_MEMBER_ADD.ts similarity index 74% rename from src/api/controllers/guilds/GUILD_MEMBER_ADD.ts rename to src/handlers/guilds/GUILD_MEMBER_ADD.ts index 4d0391a2f..c90f564e5 100644 --- a/src/api/controllers/guilds/GUILD_MEMBER_ADD.ts +++ b/src/handlers/guilds/GUILD_MEMBER_ADD.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildMemberAddPayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildMemberAddPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildMemberAdd(data: DiscordPayload) { const payload = data.d as GuildMemberAddPayload; diff --git a/src/api/controllers/guilds/GUILD_MEMBER_REMOVE.ts b/src/handlers/guilds/GUILD_MEMBER_REMOVE.ts similarity index 74% rename from src/api/controllers/guilds/GUILD_MEMBER_REMOVE.ts rename to src/handlers/guilds/GUILD_MEMBER_REMOVE.ts index c48757c47..8c5703257 100644 --- a/src/api/controllers/guilds/GUILD_MEMBER_REMOVE.ts +++ b/src/handlers/guilds/GUILD_MEMBER_REMOVE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildMemberRemove(data: DiscordPayload) { const payload = data.d as GuildBanPayload; diff --git a/src/api/controllers/guilds/GUILD_MEMBER_UPDATE.ts b/src/handlers/guilds/GUILD_MEMBER_UPDATE.ts similarity index 89% rename from src/api/controllers/guilds/GUILD_MEMBER_UPDATE.ts rename to src/handlers/guilds/GUILD_MEMBER_UPDATE.ts index b1d74fbb0..d63cb42ab 100644 --- a/src/api/controllers/guilds/GUILD_MEMBER_UPDATE.ts +++ b/src/handlers/guilds/GUILD_MEMBER_UPDATE.ts @@ -1,10 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { - DiscordPayload, - GuildMemberUpdatePayload, -} from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildMemberUpdatePayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildMemberUpdate(data: DiscordPayload) { const payload = data.d as GuildMemberUpdatePayload; diff --git a/src/api/controllers/guilds/GUILD_ROLE_CREATE.ts b/src/handlers/guilds/GUILD_ROLE_CREATE.ts similarity index 80% rename from src/api/controllers/guilds/GUILD_ROLE_CREATE.ts rename to src/handlers/guilds/GUILD_ROLE_CREATE.ts index a75ea4bf9..9277f1001 100644 --- a/src/api/controllers/guilds/GUILD_ROLE_CREATE.ts +++ b/src/handlers/guilds/GUILD_ROLE_CREATE.ts @@ -1,11 +1,11 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, GuildRoleDeletePayload, GuildRolePayload, -} from "../../../types/mod.ts"; +} from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildRoleCreate(data: DiscordPayload) { const payload = data.d as GuildRolePayload; diff --git a/src/api/controllers/guilds/GUILD_ROLE_DELETE.ts b/src/handlers/guilds/GUILD_ROLE_DELETE.ts similarity index 83% rename from src/api/controllers/guilds/GUILD_ROLE_DELETE.ts rename to src/handlers/guilds/GUILD_ROLE_DELETE.ts index bca2d5ba9..907abb0b2 100644 --- a/src/api/controllers/guilds/GUILD_ROLE_DELETE.ts +++ b/src/handlers/guilds/GUILD_ROLE_DELETE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, GuildRoleDeletePayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, GuildRoleDeletePayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildRoleDelete(data: DiscordPayload) { const payload = data.d as GuildRoleDeletePayload; diff --git a/src/api/controllers/guilds/GUILD_ROLE_UPDATE.ts b/src/handlers/guilds/GUILD_ROLE_UPDATE.ts similarity index 82% rename from src/api/controllers/guilds/GUILD_ROLE_UPDATE.ts rename to src/handlers/guilds/GUILD_ROLE_UPDATE.ts index d341d910c..7a9151b23 100644 --- a/src/api/controllers/guilds/GUILD_ROLE_UPDATE.ts +++ b/src/handlers/guilds/GUILD_ROLE_UPDATE.ts @@ -1,11 +1,11 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, GuildRoleDeletePayload, GuildRolePayload, -} from "../../../types/mod.ts"; +} from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildRoleUpdate(data: DiscordPayload) { const payload = data.d as GuildRolePayload; diff --git a/src/api/controllers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts similarity index 91% rename from src/api/controllers/guilds/GUILD_UPDATE.ts rename to src/handlers/guilds/GUILD_UPDATE.ts index 0d890e969..c35dcdfa6 100644 --- a/src/api/controllers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -1,10 +1,10 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, GuildUpdateChange, UpdateGuildPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleGuildUpdate(data: DiscordPayload) { const payload = data.d as UpdateGuildPayload; diff --git a/src/api/controllers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts similarity index 88% rename from src/api/controllers/integrations/INTEGRATION_CREATE.ts rename to src/handlers/integrations/INTEGRATION_CREATE.ts index a9441f266..7987653fd 100644 --- a/src/api/controllers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,8 +1,8 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, IntegrationCreateUpdateEvent, -} from "../../../types/mod.ts"; +} from "../../types/mod.ts"; export function handleIntegrationCreate( data: DiscordPayload, diff --git a/src/api/controllers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts similarity index 68% rename from src/api/controllers/integrations/INTEGRATION_DELETE.ts rename to src/handlers/integrations/INTEGRATION_DELETE.ts index dee2349b3..6b5d0fc74 100644 --- a/src/api/controllers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, IntegrationDeleteEvent } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, IntegrationDeleteEvent } from "../../types/mod.ts"; export function handleIntegrationDelete(data: DiscordPayload) { const { diff --git a/src/api/controllers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts similarity index 88% rename from src/api/controllers/integrations/INTEGRATION_UPDATE.ts rename to src/handlers/integrations/INTEGRATION_UPDATE.ts index 8976a62df..896088c17 100644 --- a/src/api/controllers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,8 +1,8 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, IntegrationCreateUpdateEvent, -} from "../../../types/mod.ts"; +} from "../../types/mod.ts"; export function handleIntegrationUpdate(data: DiscordPayload) { const { diff --git a/src/api/controllers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts similarity index 70% rename from src/api/controllers/interactions/INTERACTION_CREATE.ts rename to src/handlers/interactions/INTERACTION_CREATE.ts index fd303bf3c..ffdd6bc45 100644 --- a/src/api/controllers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -1,10 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { - DiscordPayload, - InteractionCommandPayload, -} from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, InteractionCommandPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleInteractionCreate(data: DiscordPayload) { const payload = data.d as InteractionCommandPayload; diff --git a/src/api/controllers/invites/INVITE_CREATE.ts b/src/handlers/invites/INVITE_CREATE.ts similarity index 81% rename from src/api/controllers/invites/INVITE_CREATE.ts rename to src/handlers/invites/INVITE_CREATE.ts index 5a788fff7..1b343bffa 100644 --- a/src/api/controllers/invites/INVITE_CREATE.ts +++ b/src/handlers/invites/INVITE_CREATE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, InviteCreateEvent } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, InviteCreateEvent } from "../../types/mod.ts"; export function handleInviteCreate(payload: DiscordPayload) { if (payload.t !== "INVITE_CREATE") return; diff --git a/src/api/controllers/invites/INVITE_DELETE.ts b/src/handlers/invites/INVITE_DELETE.ts similarity index 70% rename from src/api/controllers/invites/INVITE_DELETE.ts rename to src/handlers/invites/INVITE_DELETE.ts index d69a2f1d2..737fd9255 100644 --- a/src/api/controllers/invites/INVITE_DELETE.ts +++ b/src/handlers/invites/INVITE_DELETE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, InviteDeleteEvent } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, InviteDeleteEvent } from "../../types/mod.ts"; export function handleInviteDelete(payload: DiscordPayload) { if (payload.t !== "INVITE_DELETE") return; diff --git a/src/api/controllers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts similarity index 87% rename from src/api/controllers/messages/MESSAGE_CREATE.ts rename to src/handlers/messages/MESSAGE_CREATE.ts index 2e2523a8e..30337662e 100644 --- a/src/api/controllers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageCreateOptions } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageCreate(data: DiscordPayload) { const payload = data.d as MessageCreateOptions; diff --git a/src/api/controllers/messages/MESSAGE_DELETE.ts b/src/handlers/messages/MESSAGE_DELETE.ts similarity index 69% rename from src/api/controllers/messages/MESSAGE_DELETE.ts rename to src/handlers/messages/MESSAGE_DELETE.ts index 9e7a67ee8..43a44a14a 100644 --- a/src/api/controllers/messages/MESSAGE_DELETE.ts +++ b/src/handlers/messages/MESSAGE_DELETE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, MessageDeletePayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageDeletePayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageDelete(data: DiscordPayload) { const payload = data.d as MessageDeletePayload; diff --git a/src/api/controllers/messages/MESSAGE_DELETE_BULK.ts b/src/handlers/messages/MESSAGE_DELETE_BULK.ts similarity index 70% rename from src/api/controllers/messages/MESSAGE_DELETE_BULK.ts rename to src/handlers/messages/MESSAGE_DELETE_BULK.ts index 0173cee53..ddb227ce1 100644 --- a/src/api/controllers/messages/MESSAGE_DELETE_BULK.ts +++ b/src/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -1,9 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { - DiscordPayload, - MessageDeleteBulkPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageDeleteBulkPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageDeleteBulk(data: DiscordPayload) { const payload = data.d as MessageDeleteBulkPayload; diff --git a/src/api/controllers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts similarity index 88% rename from src/api/controllers/messages/MESSAGE_REACTION_ADD.ts rename to src/handlers/messages/MESSAGE_REACTION_ADD.ts index b4718cd99..e2cfc56c6 100644 --- a/src/api/controllers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -1,7 +1,7 @@ -import { botID, eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts"; +import { botID, eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageReactionPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageReactionAdd(data: DiscordPayload) { const payload = data.d as MessageReactionPayload; diff --git a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts similarity index 88% rename from src/api/controllers/messages/MESSAGE_REACTION_REMOVE.ts rename to src/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 877b6df4f..e0e77ec55 100644 --- a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -1,7 +1,7 @@ -import { botID, eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts"; +import { botID, eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageReactionPayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageReactionRemove( data: DiscordPayload, diff --git a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts similarity index 69% rename from src/api/controllers/messages/MESSAGE_REACTION_REMOVE_ALL.ts rename to src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index 419c6a777..8209abefe 100644 --- a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -1,9 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { - BaseMessageReactionPayload, - DiscordPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { BaseMessageReactionPayload, DiscordPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageReactionRemoveAll( data: DiscordPayload, diff --git a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts similarity index 83% rename from src/api/controllers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts rename to src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index 165f6124d..87c9bec21 100644 --- a/src/api/controllers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -1,9 +1,9 @@ -import { botID, eventHandlers } from "../../../bot.ts"; +import { botID, eventHandlers } from "../../bot.ts"; import { DiscordPayload, MessageReactionRemoveEmojiPayload, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageReactionRemoveEmoji( data: DiscordPayload, diff --git a/src/api/controllers/messages/MESSAGE_UPDATE.ts b/src/handlers/messages/MESSAGE_UPDATE.ts similarity index 84% rename from src/api/controllers/messages/MESSAGE_UPDATE.ts rename to src/handlers/messages/MESSAGE_UPDATE.ts index 69815874f..e4fc8e02c 100644 --- a/src/api/controllers/messages/MESSAGE_UPDATE.ts +++ b/src/handlers/messages/MESSAGE_UPDATE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, MessageCreateOptions } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleMessageUpdate(data: DiscordPayload) { const payload = data.d as MessageCreateOptions; diff --git a/src/api/controllers/mod.ts b/src/handlers/mod.ts similarity index 96% rename from src/api/controllers/mod.ts rename to src/handlers/mod.ts index 239888d42..dc21954f7 100644 --- a/src/api/controllers/mod.ts +++ b/src/handlers/mod.ts @@ -84,7 +84,7 @@ export { handleWebhooksUpdate, }; -export let controllers = { +export let handlers = { READY: handleReady, // channels CHANNEL_CREATE: handleChannelCreate, @@ -139,11 +139,11 @@ export let controllers = { INTEGRATION_DELETE: handleIntegrationDelete, }; -export type Controllers = typeof controllers; +export type Handlers = typeof handlers; -export function updateControllers(newControllers: Controllers) { - controllers = { - ...controllers, - ...newControllers, +export function updateHandlers(newHandlers: Handlers) { + handlers = { + ...handlers, + ...newHandlers, }; } diff --git a/src/api/controllers/presence/PRESENCE_UPDATE.ts b/src/handlers/presence/PRESENCE_UPDATE.ts similarity index 64% rename from src/api/controllers/presence/PRESENCE_UPDATE.ts rename to src/handlers/presence/PRESENCE_UPDATE.ts index 4c1920c62..4e202e6ec 100644 --- a/src/api/controllers/presence/PRESENCE_UPDATE.ts +++ b/src/handlers/presence/PRESENCE_UPDATE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, PresenceUpdatePayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, PresenceUpdatePayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handlePresenceUpdate(data: DiscordPayload) { const payload = data.d as PresenceUpdatePayload; diff --git a/src/handlers/presence/TYPING_START.ts b/src/handlers/presence/TYPING_START.ts new file mode 100644 index 000000000..308c88439 --- /dev/null +++ b/src/handlers/presence/TYPING_START.ts @@ -0,0 +1,6 @@ +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, TypingStartPayload } from "../../types/mod.ts"; + +export function handleTypingStart(data: DiscordPayload) { + eventHandlers.typingStart?.(data.d as TypingStartPayload); +} diff --git a/src/api/controllers/presence/USER_UPDATE.ts b/src/handlers/presence/USER_UPDATE.ts similarity index 72% rename from src/api/controllers/presence/USER_UPDATE.ts rename to src/handlers/presence/USER_UPDATE.ts index e1d20ddb8..aade4ffcb 100644 --- a/src/api/controllers/presence/USER_UPDATE.ts +++ b/src/handlers/presence/USER_UPDATE.ts @@ -1,6 +1,6 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, UserPayload } from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, UserPayload } from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleUserUpdate(data: DiscordPayload) { const userData = data.d as UserPayload; diff --git a/src/api/controllers/voice/VOICE_SERVER_UPDATE.ts b/src/handlers/voice/VOICE_SERVER_UPDATE.ts similarity index 73% rename from src/api/controllers/voice/VOICE_SERVER_UPDATE.ts rename to src/handlers/voice/VOICE_SERVER_UPDATE.ts index 3f33680a6..5da4ee508 100644 --- a/src/api/controllers/voice/VOICE_SERVER_UPDATE.ts +++ b/src/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -1,9 +1,9 @@ -import { eventHandlers } from "../../../bot.ts"; +import { eventHandlers } from "../../bot.ts"; import { DiscordPayload, DiscordVoiceServerUpdateEvent, -} from "../../../types/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +} from "../../types/mod.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleVoiceServerUpdate(data: DiscordPayload) { const payload = data.d as DiscordVoiceServerUpdateEvent; diff --git a/src/api/controllers/voice/VOICE_STATE_UPDATE.ts b/src/handlers/voice/VOICE_STATE_UPDATE.ts similarity index 90% rename from src/api/controllers/voice/VOICE_STATE_UPDATE.ts rename to src/handlers/voice/VOICE_STATE_UPDATE.ts index 6464d1dea..277285ee4 100644 --- a/src/api/controllers/voice/VOICE_STATE_UPDATE.ts +++ b/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -1,7 +1,7 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, VoiceStateUpdatePayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, VoiceStateUpdatePayload } from "../../types/mod.ts"; import { structures } from "../../structures/mod.ts"; -import { cacheHandlers } from "../../../cache.ts"; +import { cacheHandlers } from "../../cache.ts"; export async function handleVoiceStateUpdate(data: DiscordPayload) { const payload = data.d as VoiceStateUpdatePayload; diff --git a/src/api/controllers/webhooks/WEBHOOKS_UPDATE.ts b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts similarity index 61% rename from src/api/controllers/webhooks/WEBHOOKS_UPDATE.ts rename to src/handlers/webhooks/WEBHOOKS_UPDATE.ts index 303995f88..987683b9b 100644 --- a/src/api/controllers/webhooks/WEBHOOKS_UPDATE.ts +++ b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,5 +1,5 @@ -import { eventHandlers } from "../../../bot.ts"; -import { DiscordPayload, WebhookUpdatePayload } from "../../../types/mod.ts"; +import { eventHandlers } from "../../bot.ts"; +import { DiscordPayload, WebhookUpdatePayload } from "../../types/mod.ts"; export function handleWebhooksUpdate(data: DiscordPayload) { const options = data.d as WebhookUpdatePayload; diff --git a/src/api/handlers/channel.ts b/src/helpers/channel.ts similarity index 98% rename from src/api/handlers/channel.ts rename to src/helpers/channel.ts index 54f4c02d4..b8085ba0b 100644 --- a/src/api/handlers/channel.ts +++ b/src/helpers/channel.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { RequestManager } from "../rest/request_manager.ts"; import { ChannelEditOptions, ChannelTypes, @@ -16,14 +16,14 @@ import { Permissions, RawOverwrite, WebhookPayload, -} from "../../types/mod.ts"; -import { endpoints } from "../../util/constants.ts"; +} from "../types/mod.ts"; +import { endpoints } from "../util/constants.ts"; import { botHasChannelPermissions, botHasPermission, calculateBits, -} from "../../util/permissions.ts"; -import { cacheHandlers } from "../../cache.ts"; +} from "../util/permissions.ts"; +import { cacheHandlers } from "../cache.ts"; import { structures } from "../structures/mod.ts"; /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ diff --git a/src/api/handlers/gateway.ts b/src/helpers/gateway.ts similarity index 59% rename from src/api/handlers/gateway.ts rename to src/helpers/gateway.ts index 406946fe0..d30d42f18 100644 --- a/src/api/handlers/gateway.ts +++ b/src/helpers/gateway.ts @@ -1,6 +1,6 @@ -import { RequestManager } from "../../rest/request_manager.ts"; -import { DiscordBotGatewayData } from "../../types/mod.ts"; -import { endpoints } from "../../util/constants.ts"; +import { RequestManager } from "../rest/request_manager.ts"; +import { DiscordBotGatewayData } from "../types/mod.ts"; +import { endpoints } from "../util/constants.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ export async function getGatewayBot() { diff --git a/src/api/handlers/guild.ts b/src/helpers/guild.ts similarity index 98% rename from src/api/handlers/guild.ts rename to src/helpers/guild.ts index 5d0f955f9..a16802c3e 100644 --- a/src/api/handlers/guild.ts +++ b/src/helpers/guild.ts @@ -1,5 +1,5 @@ -import { identifyPayload } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { identifyPayload } from "../bot.ts"; +import { RequestManager } from "../rest/request_manager.ts"; import { AuditLogs, BannedUser, @@ -34,17 +34,17 @@ import { RoleData, UpdateGuildPayload, UserPayload, -} from "../../types/mod.ts"; -import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; -import { botHasPermission, calculateBits } from "../../util/permissions.ts"; +} from "../types/mod.ts"; +import { Collection } from "../util/collection.ts"; +import { endpoints } from "../util/constants.ts"; +import { botHasPermission, calculateBits } from "../util/permissions.ts"; import { camelKeysToSnakeCase, formatImageURL, urlToBase64, -} from "../../util/utils.ts"; -import { requestAllMembers } from "../../ws/shard_manager.ts"; -import { cacheHandlers } from "../../cache.ts"; +} from "../util/utils.ts"; +import { requestAllMembers } from "../ws/shard_manager.ts"; +import { cacheHandlers } from "../cache.ts"; import { Guild, Member, structures } from "../structures/mod.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ diff --git a/src/api/handlers/member.ts b/src/helpers/member.ts similarity index 95% rename from src/api/handlers/member.ts rename to src/helpers/member.ts index 78d978172..519be0790 100644 --- a/src/api/handlers/member.ts +++ b/src/helpers/member.ts @@ -1,5 +1,5 @@ -import { botID } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { botID } from "../bot.ts"; +import { RequestManager } from "../rest/request_manager.ts"; import { ChannelCreatePayload, DMChannelCreatePayload, @@ -9,15 +9,15 @@ import { ImageSize, MemberCreatePayload, MessageContent, -} from "../../types/mod.ts"; -import { endpoints } from "../../util/constants.ts"; +} from "../types/mod.ts"; +import { endpoints } from "../util/constants.ts"; import { botHasPermission, higherRolePosition, highestRole, -} from "../../util/permissions.ts"; -import { formatImageURL, urlToBase64 } from "../../util/utils.ts"; -import { cacheHandlers } from "../../cache.ts"; +} from "../util/permissions.ts"; +import { formatImageURL, urlToBase64 } from "../util/utils.ts"; +import { cacheHandlers } from "../cache.ts"; import { Member, structures } from "../structures/mod.ts"; import { sendMessage } from "./channel.ts"; diff --git a/src/api/handlers/message.ts b/src/helpers/message.ts similarity index 95% rename from src/api/handlers/message.ts rename to src/helpers/message.ts index 617d44ffd..f6b98bc8d 100644 --- a/src/api/handlers/message.ts +++ b/src/helpers/message.ts @@ -1,17 +1,17 @@ -import { botID } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { botID } from "../bot.ts"; +import { RequestManager } from "../rest/request_manager.ts"; import { DiscordGetReactionsParams, Errors, MessageContent, MessageCreateOptions, UserPayload, -} from "../../types/mod.ts"; -import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; -import { botHasChannelPermissions } from "../../util/permissions.ts"; -import { delay } from "../../util/utils.ts"; -import { cacheHandlers } from "../../cache.ts"; +} from "../types/mod.ts"; +import { Collection } from "../util/collection.ts"; +import { endpoints } from "../util/constants.ts"; +import { botHasChannelPermissions } from "../util/permissions.ts"; +import { delay } from "../util/utils.ts"; +import { cacheHandlers } from "../cache.ts"; import { Message, structures } from "../structures/mod.ts"; /** Delete a message with the channel id and message id only. */ diff --git a/src/api/handlers/mod.ts b/src/helpers/mod.ts similarity index 96% rename from src/api/handlers/mod.ts rename to src/helpers/mod.ts index 71b569052..490cea781 100644 --- a/src/api/handlers/mod.ts +++ b/src/helpers/mod.ts @@ -126,7 +126,7 @@ import { upsertSlashCommands, } from "./webhook.ts"; -export let handlers = { +export let helpers = { // Channel handler channelOverwriteHasPermission, createInvite, @@ -259,11 +259,11 @@ export let handlers = { getApplicationInformation, }; -export type Handlers = typeof handlers; +export type Helpers = typeof helpers; -export function updateHandlers(newHandlers: Partial) { - handlers = { - ...handlers, - ...newHandlers, +export function updateHelpers(newHelpers: Partial) { + helpers = { + ...helpers, + ...newHelpers, }; } diff --git a/src/api/handlers/oauth.ts b/src/helpers/oauth.ts similarity index 58% rename from src/api/handlers/oauth.ts rename to src/helpers/oauth.ts index 2fed36909..16da2d522 100644 --- a/src/api/handlers/oauth.ts +++ b/src/helpers/oauth.ts @@ -1,6 +1,6 @@ -import { RequestManager } from "../../rest/request_manager.ts"; -import { OAuthApplication } from "../../types/oauth.ts"; -import { endpoints } from "../../util/constants.ts"; +import { RequestManager } from "../rest/request_manager.ts"; +import { OAuthApplication } from "../types/oauth.ts"; +import { endpoints } from "../util/constants.ts"; /** Returns the bot's OAuth2 application object without `flags`. */ export async function getApplicationInformation() { diff --git a/src/api/handlers/webhook.ts b/src/helpers/webhook.ts similarity index 97% rename from src/api/handlers/webhook.ts rename to src/helpers/webhook.ts index 235d12749..c5da8a565 100644 --- a/src/api/handlers/webhook.ts +++ b/src/helpers/webhook.ts @@ -1,5 +1,5 @@ -import { applicationID } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { applicationID } from "../bot.ts"; +import { RequestManager } from "../rest/request_manager.ts"; import { CreateSlashCommandOptions, EditSlashCommandOptions, @@ -18,12 +18,12 @@ import { WebhookCreateOptions, WebhookEditOptions, WebhookPayload, -} from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { Collection } from "../../util/collection.ts"; -import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../../util/constants.ts"; -import { botHasChannelPermissions } from "../../util/permissions.ts"; -import { urlToBase64 } from "../../util/utils.ts"; +} from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; +import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../util/constants.ts"; +import { botHasChannelPermissions } from "../util/permissions.ts"; +import { urlToBase64 } from "../util/utils.ts"; import { structures } from "../structures/mod.ts"; /** diff --git a/src/interactions/server.ts b/src/interactions/server.ts index 9b20a517b..822b67587 100644 --- a/src/interactions/server.ts +++ b/src/interactions/server.ts @@ -12,8 +12,8 @@ const serverOptions = { port: 80, }; -/** Theses are the controllers that you can plug into and customize to your needs. */ -export const controllers = { +/** Theses are the handlers that you can plug into and customize to your needs. */ +export const handlers = { handlePayload, handleApplicationCommand, }; @@ -36,7 +36,7 @@ export async function startServer( serverOptions.publicKey = publicKey; serverOptions.port = port; if (handleApplicationCommand) { - controllers.handleApplicationCommand = handleApplicationCommand; + handlers.handleApplicationCommand = handleApplicationCommand; } const server = serve({ port: serverOptions.port }); @@ -59,7 +59,7 @@ export async function startServer( try { const data = JSON.parse(new TextDecoder().decode(buffer)); - const response = await controllers.handlePayload(data); + const response = await handlers.handlePayload(data); req.respond( { status: response.status || 200, body: JSON.stringify(response.body) }, ); @@ -74,7 +74,7 @@ function handlePayload(payload: Interaction) { case InteractionType.PING: return { status: 200, body: { type: InteractionResponseType.PONG } }; default: // APPLICATION_COMMAND - return controllers.handleApplicationCommand(payload); + return handlers.handleApplicationCommand(payload); } } diff --git a/src/api/structures/channel.ts b/src/structures/channel.ts similarity index 95% rename from src/api/structures/channel.ts rename to src/structures/channel.ts index 35eeb9c53..ded06d205 100644 --- a/src/api/structures/channel.ts +++ b/src/structures/channel.ts @@ -6,21 +6,21 @@ import { Overwrite, Permission, RawOverwrite, -} from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { Collection } from "../../util/collection.ts"; -import { createNewProp } from "../../util/utils.ts"; +} from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; +import { createNewProp } from "../util/utils.ts"; import { channelOverwriteHasPermission, editChannel, sendMessage, -} from "../handlers/channel.ts"; +} from "../helpers/channel.ts"; import { deleteChannel, deleteChannelOverwrite, editChannelOverwrite, -} from "../handlers/guild.ts"; -import { kickFromVoiceChannel } from "../handlers/member.ts"; +} from "../helpers/guild.ts"; +import { kickFromVoiceChannel } from "../helpers/member.ts"; import { CleanVoiceState, Guild } from "./guild.ts"; import { Member } from "./member.ts"; import { Message } from "./message.ts"; diff --git a/src/api/structures/guild.ts b/src/structures/guild.ts similarity index 97% rename from src/api/structures/guild.ts rename to src/structures/guild.ts index 6b3fbefd3..a5a56351d 100644 --- a/src/api/structures/guild.ts +++ b/src/structures/guild.ts @@ -1,4 +1,4 @@ -import { botID } from "../../bot.ts"; +import { botID } from "../bot.ts"; import { BanOptions, CreateGuildPayload, @@ -12,11 +12,11 @@ import { MemberCreatePayload, Presence, VoiceState, -} from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { Collection } from "../../util/collection.ts"; -import { createNewProp } from "../../util/utils.ts"; -import { cacheHandlers } from "../../cache.ts"; +} from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; +import { createNewProp } from "../util/utils.ts"; +import { cacheHandlers } from "../cache.ts"; import { ban, deleteServer, @@ -29,7 +29,7 @@ import { guildIconURL, leaveGuild, unban, -} from "../handlers/guild.ts"; +} from "../helpers/guild.ts"; import { Member } from "./member.ts"; import { Channel, Role, structures } from "./mod.ts"; diff --git a/src/api/structures/member.ts b/src/structures/member.ts similarity index 94% rename from src/api/structures/member.ts rename to src/structures/member.ts index 87e4072ec..2103a88b3 100644 --- a/src/api/structures/member.ts +++ b/src/structures/member.ts @@ -6,12 +6,12 @@ import { ImageSize, MemberCreatePayload, MessageContent, -} from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { Collection } from "../../util/collection.ts"; -import { createNewProp } from "../../util/utils.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { ban } from "../handlers/guild.ts"; +} from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; +import { createNewProp } from "../util/utils.ts"; +import { cacheHandlers } from "../cache.ts"; +import { ban } from "../helpers/guild.ts"; import { addRole, editMember, @@ -19,7 +19,7 @@ import { rawAvatarURL, removeRole, sendDirectMessage, -} from "../handlers/member.ts"; +} from "../helpers/member.ts"; import { Guild } from "./guild.ts"; const baseMember: Partial = { diff --git a/src/api/structures/message.ts b/src/structures/message.ts similarity index 96% rename from src/api/structures/message.ts rename to src/structures/message.ts index bdacc3ea4..316787ce1 100644 --- a/src/api/structures/message.ts +++ b/src/structures/message.ts @@ -11,12 +11,12 @@ import { Reaction, Reference, UserPayload, -} from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { createNewProp } from "../../util/utils.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { sendMessage } from "../handlers/channel.ts"; -import { sendDirectMessage } from "../handlers/member.ts"; +} from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { createNewProp } from "../util/utils.ts"; +import { cacheHandlers } from "../cache.ts"; +import { sendMessage } from "../helpers/channel.ts"; +import { sendDirectMessage } from "../helpers/member.ts"; import { addReaction, addReactions, @@ -26,7 +26,7 @@ import { removeAllReactions, removeReaction, removeReactionEmoji, -} from "../handlers/message.ts"; +} from "../helpers/message.ts"; import { Channel } from "./channel.ts"; import { Guild } from "./guild.ts"; import { Member } from "./member.ts"; diff --git a/src/api/structures/mod.ts b/src/structures/mod.ts similarity index 100% rename from src/api/structures/mod.ts rename to src/structures/mod.ts diff --git a/src/api/structures/role.ts b/src/structures/role.ts similarity index 93% rename from src/api/structures/role.ts rename to src/structures/role.ts index 1b2282cdb..2ede4c077 100644 --- a/src/api/structures/role.ts +++ b/src/structures/role.ts @@ -1,8 +1,8 @@ -import { CreateRoleOptions, RoleData } from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { Collection } from "../../util/collection.ts"; -import { createNewProp } from "../../util/utils.ts"; -import { deleteRole, editRole } from "../handlers/guild.ts"; +import { CreateRoleOptions, RoleData } from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; +import { createNewProp } from "../util/utils.ts"; +import { deleteRole, editRole } from "../helpers/guild.ts"; import { Guild } from "./guild.ts"; import { Member } from "./member.ts"; diff --git a/src/api/structures/template.ts b/src/structures/template.ts similarity index 92% rename from src/api/structures/template.ts rename to src/structures/template.ts index 79b45d38e..dafb1e5e7 100644 --- a/src/api/structures/template.ts +++ b/src/structures/template.ts @@ -1,6 +1,6 @@ -import { GuildTemplate, UserPayload } from "../../types/mod.ts"; -import { cache } from "../../util/cache.ts"; -import { createNewProp } from "../../util/utils.ts"; +import { GuildTemplate, UserPayload } from "../types/mod.ts"; +import { cache } from "../util/cache.ts"; +import { createNewProp } from "../util/utils.ts"; import { Guild } from "./guild.ts"; const baseTemplate: Partial