mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
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:
@@ -15,9 +15,11 @@
|
|||||||
|
|
||||||
Examples of good PR title:
|
Examples of good PR title:
|
||||||
|
|
||||||
- fix(controllers/interactions): cache member from INTERACTION_CREATE payload
|
- fix(handlers/INTERACTION_CREATE): cache member object
|
||||||
- docs: improve wording
|
- 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:
|
Examples of bad PR title:
|
||||||
|
|
||||||
|
|||||||
@@ -347,10 +347,10 @@ methods on the cacheHandlers. The current list of methods available are:
|
|||||||
- set
|
- set
|
||||||
- forEach
|
- forEach
|
||||||
|
|
||||||
## Custom Gateway Payload Handling (Controllers)
|
## Custom Gateway Payload Handling (Handlers)
|
||||||
|
|
||||||
Controllers are one of the most powerful features of Discordeno. They allow you
|
Handlers are one of the most powerful features of Discordeno. They allow you to
|
||||||
to take control of how Discordeno handles the Discord payloads from the gateway.
|
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.
|
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
|
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
|
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
|
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
|
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
|
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
|
```ts
|
||||||
import {
|
import { eventHandlers, handlers, TypingStartPayload } from "../../../deps.ts";
|
||||||
controllers,
|
|
||||||
eventHandlers,
|
|
||||||
TypingStartPayload,
|
|
||||||
} from "../../../deps.ts";
|
|
||||||
|
|
||||||
const typingUsers = new Map<String, number>();
|
const typingUsers = new Map<String, number>();
|
||||||
|
|
||||||
@@ -379,7 +375,7 @@ function createTimeout(userID: String) {
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
controllers.TYPING_START = function (data) {
|
handlers.TYPING_START = function (data) {
|
||||||
const payload = data.d as TypingStartPayload;
|
const payload = data.d as TypingStartPayload;
|
||||||
eventHandlers.typingStart?.(payload);
|
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
|
This is just a basic example but it's true potential is only limited by your
|
||||||
true potential is only limited by your imagination. I would love to see what you
|
imagination. I would love to see what you all can create.
|
||||||
all can create with controllers.
|
|
||||||
|
|
||||||
Something worth noting about why Discordeno controllers are so amazing is that
|
Something worth noting about why Discordeno handlers are so amazing is that it
|
||||||
it allows you to never depend on me. When Discord releases something new, you
|
allows you to never depend on me. When Discord releases something new, you don't
|
||||||
don't need to wait for me to update the library to access it. Without
|
need to wait for me to update the library to access it. Without handlers, if you
|
||||||
controllers, if you wanted access to a feature you would need to wait for the
|
wanted access to a feature you would need to wait for the library to be updated
|
||||||
library to be updated or have to fork it, modify it and modify your code for it.
|
or have to fork it, modify it and modify your code for it. Then when the library
|
||||||
Then when the library does get updated, you need to switch back to it and modify
|
does get updated, you need to switch back to it and modify your code again
|
||||||
your code again possibly to how the lib designed it. With controllers, you never
|
possibly to how the lib designed it. With handlers, you never have to fork or
|
||||||
have to fork or anything. Just take control!
|
anything. Just take control!
|
||||||
|
|
||||||
Controllers are extremely powerful. **Remember with great power comes great
|
Remember with great power comes great bugs!
|
||||||
bugs!**
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
export * from "./src/cache.ts";
|
export * from "./src/cache.ts";
|
||||||
export * from "./src/api/handlers/channel.ts";
|
export * from "./src/helpers/channel.ts";
|
||||||
export * from "./src/api/handlers/guild.ts";
|
export * from "./src/helpers/guild.ts";
|
||||||
export * from "./src/api/handlers/member.ts";
|
export * from "./src/helpers/member.ts";
|
||||||
export * from "./src/api/handlers/message.ts";
|
export * from "./src/helpers/message.ts";
|
||||||
export * from "./src/api/handlers/oauth.ts";
|
export * from "./src/helpers/oauth.ts";
|
||||||
export * from "./src/api/handlers/webhook.ts";
|
export * from "./src/helpers/webhook.ts";
|
||||||
export * from "./src/api/structures/channel.ts";
|
export * from "./src/structures/channel.ts";
|
||||||
export * from "./src/api/structures/guild.ts";
|
export * from "./src/structures/guild.ts";
|
||||||
export * from "./src/api/structures/member.ts";
|
export * from "./src/structures/member.ts";
|
||||||
export * from "./src/api/structures/message.ts";
|
export * from "./src/structures/message.ts";
|
||||||
export * from "./src/api/structures/mod.ts";
|
export * from "./src/structures/mod.ts";
|
||||||
export * from "./src/api/structures/role.ts";
|
export * from "./src/structures/role.ts";
|
||||||
export * from "./src/bot.ts";
|
export * from "./src/bot.ts";
|
||||||
export * from "./src/rest/mod.ts";
|
export * from "./src/rest/mod.ts";
|
||||||
export * from "./src/types/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/permissions.ts";
|
||||||
export * from "./src/util/utils.ts";
|
export * from "./src/util/utils.ts";
|
||||||
export * from "./src/ws/mod.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
@@ -1,4 +1,4 @@
|
|||||||
import { getGatewayBot } from "./api/handlers/gateway.ts";
|
import { getGatewayBot } from "./helpers/gateway.ts";
|
||||||
import {
|
import {
|
||||||
BotConfig,
|
BotConfig,
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
import { PresenceUpdatePayload } from "./types/mod.ts";
|
import { PresenceUpdatePayload } from "./types/mod.ts";
|
||||||
import { cache } from "./util/cache.ts";
|
import { cache } from "./util/cache.ts";
|
||||||
import { Collection } from "./util/collection.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 =
|
export type TableName =
|
||||||
| "guilds"
|
| "guilds"
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import {
|
|||||||
lastShardID,
|
lastShardID,
|
||||||
setApplicationID,
|
setApplicationID,
|
||||||
setBotID,
|
setBotID,
|
||||||
} from "../../bot.ts";
|
} from "../bot.ts";
|
||||||
import { DiscordPayload, ReadyPayload } from "../../types/discord.ts";
|
import { DiscordPayload, ReadyPayload } from "../types/discord.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { delay } from "../../util/utils.ts";
|
import { delay } from "../util/utils.ts";
|
||||||
import { allowNextShard, basicShards } from "../../ws/mod.ts";
|
import { allowNextShard, basicShards } from "../ws/mod.ts";
|
||||||
import { initialMemberLoadQueue } from "../structures/guild.ts";
|
import { initialMemberLoadQueue } from "../structures/guild.ts";
|
||||||
import { structures } from "../structures/mod.ts";
|
import { structures } from "../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
|
|
||||||
export async function handleReady(
|
export async function handleReady(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts";
|
import { ChannelCreatePayload, DiscordPayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleChannelCreate(data: DiscordPayload) {
|
export async function handleChannelCreate(data: DiscordPayload) {
|
||||||
const payload = data.d as ChannelCreatePayload;
|
const payload = data.d as ChannelCreatePayload;
|
||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
ChannelCreatePayload,
|
ChannelCreatePayload,
|
||||||
ChannelTypes,
|
ChannelTypes,
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleChannelDelete(data: DiscordPayload) {
|
export async function handleChannelDelete(data: DiscordPayload) {
|
||||||
const payload = data.d as ChannelCreatePayload;
|
const payload = data.d as ChannelCreatePayload;
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordChannelPinsUpdateEvent,
|
DiscordChannelPinsUpdateEvent,
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleChannelPinsUpdate(data: DiscordPayload) {
|
export async function handleChannelPinsUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as DiscordChannelPinsUpdateEvent;
|
const payload = data.d as DiscordChannelPinsUpdateEvent;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts";
|
import { ChannelCreatePayload, DiscordPayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleChannelUpdate(data: DiscordPayload) {
|
export async function handleChannelUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as ChannelCreatePayload;
|
const payload = data.d as ChannelCreatePayload;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandCreate(
|
export function handleApplicationCommandCreate(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandDelete(data: DiscordPayload) {
|
export function handleApplicationCommandDelete(data: DiscordPayload) {
|
||||||
const {
|
const {
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
import { ApplicationCommandEvent, DiscordPayload } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandUpdate(data: DiscordPayload) {
|
export function handleApplicationCommandUpdate(data: DiscordPayload) {
|
||||||
const {
|
const {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildBanAdd(data: DiscordPayload) {
|
export async function handleGuildBanAdd(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildBanPayload;
|
const payload = data.d as GuildBanPayload;
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildBanRemove(data: DiscordPayload) {
|
export async function handleGuildBanRemove(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildBanPayload;
|
const payload = data.d as GuildBanPayload;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { CreateGuildPayload, DiscordPayload } from "../../../types/mod.ts";
|
import { CreateGuildPayload, DiscordPayload } from "../../types/mod.ts";
|
||||||
import { cache } from "../../../util/cache.ts";
|
import { cache } from "../../util/cache.ts";
|
||||||
import { basicShards } from "../../../ws/shard.ts";
|
import { basicShards } from "../../ws/shard.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildCreate(
|
export async function handleGuildCreate(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildDeletePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildDeletePayload } from "../../types/mod.ts";
|
||||||
import { basicShards } from "../../../ws/shard.ts";
|
import { basicShards } from "../../ws/shard.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildDelete(
|
export async function handleGuildDelete(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+4
-7
@@ -1,10 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import { DiscordPayload, GuildEmojisUpdatePayload } from "../../types/mod.ts";
|
||||||
DiscordPayload,
|
import { Collection } from "../../util/collection.ts";
|
||||||
GuildEmojisUpdatePayload,
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
} from "../../../types/mod.ts";
|
|
||||||
import { Collection } from "../../../util/collection.ts";
|
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
|
||||||
|
|
||||||
export async function handleGuildEmojisUpdate(data: DiscordPayload) {
|
export async function handleGuildEmojisUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildEmojisUpdatePayload;
|
const payload = data.d as GuildEmojisUpdatePayload;
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordGuildIntegrationsUpdateEvent,
|
DiscordGuildIntegrationsUpdateEvent,
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildIntegrationsUpdate(
|
export async function handleGuildIntegrationsUpdate(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
import { DiscordPayload, GuildMemberChunkPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildMemberChunkPayload } from "../../types/mod.ts";
|
||||||
import { cache } from "../../../util/cache.ts";
|
import { cache } from "../../util/cache.ts";
|
||||||
import { Collection } from "../../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildMembersChunk(data: DiscordPayload) {
|
export async function handleGuildMembersChunk(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildMemberChunkPayload;
|
const payload = data.d as GuildMemberChunkPayload;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildMemberAddPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildMemberAddPayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberAdd(data: DiscordPayload) {
|
export async function handleGuildMemberAdd(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildMemberAddPayload;
|
const payload = data.d as GuildMemberAddPayload;
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildBanPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberRemove(data: DiscordPayload) {
|
export async function handleGuildMemberRemove(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildBanPayload;
|
const payload = data.d as GuildBanPayload;
|
||||||
+3
-6
@@ -1,10 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import { DiscordPayload, GuildMemberUpdatePayload } from "../../types/mod.ts";
|
||||||
DiscordPayload,
|
|
||||||
GuildMemberUpdatePayload,
|
|
||||||
} from "../../../types/mod.ts";
|
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildMemberUpdate(data: DiscordPayload) {
|
export async function handleGuildMemberUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildMemberUpdatePayload;
|
const payload = data.d as GuildMemberUpdatePayload;
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
GuildRoleDeletePayload,
|
GuildRoleDeletePayload,
|
||||||
GuildRolePayload,
|
GuildRolePayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildRoleCreate(data: DiscordPayload) {
|
export async function handleGuildRoleCreate(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildRolePayload;
|
const payload = data.d as GuildRolePayload;
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, GuildRoleDeletePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, GuildRoleDeletePayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildRoleDelete(data: DiscordPayload) {
|
export async function handleGuildRoleDelete(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildRoleDeletePayload;
|
const payload = data.d as GuildRoleDeletePayload;
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
GuildRoleDeletePayload,
|
GuildRoleDeletePayload,
|
||||||
GuildRolePayload,
|
GuildRolePayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildRoleUpdate(data: DiscordPayload) {
|
export async function handleGuildRoleUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as GuildRolePayload;
|
const payload = data.d as GuildRolePayload;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
GuildUpdateChange,
|
GuildUpdateChange,
|
||||||
UpdateGuildPayload,
|
UpdateGuildPayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleGuildUpdate(data: DiscordPayload) {
|
export async function handleGuildUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as UpdateGuildPayload;
|
const payload = data.d as UpdateGuildPayload;
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
IntegrationCreateUpdateEvent,
|
IntegrationCreateUpdateEvent,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleIntegrationCreate(
|
export function handleIntegrationCreate(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, IntegrationDeleteEvent } from "../../../types/mod.ts";
|
import { DiscordPayload, IntegrationDeleteEvent } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleIntegrationDelete(data: DiscordPayload) {
|
export function handleIntegrationDelete(data: DiscordPayload) {
|
||||||
const {
|
const {
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
IntegrationCreateUpdateEvent,
|
IntegrationCreateUpdateEvent,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleIntegrationUpdate(data: DiscordPayload) {
|
export function handleIntegrationUpdate(data: DiscordPayload) {
|
||||||
const {
|
const {
|
||||||
+3
-6
@@ -1,10 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import { DiscordPayload, InteractionCommandPayload } from "../../types/mod.ts";
|
||||||
DiscordPayload,
|
|
||||||
InteractionCommandPayload,
|
|
||||||
} from "../../../types/mod.ts";
|
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleInteractionCreate(data: DiscordPayload) {
|
export async function handleInteractionCreate(data: DiscordPayload) {
|
||||||
const payload = data.d as InteractionCommandPayload;
|
const payload = data.d as InteractionCommandPayload;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, InviteCreateEvent } from "../../../types/mod.ts";
|
import { DiscordPayload, InviteCreateEvent } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleInviteCreate(payload: DiscordPayload) {
|
export function handleInviteCreate(payload: DiscordPayload) {
|
||||||
if (payload.t !== "INVITE_CREATE") return;
|
if (payload.t !== "INVITE_CREATE") return;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, InviteDeleteEvent } from "../../../types/mod.ts";
|
import { DiscordPayload, InviteDeleteEvent } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleInviteDelete(payload: DiscordPayload) {
|
export function handleInviteDelete(payload: DiscordPayload) {
|
||||||
if (payload.t !== "INVITE_DELETE") return;
|
if (payload.t !== "INVITE_DELETE") return;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts";
|
import { DiscordPayload, MessageCreateOptions } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageCreate(data: DiscordPayload) {
|
export async function handleMessageCreate(data: DiscordPayload) {
|
||||||
const payload = data.d as MessageCreateOptions;
|
const payload = data.d as MessageCreateOptions;
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, MessageDeletePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, MessageDeletePayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageDelete(data: DiscordPayload) {
|
export async function handleMessageDelete(data: DiscordPayload) {
|
||||||
const payload = data.d as MessageDeletePayload;
|
const payload = data.d as MessageDeletePayload;
|
||||||
+3
-6
@@ -1,9 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import { DiscordPayload, MessageDeleteBulkPayload } from "../../types/mod.ts";
|
||||||
DiscordPayload,
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
MessageDeleteBulkPayload,
|
|
||||||
} from "../../../types/mod.ts";
|
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
|
||||||
|
|
||||||
export async function handleMessageDeleteBulk(data: DiscordPayload) {
|
export async function handleMessageDeleteBulk(data: DiscordPayload) {
|
||||||
const payload = data.d as MessageDeleteBulkPayload;
|
const payload = data.d as MessageDeleteBulkPayload;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { botID, eventHandlers } from "../../../bot.ts";
|
import { botID, eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, MessageReactionPayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionAdd(data: DiscordPayload) {
|
export async function handleMessageReactionAdd(data: DiscordPayload) {
|
||||||
const payload = data.d as MessageReactionPayload;
|
const payload = data.d as MessageReactionPayload;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { botID, eventHandlers } from "../../../bot.ts";
|
import { botID, eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, MessageReactionPayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemove(
|
export async function handleMessageReactionRemove(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+3
-6
@@ -1,9 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import { BaseMessageReactionPayload, DiscordPayload } from "../../types/mod.ts";
|
||||||
BaseMessageReactionPayload,
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
DiscordPayload,
|
|
||||||
} from "../../../types/mod.ts";
|
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
|
||||||
|
|
||||||
export async function handleMessageReactionRemoveAll(
|
export async function handleMessageReactionRemoveAll(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
import { botID, eventHandlers } from "../../../bot.ts";
|
import { botID, eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
MessageReactionRemoveEmojiPayload,
|
MessageReactionRemoveEmojiPayload,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemoveEmoji(
|
export async function handleMessageReactionRemoveEmoji(
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts";
|
import { DiscordPayload, MessageCreateOptions } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleMessageUpdate(data: DiscordPayload) {
|
export async function handleMessageUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as MessageCreateOptions;
|
const payload = data.d as MessageCreateOptions;
|
||||||
@@ -84,7 +84,7 @@ export {
|
|||||||
handleWebhooksUpdate,
|
handleWebhooksUpdate,
|
||||||
};
|
};
|
||||||
|
|
||||||
export let controllers = {
|
export let handlers = {
|
||||||
READY: handleReady,
|
READY: handleReady,
|
||||||
// channels
|
// channels
|
||||||
CHANNEL_CREATE: handleChannelCreate,
|
CHANNEL_CREATE: handleChannelCreate,
|
||||||
@@ -139,11 +139,11 @@ export let controllers = {
|
|||||||
INTEGRATION_DELETE: handleIntegrationDelete,
|
INTEGRATION_DELETE: handleIntegrationDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Controllers = typeof controllers;
|
export type Handlers = typeof handlers;
|
||||||
|
|
||||||
export function updateControllers(newControllers: Controllers) {
|
export function updateHandlers(newHandlers: Handlers) {
|
||||||
controllers = {
|
handlers = {
|
||||||
...controllers,
|
...handlers,
|
||||||
...newControllers,
|
...newHandlers,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, PresenceUpdatePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, PresenceUpdatePayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handlePresenceUpdate(data: DiscordPayload) {
|
export async function handlePresenceUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as PresenceUpdatePayload;
|
const payload = data.d as PresenceUpdatePayload;
|
||||||
@@ -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 { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, UserPayload } from "../../../types/mod.ts";
|
import { DiscordPayload, UserPayload } from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleUserUpdate(data: DiscordPayload) {
|
export async function handleUserUpdate(data: DiscordPayload) {
|
||||||
const userData = data.d as UserPayload;
|
const userData = data.d as UserPayload;
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
DiscordVoiceServerUpdateEvent,
|
DiscordVoiceServerUpdateEvent,
|
||||||
} from "../../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleVoiceServerUpdate(data: DiscordPayload) {
|
export async function handleVoiceServerUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as DiscordVoiceServerUpdateEvent;
|
const payload = data.d as DiscordVoiceServerUpdateEvent;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, VoiceStateUpdatePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, VoiceStateUpdatePayload } from "../../types/mod.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
export async function handleVoiceStateUpdate(data: DiscordPayload) {
|
export async function handleVoiceStateUpdate(data: DiscordPayload) {
|
||||||
const payload = data.d as VoiceStateUpdatePayload;
|
const payload = data.d as VoiceStateUpdatePayload;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { eventHandlers } from "../../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordPayload, WebhookUpdatePayload } from "../../../types/mod.ts";
|
import { DiscordPayload, WebhookUpdatePayload } from "../../types/mod.ts";
|
||||||
|
|
||||||
export function handleWebhooksUpdate(data: DiscordPayload) {
|
export function handleWebhooksUpdate(data: DiscordPayload) {
|
||||||
const options = data.d as WebhookUpdatePayload;
|
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 {
|
import {
|
||||||
ChannelEditOptions,
|
ChannelEditOptions,
|
||||||
ChannelTypes,
|
ChannelTypes,
|
||||||
@@ -16,14 +16,14 @@ import {
|
|||||||
Permissions,
|
Permissions,
|
||||||
RawOverwrite,
|
RawOverwrite,
|
||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
botHasChannelPermissions,
|
botHasChannelPermissions,
|
||||||
botHasPermission,
|
botHasPermission,
|
||||||
calculateBits,
|
calculateBits,
|
||||||
} from "../../util/permissions.ts";
|
} from "../util/permissions.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { structures } from "../structures/mod.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 */
|
/** 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 { RequestManager } from "../rest/request_manager.ts";
|
||||||
import { DiscordBotGatewayData } from "../../types/mod.ts";
|
import { DiscordBotGatewayData } from "../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
|
|
||||||
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
|
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
|
||||||
export async function getGatewayBot() {
|
export async function getGatewayBot() {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { identifyPayload } from "../../bot.ts";
|
import { identifyPayload } from "../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../rest/request_manager.ts";
|
||||||
import {
|
import {
|
||||||
AuditLogs,
|
AuditLogs,
|
||||||
BannedUser,
|
BannedUser,
|
||||||
@@ -34,17 +34,17 @@ import {
|
|||||||
RoleData,
|
RoleData,
|
||||||
UpdateGuildPayload,
|
UpdateGuildPayload,
|
||||||
UserPayload,
|
UserPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
import { botHasPermission, calculateBits } from "../../util/permissions.ts";
|
import { botHasPermission, calculateBits } from "../util/permissions.ts";
|
||||||
import {
|
import {
|
||||||
camelKeysToSnakeCase,
|
camelKeysToSnakeCase,
|
||||||
formatImageURL,
|
formatImageURL,
|
||||||
urlToBase64,
|
urlToBase64,
|
||||||
} from "../../util/utils.ts";
|
} from "../util/utils.ts";
|
||||||
import { requestAllMembers } from "../../ws/shard_manager.ts";
|
import { requestAllMembers } from "../ws/shard_manager.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { Guild, Member, structures } from "../structures/mod.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. */
|
/** 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 { botID } from "../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../rest/request_manager.ts";
|
||||||
import {
|
import {
|
||||||
ChannelCreatePayload,
|
ChannelCreatePayload,
|
||||||
DMChannelCreatePayload,
|
DMChannelCreatePayload,
|
||||||
@@ -9,15 +9,15 @@ import {
|
|||||||
ImageSize,
|
ImageSize,
|
||||||
MemberCreatePayload,
|
MemberCreatePayload,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
botHasPermission,
|
botHasPermission,
|
||||||
higherRolePosition,
|
higherRolePosition,
|
||||||
highestRole,
|
highestRole,
|
||||||
} from "../../util/permissions.ts";
|
} from "../util/permissions.ts";
|
||||||
import { formatImageURL, urlToBase64 } from "../../util/utils.ts";
|
import { formatImageURL, urlToBase64 } from "../util/utils.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { Member, structures } from "../structures/mod.ts";
|
import { Member, structures } from "../structures/mod.ts";
|
||||||
import { sendMessage } from "./channel.ts";
|
import { sendMessage } from "./channel.ts";
|
||||||
|
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botID } from "../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../rest/request_manager.ts";
|
||||||
import {
|
import {
|
||||||
DiscordGetReactionsParams,
|
DiscordGetReactionsParams,
|
||||||
Errors,
|
Errors,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
MessageCreateOptions,
|
MessageCreateOptions,
|
||||||
UserPayload,
|
UserPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
import { botHasChannelPermissions } from "../util/permissions.ts";
|
||||||
import { delay } from "../../util/utils.ts";
|
import { delay } from "../util/utils.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { Message, structures } from "../structures/mod.ts";
|
import { Message, structures } from "../structures/mod.ts";
|
||||||
|
|
||||||
/** Delete a message with the channel id and message id only. */
|
/** Delete a message with the channel id and message id only. */
|
||||||
@@ -126,7 +126,7 @@ import {
|
|||||||
upsertSlashCommands,
|
upsertSlashCommands,
|
||||||
} from "./webhook.ts";
|
} from "./webhook.ts";
|
||||||
|
|
||||||
export let handlers = {
|
export let helpers = {
|
||||||
// Channel handler
|
// Channel handler
|
||||||
channelOverwriteHasPermission,
|
channelOverwriteHasPermission,
|
||||||
createInvite,
|
createInvite,
|
||||||
@@ -259,11 +259,11 @@ export let handlers = {
|
|||||||
getApplicationInformation,
|
getApplicationInformation,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Handlers = typeof handlers;
|
export type Helpers = typeof helpers;
|
||||||
|
|
||||||
export function updateHandlers(newHandlers: Partial<Handlers>) {
|
export function updateHelpers(newHelpers: Partial<Helpers>) {
|
||||||
handlers = {
|
helpers = {
|
||||||
...handlers,
|
...helpers,
|
||||||
...newHandlers,
|
...newHelpers,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../rest/request_manager.ts";
|
||||||
import { OAuthApplication } from "../../types/oauth.ts";
|
import { OAuthApplication } from "../types/oauth.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../util/constants.ts";
|
||||||
|
|
||||||
/** Returns the bot's OAuth2 application object without `flags`. */
|
/** Returns the bot's OAuth2 application object without `flags`. */
|
||||||
export async function getApplicationInformation() {
|
export async function getApplicationInformation() {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationID } from "../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../rest/request_manager.ts";
|
||||||
import {
|
import {
|
||||||
CreateSlashCommandOptions,
|
CreateSlashCommandOptions,
|
||||||
EditSlashCommandOptions,
|
EditSlashCommandOptions,
|
||||||
@@ -18,12 +18,12 @@ import {
|
|||||||
WebhookCreateOptions,
|
WebhookCreateOptions,
|
||||||
WebhookEditOptions,
|
WebhookEditOptions,
|
||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../../util/constants.ts";
|
import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../util/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
import { botHasChannelPermissions } from "../util/permissions.ts";
|
||||||
import { urlToBase64 } from "../../util/utils.ts";
|
import { urlToBase64 } from "../util/utils.ts";
|
||||||
import { structures } from "../structures/mod.ts";
|
import { structures } from "../structures/mod.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,8 +12,8 @@ const serverOptions = {
|
|||||||
port: 80,
|
port: 80,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Theses are the controllers that you can plug into and customize to your needs. */
|
/** Theses are the handlers that you can plug into and customize to your needs. */
|
||||||
export const controllers = {
|
export const handlers = {
|
||||||
handlePayload,
|
handlePayload,
|
||||||
handleApplicationCommand,
|
handleApplicationCommand,
|
||||||
};
|
};
|
||||||
@@ -36,7 +36,7 @@ export async function startServer(
|
|||||||
serverOptions.publicKey = publicKey;
|
serverOptions.publicKey = publicKey;
|
||||||
serverOptions.port = port;
|
serverOptions.port = port;
|
||||||
if (handleApplicationCommand) {
|
if (handleApplicationCommand) {
|
||||||
controllers.handleApplicationCommand = handleApplicationCommand;
|
handlers.handleApplicationCommand = handleApplicationCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = serve({ port: serverOptions.port });
|
const server = serve({ port: serverOptions.port });
|
||||||
@@ -59,7 +59,7 @@ export async function startServer(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(new TextDecoder().decode(buffer));
|
const data = JSON.parse(new TextDecoder().decode(buffer));
|
||||||
const response = await controllers.handlePayload(data);
|
const response = await handlers.handlePayload(data);
|
||||||
req.respond(
|
req.respond(
|
||||||
{ status: response.status || 200, body: JSON.stringify(response.body) },
|
{ status: response.status || 200, body: JSON.stringify(response.body) },
|
||||||
);
|
);
|
||||||
@@ -74,7 +74,7 @@ function handlePayload(payload: Interaction) {
|
|||||||
case InteractionType.PING:
|
case InteractionType.PING:
|
||||||
return { status: 200, body: { type: InteractionResponseType.PONG } };
|
return { status: 200, body: { type: InteractionResponseType.PONG } };
|
||||||
default: // APPLICATION_COMMAND
|
default: // APPLICATION_COMMAND
|
||||||
return controllers.handleApplicationCommand(payload);
|
return handlers.handleApplicationCommand(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ import {
|
|||||||
Overwrite,
|
Overwrite,
|
||||||
Permission,
|
Permission,
|
||||||
RawOverwrite,
|
RawOverwrite,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import {
|
import {
|
||||||
channelOverwriteHasPermission,
|
channelOverwriteHasPermission,
|
||||||
editChannel,
|
editChannel,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
} from "../handlers/channel.ts";
|
} from "../helpers/channel.ts";
|
||||||
import {
|
import {
|
||||||
deleteChannel,
|
deleteChannel,
|
||||||
deleteChannelOverwrite,
|
deleteChannelOverwrite,
|
||||||
editChannelOverwrite,
|
editChannelOverwrite,
|
||||||
} from "../handlers/guild.ts";
|
} from "../helpers/guild.ts";
|
||||||
import { kickFromVoiceChannel } from "../handlers/member.ts";
|
import { kickFromVoiceChannel } from "../helpers/member.ts";
|
||||||
import { CleanVoiceState, Guild } from "./guild.ts";
|
import { CleanVoiceState, Guild } from "./guild.ts";
|
||||||
import { Member } from "./member.ts";
|
import { Member } from "./member.ts";
|
||||||
import { Message } from "./message.ts";
|
import { Message } from "./message.ts";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botID } from "../bot.ts";
|
||||||
import {
|
import {
|
||||||
BanOptions,
|
BanOptions,
|
||||||
CreateGuildPayload,
|
CreateGuildPayload,
|
||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
MemberCreatePayload,
|
MemberCreatePayload,
|
||||||
Presence,
|
Presence,
|
||||||
VoiceState,
|
VoiceState,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import {
|
import {
|
||||||
ban,
|
ban,
|
||||||
deleteServer,
|
deleteServer,
|
||||||
@@ -29,7 +29,7 @@ import {
|
|||||||
guildIconURL,
|
guildIconURL,
|
||||||
leaveGuild,
|
leaveGuild,
|
||||||
unban,
|
unban,
|
||||||
} from "../handlers/guild.ts";
|
} from "../helpers/guild.ts";
|
||||||
import { Member } from "./member.ts";
|
import { Member } from "./member.ts";
|
||||||
import { Channel, Role, structures } from "./mod.ts";
|
import { Channel, Role, structures } from "./mod.ts";
|
||||||
|
|
||||||
@@ -6,12 +6,12 @@ import {
|
|||||||
ImageSize,
|
ImageSize,
|
||||||
MemberCreatePayload,
|
MemberCreatePayload,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { ban } from "../handlers/guild.ts";
|
import { ban } from "../helpers/guild.ts";
|
||||||
import {
|
import {
|
||||||
addRole,
|
addRole,
|
||||||
editMember,
|
editMember,
|
||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
rawAvatarURL,
|
rawAvatarURL,
|
||||||
removeRole,
|
removeRole,
|
||||||
sendDirectMessage,
|
sendDirectMessage,
|
||||||
} from "../handlers/member.ts";
|
} from "../helpers/member.ts";
|
||||||
import { Guild } from "./guild.ts";
|
import { Guild } from "./guild.ts";
|
||||||
|
|
||||||
const baseMember: Partial<Member> = {
|
const baseMember: Partial<Member> = {
|
||||||
@@ -11,12 +11,12 @@ import {
|
|||||||
Reaction,
|
Reaction,
|
||||||
Reference,
|
Reference,
|
||||||
UserPayload,
|
UserPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { sendMessage } from "../handlers/channel.ts";
|
import { sendMessage } from "../helpers/channel.ts";
|
||||||
import { sendDirectMessage } from "../handlers/member.ts";
|
import { sendDirectMessage } from "../helpers/member.ts";
|
||||||
import {
|
import {
|
||||||
addReaction,
|
addReaction,
|
||||||
addReactions,
|
addReactions,
|
||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
removeAllReactions,
|
removeAllReactions,
|
||||||
removeReaction,
|
removeReaction,
|
||||||
removeReactionEmoji,
|
removeReactionEmoji,
|
||||||
} from "../handlers/message.ts";
|
} from "../helpers/message.ts";
|
||||||
import { Channel } from "./channel.ts";
|
import { Channel } from "./channel.ts";
|
||||||
import { Guild } from "./guild.ts";
|
import { Guild } from "./guild.ts";
|
||||||
import { Member } from "./member.ts";
|
import { Member } from "./member.ts";
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { CreateRoleOptions, RoleData } from "../../types/mod.ts";
|
import { CreateRoleOptions, RoleData } from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import { deleteRole, editRole } from "../handlers/guild.ts";
|
import { deleteRole, editRole } from "../helpers/guild.ts";
|
||||||
import { Guild } from "./guild.ts";
|
import { Guild } from "./guild.ts";
|
||||||
import { Member } from "./member.ts";
|
import { Member } from "./member.ts";
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { GuildTemplate, UserPayload } from "../../types/mod.ts";
|
import { GuildTemplate, UserPayload } from "../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.ts";
|
import { cache } from "../util/cache.ts";
|
||||||
import { createNewProp } from "../../util/utils.ts";
|
import { createNewProp } from "../util/utils.ts";
|
||||||
import { Guild } from "./guild.ts";
|
import { Guild } from "./guild.ts";
|
||||||
|
|
||||||
const baseTemplate: Partial<Template> = {
|
const baseTemplate: Partial<Template> = {
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Guild } from "../api/structures/mod.ts";
|
import { Guild } from "../structures/mod.ts";
|
||||||
import { ChannelCreatePayload, ChannelTypes } from "./channel.ts";
|
import { ChannelCreatePayload, ChannelTypes } from "./channel.ts";
|
||||||
import { Emoji, StatusType } from "./discord.ts";
|
import { Emoji, StatusType } from "./discord.ts";
|
||||||
import { MemberCreatePayload } from "./member.ts";
|
import { MemberCreatePayload } from "./member.ts";
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Guild } from "../api/structures/mod.ts";
|
import { Guild } from "../structures/mod.ts";
|
||||||
import { ChannelCreatePayload } from "./channel.ts";
|
import { ChannelCreatePayload } from "./channel.ts";
|
||||||
import { UserPayload } from "./guild.ts";
|
import { UserPayload } from "./guild.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Channel } from "../api/structures/mod.ts";
|
import { Channel } from "../structures/mod.ts";
|
||||||
import { ChannelType } from "./channel.ts";
|
import { ChannelType } from "./channel.ts";
|
||||||
import { UserPayload } from "./guild.ts";
|
import { UserPayload } from "./guild.ts";
|
||||||
import { MemberCreatePayload } from "./member.ts";
|
import { MemberCreatePayload } from "./member.ts";
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
import {
|
import { Channel, Guild, Member, Message, Role } from "../structures/mod.ts";
|
||||||
Channel,
|
|
||||||
Guild,
|
|
||||||
Member,
|
|
||||||
Message,
|
|
||||||
Role,
|
|
||||||
} from "../api/structures/mod.ts";
|
|
||||||
import { Collection } from "../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import {
|
import {
|
||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
|
|||||||
+1
-1
@@ -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 { PresenceUpdatePayload } from "../types/mod.ts";
|
||||||
import { Collection } from "./collection.ts";
|
import { Collection } from "./collection.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { cacheHandlers } from "../cache.ts";
|
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 { botID } from "../bot.ts";
|
||||||
import { Permission, Permissions, RawOverwrite } from "../types/mod.ts";
|
import { Permission, Permissions, RawOverwrite } from "../types/mod.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { controllers } from "../api/controllers/mod.ts";
|
import { handlers } from "../handlers/mod.ts";
|
||||||
import { Guild } from "../api/structures/guild.ts";
|
import { Guild } from "../structures/guild.ts";
|
||||||
import { Member } from "../api/structures/mod.ts";
|
import { Member } from "../structures/mod.ts";
|
||||||
import { eventHandlers } from "../bot.ts";
|
import { eventHandlers } from "../bot.ts";
|
||||||
import {
|
import {
|
||||||
DiscordBotGatewayData,
|
DiscordBotGatewayData,
|
||||||
@@ -80,8 +80,8 @@ export async function handleDiscordPayload(
|
|||||||
return eventHandlers.heartbeat?.();
|
return eventHandlers.heartbeat?.();
|
||||||
case GatewayOpcode.Dispatch:
|
case GatewayOpcode.Dispatch:
|
||||||
if (!data.t) return;
|
if (!data.t) return;
|
||||||
// Run the appropriate controller for this event.
|
// Run the appropriate handler for this event.
|
||||||
return controllers[data.t]?.(data, shardID);
|
return handlers[data.t]?.(data, shardID);
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user