refactor: rename controllers to handlers and handlers to helpers (#660)

* refactor: rename controllers to handlers and handlers to helpers

* fmt
This commit is contained in:
ayntee
2021-03-11 21:41:03 +04:00
committed by GitHub
parent aaed064709
commit 8654aeded5
72 changed files with 271 additions and 296 deletions
+4 -2
View File
@@ -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:
+17 -23
View File
@@ -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<String, number>();
@@ -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!
+13 -13
View File
@@ -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";
@@ -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);
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { getGatewayBot } from "./api/handlers/gateway.ts";
import { getGatewayBot } from "./helpers/gateway.ts";
import {
BotConfig,
DiscordBotGatewayData,
+1 -1
View File
@@ -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"
@@ -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,
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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,
@@ -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 {
@@ -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 {
@@ -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;
@@ -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;
@@ -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,
@@ -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,
@@ -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;
@@ -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,
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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,
@@ -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 {
@@ -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 {
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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,
@@ -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,
@@ -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,
@@ -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;
@@ -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,
};
}
@@ -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;
+6
View File
@@ -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);
}
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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 */
@@ -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() {
@@ -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. */
@@ -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";
@@ -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. */
@@ -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 = {
...handlers,
...newHandlers,
export function updateHelpers(newHelpers: Partial<Helpers>) {
helpers = {
...helpers,
...newHelpers,
};
}
@@ -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() {
@@ -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";
/**
+5 -5
View File
@@ -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);
}
}
@@ -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";
@@ -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";
@@ -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<Member> = {
@@ -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";
@@ -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";
@@ -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<Template> = {
+1 -1
View File
@@ -1,4 +1,4 @@
import { Guild } from "../api/structures/mod.ts";
import { Guild } from "../structures/mod.ts";
import { ChannelCreatePayload, ChannelTypes } from "./channel.ts";
import { Emoji, StatusType } from "./discord.ts";
import { MemberCreatePayload } from "./member.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Guild } from "../api/structures/mod.ts";
import { Guild } from "../structures/mod.ts";
import { ChannelCreatePayload } from "./channel.ts";
import { UserPayload } from "./guild.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Channel } from "../api/structures/mod.ts";
import { Channel } from "../structures/mod.ts";
import { ChannelType } from "./channel.ts";
import { UserPayload } from "./guild.ts";
import { MemberCreatePayload } from "./member.ts";
+1 -7
View File
@@ -1,10 +1,4 @@
import {
Channel,
Guild,
Member,
Message,
Role,
} from "../api/structures/mod.ts";
import { Channel, Guild, Member, Message, Role } from "../structures/mod.ts";
import { Collection } from "../util/collection.ts";
import {
DiscordPayload,
+1 -1
View File
@@ -1,4 +1,4 @@
import { Channel, Guild, Member, Message } from "../api/structures/mod.ts";
import { Channel, Guild, Member, Message } from "../structures/mod.ts";
import { PresenceUpdatePayload } from "../types/mod.ts";
import { Collection } from "./collection.ts";
+1 -1
View File
@@ -1,5 +1,5 @@
import { cacheHandlers } from "../cache.ts";
import { Guild, Role } from "../api/structures/mod.ts";
import { Guild, Role } from "../structures/mod.ts";
import { botID } from "../bot.ts";
import { Permission, Permissions, RawOverwrite } from "../types/mod.ts";
+5 -5
View File
@@ -1,6 +1,6 @@
import { controllers } from "../api/controllers/mod.ts";
import { Guild } from "../api/structures/guild.ts";
import { Member } from "../api/structures/mod.ts";
import { handlers } from "../handlers/mod.ts";
import { Guild } from "../structures/guild.ts";
import { Member } from "../structures/mod.ts";
import { eventHandlers } from "../bot.ts";
import {
DiscordBotGatewayData,
@@ -80,8 +80,8 @@ export async function handleDiscordPayload(
return eventHandlers.heartbeat?.();
case GatewayOpcode.Dispatch:
if (!data.t) return;
// Run the appropriate controller for this event.
return controllers[data.t]?.(data, shardID);
// Run the appropriate handler for this event.
return handlers[data.t]?.(data, shardID);
default:
return;
}