mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactor(controllers): separate controllers into different files (#657)
* refactor(controllers): separate controller into files * add CHANNEL_UPDATE * guilds * interactions * members * messages * finally * done * fix ci * fixes
This commit is contained in:
@@ -1,13 +1,4 @@
|
|||||||
export * from "./src/api/controllers/bans.ts";
|
export * from "./src/cache.ts";
|
||||||
export * from "./src/api/controllers/cache.ts";
|
|
||||||
export * from "./src/api/controllers/channels.ts";
|
|
||||||
export * from "./src/api/controllers/guilds.ts";
|
|
||||||
export * from "./src/api/controllers/members.ts";
|
|
||||||
export * from "./src/api/controllers/messages.ts";
|
|
||||||
export * from "./src/api/controllers/misc.ts";
|
|
||||||
export * from "./src/api/controllers/mod.ts";
|
|
||||||
export * from "./src/api/controllers/reactions.ts";
|
|
||||||
export * from "./src/api/controllers/roles.ts";
|
|
||||||
export * from "./src/api/handlers/channel.ts";
|
export * from "./src/api/handlers/channel.ts";
|
||||||
export * from "./src/api/handlers/guild.ts";
|
export * from "./src/api/handlers/guild.ts";
|
||||||
export * from "./src/api/handlers/member.ts";
|
export * from "./src/api/handlers/member.ts";
|
||||||
@@ -28,3 +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";
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ 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";
|
||||||
|
|
||||||
/** This function is the internal handler for the ready event. Users can override this with controllers if desired. */
|
export async function handleReady(
|
||||||
export async function handleInternalReady(
|
|
||||||
data: DiscordPayload,
|
data: DiscordPayload,
|
||||||
shardID: number,
|
shardID: number,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalGuildBanAdd(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildBanPayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const member = await cacheHandlers.get("members", payload.user.id);
|
|
||||||
eventHandlers.guildBanAdd?.(guild, payload.user, member);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildBanRemove(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildBanPayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const member = await cacheHandlers.get("members", payload.user.id);
|
|
||||||
eventHandlers.guildBanRemove?.(guild, payload.user, member);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleChannelCreate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as ChannelCreatePayload;
|
||||||
|
|
||||||
|
const channelStruct = await structures.createChannelStruct(payload);
|
||||||
|
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
||||||
|
|
||||||
|
eventHandlers.channelCreate?.(channelStruct);
|
||||||
|
}
|
||||||
@@ -1,22 +1,12 @@
|
|||||||
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 { structures } from "../structures/mod.ts";
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalChannelCreate(data: DiscordPayload) {
|
export async function handleChannelDelete(data: DiscordPayload) {
|
||||||
const payload = data.d as ChannelCreatePayload;
|
|
||||||
|
|
||||||
const channelStruct = await structures.createChannelStruct(payload);
|
|
||||||
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
|
||||||
|
|
||||||
eventHandlers.channelCreate?.(channelStruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalChannelDelete(data: DiscordPayload) {
|
|
||||||
const payload = data.d as ChannelCreatePayload;
|
const payload = data.d as ChannelCreatePayload;
|
||||||
|
|
||||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||||
@@ -48,15 +38,3 @@ export async function handleInternalChannelDelete(data: DiscordPayload) {
|
|||||||
});
|
});
|
||||||
eventHandlers.channelDelete?.(cachedChannel);
|
eventHandlers.channelDelete?.(cachedChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleInternalChannelUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as ChannelCreatePayload;
|
|
||||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
|
||||||
|
|
||||||
const channelStruct = await structures.createChannelStruct(payload);
|
|
||||||
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
|
||||||
|
|
||||||
if (!cachedChannel) return;
|
|
||||||
|
|
||||||
eventHandlers.channelUpdate?.(channelStruct, cachedChannel);
|
|
||||||
}
|
|
||||||
+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;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { ChannelCreatePayload, DiscordPayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleChannelUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as ChannelCreatePayload;
|
||||||
|
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||||
|
|
||||||
|
const channelStruct = await structures.createChannelStruct(payload);
|
||||||
|
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
||||||
|
|
||||||
|
if (!cachedChannel) return;
|
||||||
|
|
||||||
|
eventHandlers.channelUpdate?.(channelStruct, cachedChannel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleApplicationCommandCreate(
|
||||||
|
data: DiscordPayload,
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
guild_id: guildID,
|
||||||
|
application_id: applicationID,
|
||||||
|
...rest
|
||||||
|
} = data.d as ApplicationCommandEvent;
|
||||||
|
|
||||||
|
eventHandlers.applicationCommandCreate?.({
|
||||||
|
...rest,
|
||||||
|
guildID,
|
||||||
|
applicationID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleApplicationCommandDelete(data: DiscordPayload) {
|
||||||
|
const {
|
||||||
|
application_id: applicationID,
|
||||||
|
guild_id: guildID,
|
||||||
|
...rest
|
||||||
|
} = data.d as ApplicationCommandEvent;
|
||||||
|
|
||||||
|
eventHandlers.applicationCommandDelete?.({
|
||||||
|
...rest,
|
||||||
|
guildID,
|
||||||
|
applicationID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { ApplicationCommandEvent, DiscordPayload } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleApplicationCommandUpdate(data: DiscordPayload) {
|
||||||
|
const {
|
||||||
|
application_id: applicationID,
|
||||||
|
guild_id: guildID,
|
||||||
|
...rest
|
||||||
|
} = data.d as ApplicationCommandEvent;
|
||||||
|
|
||||||
|
eventHandlers.applicationCommandUpdate?.({
|
||||||
|
...rest,
|
||||||
|
guildID,
|
||||||
|
applicationID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
CreateGuildPayload,
|
|
||||||
DiscordPayload,
|
|
||||||
GuildDeletePayload,
|
|
||||||
GuildEmojisUpdatePayload,
|
|
||||||
GuildUpdateChange,
|
|
||||||
UpdateGuildPayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { cache } from "../../util/cache.ts";
|
|
||||||
import { Collection } from "../../util/collection.ts";
|
|
||||||
import { basicShards } from "../../ws/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalGuildCreate(
|
|
||||||
data: DiscordPayload,
|
|
||||||
shardID: number,
|
|
||||||
) {
|
|
||||||
const payload = data.d as CreateGuildPayload;
|
|
||||||
// When shards resume they emit GUILD_CREATE again.
|
|
||||||
if (await cacheHandlers.has("guilds", payload.id)) return;
|
|
||||||
|
|
||||||
const guildStruct = await structures.createGuildStruct(
|
|
||||||
data.d as CreateGuildPayload,
|
|
||||||
shardID,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);
|
|
||||||
|
|
||||||
const shard = basicShards.get(shardID);
|
|
||||||
|
|
||||||
if (shard?.unavailableGuildIDs.has(payload.id)) {
|
|
||||||
await cacheHandlers.delete("unavailableGuilds", payload.id);
|
|
||||||
|
|
||||||
shard.unavailableGuildIDs.delete(payload.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
|
|
||||||
eventHandlers.guildCreate?.(guildStruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildDelete(
|
|
||||||
data: DiscordPayload,
|
|
||||||
shardID: number,
|
|
||||||
) {
|
|
||||||
const payload = data.d as GuildDeletePayload;
|
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
|
||||||
if (message.guildID === payload.id) {
|
|
||||||
cacheHandlers.delete("messages", message.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cacheHandlers.forEach("channels", (channel) => {
|
|
||||||
if (channel.guildID === payload.id) {
|
|
||||||
cacheHandlers.delete("channels", channel.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cacheHandlers.forEach("members", async (member) => {
|
|
||||||
if (!member.guilds.has(payload.id)) return;
|
|
||||||
|
|
||||||
member.guilds.delete(payload.id);
|
|
||||||
|
|
||||||
if (!member.guilds.size) {
|
|
||||||
await cacheHandlers.delete("members", member.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await cacheHandlers.set("members", member.id, member);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (payload.unavailable) {
|
|
||||||
const shard = basicShards.get(shardID);
|
|
||||||
if (shard) shard.unavailableGuildIDs.add(payload.id);
|
|
||||||
|
|
||||||
return cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
await cacheHandlers.delete("guilds", payload.id);
|
|
||||||
|
|
||||||
eventHandlers.guildDelete?.(guild);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as UpdateGuildPayload;
|
|
||||||
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
|
|
||||||
if (!cachedGuild) return;
|
|
||||||
|
|
||||||
const keysToSkip = [
|
|
||||||
"roles",
|
|
||||||
"guild_hashes",
|
|
||||||
"guild_id",
|
|
||||||
"max_members",
|
|
||||||
"emojis",
|
|
||||||
];
|
|
||||||
|
|
||||||
const changes = Object.entries(payload)
|
|
||||||
.map(([key, value]) => {
|
|
||||||
if (keysToSkip.includes(key)) return;
|
|
||||||
|
|
||||||
// @ts-ignore index signature
|
|
||||||
const cachedValue = cachedGuild[key];
|
|
||||||
if (cachedValue !== value) {
|
|
||||||
// Guild create sends undefined and update sends false.
|
|
||||||
if (!cachedValue && !value) return;
|
|
||||||
|
|
||||||
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
|
||||||
const different = (cachedValue.length !== value.length) ||
|
|
||||||
cachedValue.find((val) => !value.includes(val)) ||
|
|
||||||
value.find((val) => !cachedValue.includes(val));
|
|
||||||
if (!different) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore index signature
|
|
||||||
cachedGuild[key] = value;
|
|
||||||
return { key, oldValue: cachedValue, value };
|
|
||||||
}
|
|
||||||
}).filter((change) => change) as GuildUpdateChange[];
|
|
||||||
|
|
||||||
await cacheHandlers.set("guilds", payload.id, cachedGuild);
|
|
||||||
|
|
||||||
eventHandlers.guildUpdate?.(cachedGuild, changes);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildEmojisUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildEmojisUpdatePayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const cachedEmojis = guild.emojis;
|
|
||||||
guild.emojis = new Collection(
|
|
||||||
payload.emojis.map((emoji) => [emoji.id ?? emoji.name, emoji]),
|
|
||||||
);
|
|
||||||
|
|
||||||
cacheHandlers.set("guilds", payload.guild_id, guild);
|
|
||||||
|
|
||||||
eventHandlers.guildEmojisUpdate?.(
|
|
||||||
guild,
|
|
||||||
guild.emojis,
|
|
||||||
cachedEmojis,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const member = await cacheHandlers.get("members", payload.user.id);
|
||||||
|
eventHandlers.guildBanAdd?.(guild, payload.user, member);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const member = await cacheHandlers.get("members", payload.user.id);
|
||||||
|
eventHandlers.guildBanRemove?.(guild, payload.user, member);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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";
|
||||||
|
|
||||||
|
export async function handleGuildCreate(
|
||||||
|
data: DiscordPayload,
|
||||||
|
shardID: number,
|
||||||
|
) {
|
||||||
|
const payload = data.d as CreateGuildPayload;
|
||||||
|
// When shards resume they emit GUILD_CREATE again.
|
||||||
|
if (await cacheHandlers.has("guilds", payload.id)) return;
|
||||||
|
|
||||||
|
const guildStruct = await structures.createGuildStruct(
|
||||||
|
data.d as CreateGuildPayload,
|
||||||
|
shardID,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);
|
||||||
|
|
||||||
|
const shard = basicShards.get(shardID);
|
||||||
|
|
||||||
|
if (shard?.unavailableGuildIDs.has(payload.id)) {
|
||||||
|
await cacheHandlers.delete("unavailableGuilds", payload.id);
|
||||||
|
|
||||||
|
shard.unavailableGuildIDs.delete(payload.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
|
||||||
|
eventHandlers.guildCreate?.(guildStruct);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
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,
|
||||||
|
shardID: number,
|
||||||
|
) {
|
||||||
|
const payload = data.d as GuildDeletePayload;
|
||||||
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
|
if (message.guildID === payload.id) {
|
||||||
|
cacheHandlers.delete("messages", message.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cacheHandlers.forEach("channels", (channel) => {
|
||||||
|
if (channel.guildID === payload.id) {
|
||||||
|
cacheHandlers.delete("channels", channel.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cacheHandlers.forEach("members", async (member) => {
|
||||||
|
if (!member.guilds.has(payload.id)) return;
|
||||||
|
|
||||||
|
member.guilds.delete(payload.id);
|
||||||
|
|
||||||
|
if (!member.guilds.size) {
|
||||||
|
await cacheHandlers.delete("members", member.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await cacheHandlers.set("members", member.id, member);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (payload.unavailable) {
|
||||||
|
const shard = basicShards.get(shardID);
|
||||||
|
if (shard) shard.unavailableGuildIDs.add(payload.id);
|
||||||
|
|
||||||
|
return cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
await cacheHandlers.delete("guilds", payload.id);
|
||||||
|
|
||||||
|
eventHandlers.guildDelete?.(guild);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const cachedEmojis = guild.emojis;
|
||||||
|
guild.emojis = new Collection(
|
||||||
|
payload.emojis.map((emoji) => [emoji.id ?? emoji.name, emoji]),
|
||||||
|
);
|
||||||
|
|
||||||
|
cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||||
|
|
||||||
|
eventHandlers.guildEmojisUpdate?.(
|
||||||
|
guild,
|
||||||
|
guild.emojis,
|
||||||
|
cachedEmojis,
|
||||||
|
);
|
||||||
|
}
|
||||||
+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,
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
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";
|
||||||
|
|
||||||
|
export async function handleGuildMembersChunk(data: DiscordPayload) {
|
||||||
|
const payload = data.d as GuildMemberChunkPayload;
|
||||||
|
|
||||||
|
const members = await Promise.all(
|
||||||
|
payload.members.map(async (member) => {
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
member,
|
||||||
|
payload.guild_id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|
||||||
|
return memberStruct;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
||||||
|
if (
|
||||||
|
payload.nonce
|
||||||
|
) {
|
||||||
|
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
||||||
|
if (!resolve) return;
|
||||||
|
|
||||||
|
if (payload.chunk_index + 1 === payload.chunk_count) {
|
||||||
|
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
||||||
|
// Only 1 chunk most likely is all members or users only request a small amount of users
|
||||||
|
if (payload.chunk_count === 1) {
|
||||||
|
return resolve(new Collection(members.map((m) => [m.id, m])));
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolve(
|
||||||
|
await cacheHandlers.filter(
|
||||||
|
"members",
|
||||||
|
(m) => m.guilds.has(payload.guild_id),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, GuildMemberAddPayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleGuildMemberAdd(data: DiscordPayload) {
|
||||||
|
const payload = data.d as GuildMemberAddPayload;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
guild.memberCount++;
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
payload,
|
||||||
|
payload.guild_id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|
||||||
|
eventHandlers.guildMemberAdd?.(guild, memberStruct);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
guild.memberCount--;
|
||||||
|
const member = await cacheHandlers.get("members", payload.user.id);
|
||||||
|
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
||||||
|
|
||||||
|
member?.guilds.delete(guild.id);
|
||||||
|
if (member && !member.guilds.size) {
|
||||||
|
await cacheHandlers.delete("members", member.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
GuildMemberUpdatePayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleGuildMemberUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as GuildMemberUpdatePayload;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const cachedMember = await cacheHandlers.get("members", payload.user.id);
|
||||||
|
const guildMember = cachedMember?.guilds.get(payload.guild_id);
|
||||||
|
|
||||||
|
const newMemberData = {
|
||||||
|
...payload,
|
||||||
|
// deno-lint-ignore camelcase
|
||||||
|
premium_since: payload.premium_since || undefined,
|
||||||
|
// deno-lint-ignore camelcase
|
||||||
|
joined_at: new Date(guildMember?.joinedAt || Date.now())
|
||||||
|
.toISOString(),
|
||||||
|
deaf: guildMember?.deaf || false,
|
||||||
|
mute: guildMember?.mute || false,
|
||||||
|
roles: payload.roles,
|
||||||
|
};
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
newMemberData,
|
||||||
|
payload.guild_id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|
||||||
|
if (guildMember?.nick !== payload.nick) {
|
||||||
|
eventHandlers.nicknameUpdate?.(
|
||||||
|
guild,
|
||||||
|
memberStruct,
|
||||||
|
payload.nick,
|
||||||
|
guildMember?.nick,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.pending === false && guildMember?.pending === true) {
|
||||||
|
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleIDs = guildMember?.roles || [];
|
||||||
|
|
||||||
|
roleIDs.forEach((id) => {
|
||||||
|
if (!payload.roles.includes(id)) {
|
||||||
|
eventHandlers.roleLost?.(guild, memberStruct, id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
payload.roles.forEach((id) => {
|
||||||
|
if (!roleIDs.includes(id)) {
|
||||||
|
eventHandlers.roleGained?.(guild, memberStruct, id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
eventHandlers.guildMemberUpdate?.(guild, memberStruct, cachedMember);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
GuildRoleDeletePayload,
|
||||||
|
GuildRolePayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleGuildRoleCreate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as GuildRolePayload;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const role = await structures.createRoleStruct(payload.role);
|
||||||
|
guild.roles = guild.roles.set(payload.role.id, role);
|
||||||
|
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||||
|
|
||||||
|
eventHandlers.roleCreate?.(guild, role);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const cachedRole = guild.roles.get(payload.role_id)!;
|
||||||
|
guild.roles.delete(payload.role_id);
|
||||||
|
|
||||||
|
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
|
||||||
|
|
||||||
|
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
|
||||||
|
cacheHandlers.forEach("members", (member) => {
|
||||||
|
// Not in the relevant guild so just skip.
|
||||||
|
if (!member.guilds.has(guild.id)) return;
|
||||||
|
|
||||||
|
member.guilds.forEach((g) => {
|
||||||
|
// Member does not have this role
|
||||||
|
if (!g.roles.includes(payload.role_id)) return;
|
||||||
|
// Remove this role from the members cache
|
||||||
|
g.roles = g.roles.filter((id) => id !== payload.role_id);
|
||||||
|
cacheHandlers.set("members", member.id, member);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
GuildRoleDeletePayload,
|
||||||
|
GuildRolePayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleGuildRoleUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as GuildRolePayload;
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const cachedRole = guild.roles.get(payload.role.id);
|
||||||
|
if (!cachedRole) return;
|
||||||
|
|
||||||
|
const role = await structures.createRoleStruct(payload.role);
|
||||||
|
guild.roles.set(payload.role.id, role);
|
||||||
|
await cacheHandlers.set("guilds", guild.id, guild);
|
||||||
|
|
||||||
|
eventHandlers.roleUpdate?.(guild, role, cachedRole);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
GuildUpdateChange,
|
||||||
|
UpdateGuildPayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleGuildUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as UpdateGuildPayload;
|
||||||
|
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
|
||||||
|
if (!cachedGuild) return;
|
||||||
|
|
||||||
|
const keysToSkip = [
|
||||||
|
"roles",
|
||||||
|
"guild_hashes",
|
||||||
|
"guild_id",
|
||||||
|
"max_members",
|
||||||
|
"emojis",
|
||||||
|
];
|
||||||
|
|
||||||
|
const changes = Object.entries(payload)
|
||||||
|
.map(([key, value]) => {
|
||||||
|
if (keysToSkip.includes(key)) return;
|
||||||
|
|
||||||
|
// @ts-ignore index signature
|
||||||
|
const cachedValue = cachedGuild[key];
|
||||||
|
if (cachedValue !== value) {
|
||||||
|
// Guild create sends undefined and update sends false.
|
||||||
|
if (!cachedValue && !value) return;
|
||||||
|
|
||||||
|
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
||||||
|
const different = (cachedValue.length !== value.length) ||
|
||||||
|
cachedValue.find((val) => !value.includes(val)) ||
|
||||||
|
value.find((val) => !cachedValue.includes(val));
|
||||||
|
if (!different) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore index signature
|
||||||
|
cachedGuild[key] = value;
|
||||||
|
return { key, oldValue: cachedValue, value };
|
||||||
|
}
|
||||||
|
}).filter((change) => change) as GuildUpdateChange[];
|
||||||
|
|
||||||
|
await cacheHandlers.set("guilds", payload.id, cachedGuild);
|
||||||
|
|
||||||
|
eventHandlers.guildUpdate?.(cachedGuild, changes);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
IntegrationCreateUpdateEvent,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleIntegrationCreate(
|
||||||
|
data: DiscordPayload,
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
guild_id: guildID,
|
||||||
|
enable_emoticons: enableEmoticons,
|
||||||
|
expire_behavior: expireBehavior,
|
||||||
|
expire_grace_period: expireGracePeriod,
|
||||||
|
subscriber_count: subscriberCount,
|
||||||
|
role_id: roleID,
|
||||||
|
synced_at: syncedAt,
|
||||||
|
...rest
|
||||||
|
} = data.d as IntegrationCreateUpdateEvent;
|
||||||
|
|
||||||
|
eventHandlers.integrationCreate?.({
|
||||||
|
...rest,
|
||||||
|
guildID,
|
||||||
|
enableEmoticons,
|
||||||
|
expireBehavior,
|
||||||
|
expireGracePeriod,
|
||||||
|
syncedAt,
|
||||||
|
subscriberCount,
|
||||||
|
roleID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, IntegrationDeleteEvent } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleIntegrationDelete(data: DiscordPayload) {
|
||||||
|
const {
|
||||||
|
guild_id: guildID,
|
||||||
|
application_id: applicationID,
|
||||||
|
...rest
|
||||||
|
} = data.d as IntegrationDeleteEvent;
|
||||||
|
|
||||||
|
eventHandlers.integrationDelete?.({
|
||||||
|
...rest,
|
||||||
|
applicationID,
|
||||||
|
guildID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
IntegrationCreateUpdateEvent,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleIntegrationUpdate(data: DiscordPayload) {
|
||||||
|
const {
|
||||||
|
enable_emoticons: enableEmoticons,
|
||||||
|
expire_behavior: expireBehavior,
|
||||||
|
expire_grace_period: expireGracePeriod,
|
||||||
|
role_id: roleID,
|
||||||
|
subscriber_count: subscriberCount,
|
||||||
|
synced_at: syncedAt,
|
||||||
|
guild_id: guildID,
|
||||||
|
...rest
|
||||||
|
} = data.d as IntegrationCreateUpdateEvent;
|
||||||
|
|
||||||
|
eventHandlers.integrationUpdate?.({
|
||||||
|
...rest,
|
||||||
|
guildID,
|
||||||
|
subscriberCount,
|
||||||
|
enableEmoticons,
|
||||||
|
expireGracePeriod,
|
||||||
|
roleID,
|
||||||
|
expireBehavior,
|
||||||
|
syncedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
ApplicationCommandEvent,
|
|
||||||
DiscordPayload,
|
|
||||||
InteractionCommandPayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalInteractionCreate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as InteractionCommandPayload;
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
payload.member,
|
|
||||||
payload.guild_id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
|
|
||||||
eventHandlers.interactionCreate?.(
|
|
||||||
{
|
|
||||||
...payload,
|
|
||||||
member: memberStruct,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalApplicationCommandCreate(
|
|
||||||
data: DiscordPayload,
|
|
||||||
) {
|
|
||||||
const {
|
|
||||||
guild_id: guildID,
|
|
||||||
application_id: applicationID,
|
|
||||||
...rest
|
|
||||||
} = data.d as ApplicationCommandEvent;
|
|
||||||
|
|
||||||
eventHandlers.applicationCommandCreate?.({
|
|
||||||
...rest,
|
|
||||||
guildID,
|
|
||||||
applicationID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalApplicationCommandUpdate(data: DiscordPayload) {
|
|
||||||
const {
|
|
||||||
application_id: applicationID,
|
|
||||||
guild_id: guildID,
|
|
||||||
...rest
|
|
||||||
} = data.d as ApplicationCommandEvent;
|
|
||||||
|
|
||||||
eventHandlers.applicationCommandUpdate?.({
|
|
||||||
...rest,
|
|
||||||
guildID,
|
|
||||||
applicationID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalApplicationCommandDelete(data: DiscordPayload) {
|
|
||||||
const {
|
|
||||||
application_id: applicationID,
|
|
||||||
guild_id: guildID,
|
|
||||||
...rest
|
|
||||||
} = data.d as ApplicationCommandEvent;
|
|
||||||
|
|
||||||
eventHandlers.applicationCommandDelete?.({
|
|
||||||
...rest,
|
|
||||||
guildID,
|
|
||||||
applicationID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
InteractionCommandPayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleInteractionCreate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as InteractionCommandPayload;
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
payload.member,
|
||||||
|
payload.guild_id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|
||||||
|
eventHandlers.interactionCreate?.(
|
||||||
|
{
|
||||||
|
...payload,
|
||||||
|
member: memberStruct,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, InviteCreateEvent } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleInviteCreate(payload: DiscordPayload) {
|
||||||
|
if (payload.t !== "INVITE_CREATE") return;
|
||||||
|
//TODO: replace with tocamelcase
|
||||||
|
const {
|
||||||
|
channel_id: channelID,
|
||||||
|
created_at: createdAt,
|
||||||
|
max_age: maxAge,
|
||||||
|
guild_id: guildID,
|
||||||
|
target_user: targetUser,
|
||||||
|
target_user_type: targetUserType,
|
||||||
|
max_uses: maxUses,
|
||||||
|
...rest
|
||||||
|
} = payload.d as InviteCreateEvent;
|
||||||
|
|
||||||
|
eventHandlers.inviteCreate?.({
|
||||||
|
...rest,
|
||||||
|
channelID,
|
||||||
|
guildID,
|
||||||
|
maxAge,
|
||||||
|
targetUser,
|
||||||
|
targetUserType,
|
||||||
|
maxUses,
|
||||||
|
createdAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, InviteDeleteEvent } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleInviteDelete(payload: DiscordPayload) {
|
||||||
|
if (payload.t !== "INVITE_DELETE") return;
|
||||||
|
|
||||||
|
const {
|
||||||
|
channel_id: channelID,
|
||||||
|
guild_id: guildID,
|
||||||
|
...rest
|
||||||
|
} = payload.d as InviteDeleteEvent;
|
||||||
|
|
||||||
|
eventHandlers.inviteDelete?.({
|
||||||
|
...rest,
|
||||||
|
channelID,
|
||||||
|
guildID,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
DiscordPayload,
|
|
||||||
GuildBanPayload,
|
|
||||||
GuildMemberAddPayload,
|
|
||||||
GuildMemberChunkPayload,
|
|
||||||
GuildMemberUpdatePayload,
|
|
||||||
} 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";
|
|
||||||
|
|
||||||
export async function handleInternalGuildMemberAdd(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildMemberAddPayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
guild.memberCount++;
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
payload,
|
|
||||||
payload.guild_id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
|
|
||||||
eventHandlers.guildMemberAdd?.(guild, memberStruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildMemberRemove(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildBanPayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
guild.memberCount--;
|
|
||||||
const member = await cacheHandlers.get("members", payload.user.id);
|
|
||||||
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
|
||||||
|
|
||||||
member?.guilds.delete(guild.id);
|
|
||||||
if (member && !member.guilds.size) {
|
|
||||||
await cacheHandlers.delete("members", member.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildMemberUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildMemberUpdatePayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const cachedMember = await cacheHandlers.get("members", payload.user.id);
|
|
||||||
const guildMember = cachedMember?.guilds.get(payload.guild_id);
|
|
||||||
|
|
||||||
const newMemberData = {
|
|
||||||
...payload,
|
|
||||||
// deno-lint-ignore camelcase
|
|
||||||
premium_since: payload.premium_since || undefined,
|
|
||||||
// deno-lint-ignore camelcase
|
|
||||||
joined_at: new Date(guildMember?.joinedAt || Date.now())
|
|
||||||
.toISOString(),
|
|
||||||
deaf: guildMember?.deaf || false,
|
|
||||||
mute: guildMember?.mute || false,
|
|
||||||
roles: payload.roles,
|
|
||||||
};
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
newMemberData,
|
|
||||||
payload.guild_id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
|
|
||||||
if (guildMember?.nick !== payload.nick) {
|
|
||||||
eventHandlers.nicknameUpdate?.(
|
|
||||||
guild,
|
|
||||||
memberStruct,
|
|
||||||
payload.nick,
|
|
||||||
guildMember?.nick,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.pending === false && guildMember?.pending === true) {
|
|
||||||
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
const roleIDs = guildMember?.roles || [];
|
|
||||||
|
|
||||||
roleIDs.forEach((id) => {
|
|
||||||
if (!payload.roles.includes(id)) {
|
|
||||||
eventHandlers.roleLost?.(guild, memberStruct, id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
payload.roles.forEach((id) => {
|
|
||||||
if (!roleIDs.includes(id)) {
|
|
||||||
eventHandlers.roleGained?.(guild, memberStruct, id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventHandlers.guildMemberUpdate?.(guild, memberStruct, cachedMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildMembersChunk(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildMemberChunkPayload;
|
|
||||||
|
|
||||||
const members = await Promise.all(
|
|
||||||
payload.members.map(async (member) => {
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
member,
|
|
||||||
payload.guild_id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
|
|
||||||
return memberStruct;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
|
||||||
if (
|
|
||||||
payload.nonce
|
|
||||||
) {
|
|
||||||
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
|
||||||
if (!resolve) return;
|
|
||||||
|
|
||||||
if (payload.chunk_index + 1 === payload.chunk_count) {
|
|
||||||
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
|
|
||||||
// Only 1 chunk most likely is all members or users only request a small amount of users
|
|
||||||
if (payload.chunk_count === 1) {
|
|
||||||
return resolve(new Collection(members.map((m) => [m.id, m])));
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(
|
|
||||||
await cacheHandlers.filter(
|
|
||||||
"members",
|
|
||||||
(m) => m.guilds.has(payload.guild_id),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
DiscordPayload,
|
|
||||||
MessageCreateOptions,
|
|
||||||
MessageDeleteBulkPayload,
|
|
||||||
MessageDeletePayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalMessageCreate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as MessageCreateOptions;
|
|
||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
|
||||||
if (channel) channel.lastMessageID = payload.id;
|
|
||||||
|
|
||||||
const guild = payload.guild_id
|
|
||||||
? await cacheHandlers.get("guilds", payload.guild_id)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (payload.member && guild) {
|
|
||||||
// If in a guild cache the author as a member
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
{ ...payload.member, user: payload.author },
|
|
||||||
guild.id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(payload.mentions.map(async (mention) => {
|
|
||||||
// Cache the member if its a valid member
|
|
||||||
if (mention.member && guild) {
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
{ ...mention.member, user: mention },
|
|
||||||
guild.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
return cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
const message = await structures.createMessageStruct(payload);
|
|
||||||
// Cache the message
|
|
||||||
await cacheHandlers.set("messages", payload.id, message);
|
|
||||||
|
|
||||||
eventHandlers.messageCreate?.(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageDelete(data: DiscordPayload) {
|
|
||||||
const payload = data.d as MessageDeletePayload;
|
|
||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
eventHandlers.messageDelete?.(
|
|
||||||
{ id: payload.id, channel },
|
|
||||||
await cacheHandlers.get("messages", payload.id),
|
|
||||||
);
|
|
||||||
|
|
||||||
await cacheHandlers.delete("messages", payload.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageDeleteBulk(data: DiscordPayload) {
|
|
||||||
const payload = data.d as MessageDeleteBulkPayload;
|
|
||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
return Promise.all(payload.ids.map(async (id) => {
|
|
||||||
eventHandlers.messageDelete?.(
|
|
||||||
{ id, channel },
|
|
||||||
await cacheHandlers.get("messages", id),
|
|
||||||
);
|
|
||||||
await cacheHandlers.delete("messages", id);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as MessageCreateOptions;
|
|
||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
const cachedMessage = await cacheHandlers.get("messages", payload.id);
|
|
||||||
if (!cachedMessage) return;
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
attachments: cachedMessage.attachments,
|
|
||||||
content: cachedMessage.content,
|
|
||||||
embeds: cachedMessage.embeds,
|
|
||||||
editedTimestamp: cachedMessage.editedTimestamp,
|
|
||||||
tts: cachedMessage.tts,
|
|
||||||
pinned: cachedMessage.pinned,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Messages with embeds can trigger update but they wont have edited_timestamp
|
|
||||||
if (
|
|
||||||
!payload.edited_timestamp ||
|
|
||||||
(cachedMessage.content === payload.content)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = await structures.createMessageStruct(payload);
|
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.id, message);
|
|
||||||
|
|
||||||
eventHandlers.messageUpdate?.(message, oldMessage);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageCreate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as MessageCreateOptions;
|
||||||
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
|
if (channel) channel.lastMessageID = payload.id;
|
||||||
|
|
||||||
|
const guild = payload.guild_id
|
||||||
|
? await cacheHandlers.get("guilds", payload.guild_id)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (payload.member && guild) {
|
||||||
|
// If in a guild cache the author as a member
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
{ ...payload.member, user: payload.author },
|
||||||
|
guild.id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(payload.mentions.map(async (mention) => {
|
||||||
|
// Cache the member if its a valid member
|
||||||
|
if (mention.member && guild) {
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
{ ...mention.member, user: mention },
|
||||||
|
guild.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
return cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
const message = await structures.createMessageStruct(payload);
|
||||||
|
// Cache the message
|
||||||
|
await cacheHandlers.set("messages", payload.id, message);
|
||||||
|
|
||||||
|
eventHandlers.messageCreate?.(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
eventHandlers.messageDelete?.(
|
||||||
|
{ id: payload.id, channel },
|
||||||
|
await cacheHandlers.get("messages", payload.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
await cacheHandlers.delete("messages", payload.id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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;
|
||||||
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
return Promise.all(payload.ids.map(async (id) => {
|
||||||
|
eventHandlers.messageDelete?.(
|
||||||
|
{ id, channel },
|
||||||
|
await cacheHandlers.get("messages", id),
|
||||||
|
);
|
||||||
|
await cacheHandlers.delete("messages", id);
|
||||||
|
}));
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { botID, eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageReactionAdd(data: DiscordPayload) {
|
||||||
|
const payload = data.d as MessageReactionPayload;
|
||||||
|
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
const reactionExisted = message.reactions?.find(
|
||||||
|
(reaction) =>
|
||||||
|
reaction.emoji.id === payload.emoji.id &&
|
||||||
|
reaction.emoji.name === payload.emoji.name,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (reactionExisted) reactionExisted.count++;
|
||||||
|
else {
|
||||||
|
const newReaction = {
|
||||||
|
count: 1,
|
||||||
|
me: payload.user_id === botID,
|
||||||
|
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||||
|
};
|
||||||
|
message.reactions = message.reactions
|
||||||
|
? [...message.reactions, newReaction]
|
||||||
|
: [newReaction];
|
||||||
|
}
|
||||||
|
|
||||||
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.member && payload.guild_id) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (guild) {
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
payload.member,
|
||||||
|
guild.id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uncachedOptions = {
|
||||||
|
...payload,
|
||||||
|
id: payload.message_id,
|
||||||
|
channelID: payload.channel_id,
|
||||||
|
guildID: payload.guild_id || "",
|
||||||
|
};
|
||||||
|
|
||||||
|
eventHandlers.reactionAdd?.(
|
||||||
|
uncachedOptions,
|
||||||
|
payload.emoji,
|
||||||
|
payload.user_id,
|
||||||
|
message,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { botID, eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, MessageReactionPayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageReactionRemove(
|
||||||
|
data: DiscordPayload,
|
||||||
|
) {
|
||||||
|
const payload = data.d as MessageReactionPayload;
|
||||||
|
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
const reactionExisted = message.reactions?.find(
|
||||||
|
(reaction) =>
|
||||||
|
reaction.emoji.id === payload.emoji.id &&
|
||||||
|
reaction.emoji.name === payload.emoji.name,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (reactionExisted) reactionExisted.count--;
|
||||||
|
else {
|
||||||
|
const newReaction = {
|
||||||
|
count: 1,
|
||||||
|
me: payload.user_id === botID,
|
||||||
|
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||||
|
};
|
||||||
|
message.reactions = message.reactions
|
||||||
|
? [...message.reactions, newReaction]
|
||||||
|
: [newReaction];
|
||||||
|
}
|
||||||
|
|
||||||
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.member && payload.guild_id) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (guild) {
|
||||||
|
const memberStruct = await structures.createMemberStruct(
|
||||||
|
payload.member,
|
||||||
|
guild.id,
|
||||||
|
);
|
||||||
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uncachedOptions = {
|
||||||
|
...payload,
|
||||||
|
id: payload.message_id,
|
||||||
|
channelID: payload.channel_id,
|
||||||
|
guildID: payload.guild_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
eventHandlers.reactionRemove?.(
|
||||||
|
uncachedOptions,
|
||||||
|
payload.emoji,
|
||||||
|
payload.user_id,
|
||||||
|
message,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
BaseMessageReactionPayload,
|
||||||
|
DiscordPayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageReactionRemoveAll(
|
||||||
|
data: DiscordPayload,
|
||||||
|
) {
|
||||||
|
const payload = data.d as BaseMessageReactionPayload;
|
||||||
|
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||||
|
|
||||||
|
if (message?.reactions) {
|
||||||
|
message.reactions = undefined;
|
||||||
|
|
||||||
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
eventHandlers.reactionRemoveAll?.(data.d as BaseMessageReactionPayload);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { botID, eventHandlers } from "../../../bot.ts";
|
||||||
|
import {
|
||||||
|
DiscordPayload,
|
||||||
|
MessageReactionRemoveEmojiPayload,
|
||||||
|
} from "../../../types/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageReactionRemoveEmoji(
|
||||||
|
data: DiscordPayload,
|
||||||
|
) {
|
||||||
|
const payload = data.d as MessageReactionRemoveEmojiPayload;
|
||||||
|
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||||
|
|
||||||
|
if (message?.reactions) {
|
||||||
|
message.reactions = message.reactions?.filter(
|
||||||
|
(reaction) =>
|
||||||
|
!(
|
||||||
|
reaction.emoji.id === payload.emoji.id &&
|
||||||
|
reaction.emoji.name === payload.emoji.name
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
eventHandlers.reactionRemoveEmoji?.(
|
||||||
|
data.d as MessageReactionRemoveEmojiPayload,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, MessageCreateOptions } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleMessageUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as MessageCreateOptions;
|
||||||
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const cachedMessage = await cacheHandlers.get("messages", payload.id);
|
||||||
|
if (!cachedMessage) return;
|
||||||
|
|
||||||
|
const oldMessage = {
|
||||||
|
attachments: cachedMessage.attachments,
|
||||||
|
content: cachedMessage.content,
|
||||||
|
embeds: cachedMessage.embeds,
|
||||||
|
editedTimestamp: cachedMessage.editedTimestamp,
|
||||||
|
tts: cachedMessage.tts,
|
||||||
|
pinned: cachedMessage.pinned,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Messages with embeds can trigger update but they wont have edited_timestamp
|
||||||
|
if (
|
||||||
|
!payload.edited_timestamp ||
|
||||||
|
(cachedMessage.content === payload.content)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = await structures.createMessageStruct(payload);
|
||||||
|
|
||||||
|
await cacheHandlers.set("messages", payload.id, message);
|
||||||
|
|
||||||
|
eventHandlers.messageUpdate?.(message, oldMessage);
|
||||||
|
}
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
DiscordPayload,
|
|
||||||
IntegrationCreateUpdateEvent,
|
|
||||||
IntegrationDeleteEvent,
|
|
||||||
InviteCreateEvent,
|
|
||||||
InviteDeleteEvent,
|
|
||||||
PresenceUpdatePayload,
|
|
||||||
TypingStartPayload,
|
|
||||||
UserPayload,
|
|
||||||
VoiceStateUpdatePayload,
|
|
||||||
WebhookUpdatePayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
/** This function is the internal handler for the presence update event. Users can override this with controllers if desired. */
|
|
||||||
export async function handleInternalPresenceUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as PresenceUpdatePayload;
|
|
||||||
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
|
||||||
await cacheHandlers.set("presences", payload.user.id, payload);
|
|
||||||
|
|
||||||
eventHandlers.presenceUpdate?.(payload, oldPresence);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This function is the internal handler for the typings event. Users can override this with controllers if desired. */
|
|
||||||
export function handleInternalTypingStart(data: DiscordPayload) {
|
|
||||||
eventHandlers.typingStart?.(data.d as TypingStartPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This function is the internal handler for the user update event. Users can override this with controllers if desired. */
|
|
||||||
export async function handleInternalUserUpdate(data: DiscordPayload) {
|
|
||||||
const userData = data.d as UserPayload;
|
|
||||||
|
|
||||||
const member = await cacheHandlers.get("members", userData.id);
|
|
||||||
if (!member) return;
|
|
||||||
|
|
||||||
Object.entries(userData).forEach(([key, value]) => {
|
|
||||||
// @ts-ignore index signatures
|
|
||||||
if (member[key] !== value) return member[key] = value;
|
|
||||||
});
|
|
||||||
|
|
||||||
await cacheHandlers.set("members", userData.id, member);
|
|
||||||
|
|
||||||
eventHandlers.botUpdate?.(userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This function is the internal handler for the voice state update event. Users can override this with controllers if desired. */
|
|
||||||
export async function handleInternalVoiceStateUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as VoiceStateUpdatePayload;
|
|
||||||
if (!payload.guild_id) return;
|
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const member = payload.member
|
|
||||||
? await structures.createMemberStruct(payload.member, guild.id)
|
|
||||||
: await cacheHandlers.get("members", payload.user_id);
|
|
||||||
if (!member) return;
|
|
||||||
|
|
||||||
// No cached state before so lets make one for em
|
|
||||||
const cachedState = guild.voiceStates.get(payload.user_id);
|
|
||||||
|
|
||||||
guild.voiceStates.set(payload.user_id, {
|
|
||||||
...payload,
|
|
||||||
guildID: payload.guild_id,
|
|
||||||
channelID: payload.channel_id || "",
|
|
||||||
userID: payload.user_id,
|
|
||||||
sessionID: payload.session_id,
|
|
||||||
selfDeaf: payload.self_deaf,
|
|
||||||
selfMute: payload.self_mute,
|
|
||||||
selfStream: payload.self_stream || false,
|
|
||||||
});
|
|
||||||
|
|
||||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
|
||||||
|
|
||||||
if (cachedState?.channelID !== payload.channel_id) {
|
|
||||||
// Either joined or moved channels
|
|
||||||
if (payload.channel_id) {
|
|
||||||
if (cachedState?.channelID) { // Was in a channel before
|
|
||||||
eventHandlers.voiceChannelSwitch?.(
|
|
||||||
member,
|
|
||||||
payload.channel_id,
|
|
||||||
cachedState.channelID,
|
|
||||||
);
|
|
||||||
} else { // Was not in a channel before so user just joined
|
|
||||||
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
|
||||||
}
|
|
||||||
} // Left the channel
|
|
||||||
else if (cachedState?.channelID) {
|
|
||||||
guild.voiceStates.delete(payload.user_id);
|
|
||||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventHandlers.voiceStateUpdate?.(member, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This function is the internal handler for the webhooks update event. Users can override this with controllers if desired. */
|
|
||||||
export function handleInternalWebhooksUpdate(data: DiscordPayload) {
|
|
||||||
const options = data.d as WebhookUpdatePayload;
|
|
||||||
eventHandlers.webhooksUpdate?.(
|
|
||||||
options.channel_id,
|
|
||||||
options.guild_id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalIntegrationCreate(
|
|
||||||
data: DiscordPayload,
|
|
||||||
) {
|
|
||||||
const {
|
|
||||||
guild_id: guildID,
|
|
||||||
enable_emoticons: enableEmoticons,
|
|
||||||
expire_behavior: expireBehavior,
|
|
||||||
expire_grace_period: expireGracePeriod,
|
|
||||||
subscriber_count: subscriberCount,
|
|
||||||
role_id: roleID,
|
|
||||||
synced_at: syncedAt,
|
|
||||||
...rest
|
|
||||||
} = data.d as IntegrationCreateUpdateEvent;
|
|
||||||
|
|
||||||
eventHandlers.integrationCreate?.({
|
|
||||||
...rest,
|
|
||||||
guildID,
|
|
||||||
enableEmoticons,
|
|
||||||
expireBehavior,
|
|
||||||
expireGracePeriod,
|
|
||||||
syncedAt,
|
|
||||||
subscriberCount,
|
|
||||||
roleID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalIntegrationUpdate(data: DiscordPayload) {
|
|
||||||
const {
|
|
||||||
enable_emoticons: enableEmoticons,
|
|
||||||
expire_behavior: expireBehavior,
|
|
||||||
expire_grace_period: expireGracePeriod,
|
|
||||||
role_id: roleID,
|
|
||||||
subscriber_count: subscriberCount,
|
|
||||||
synced_at: syncedAt,
|
|
||||||
guild_id: guildID,
|
|
||||||
...rest
|
|
||||||
} = data.d as IntegrationCreateUpdateEvent;
|
|
||||||
|
|
||||||
eventHandlers.integrationUpdate?.({
|
|
||||||
...rest,
|
|
||||||
guildID,
|
|
||||||
subscriberCount,
|
|
||||||
enableEmoticons,
|
|
||||||
expireGracePeriod,
|
|
||||||
roleID,
|
|
||||||
expireBehavior,
|
|
||||||
syncedAt,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalIntegrationDelete(data: DiscordPayload) {
|
|
||||||
const {
|
|
||||||
guild_id: guildID,
|
|
||||||
application_id: applicationID,
|
|
||||||
...rest
|
|
||||||
} = data.d as IntegrationDeleteEvent;
|
|
||||||
|
|
||||||
eventHandlers.integrationDelete?.({
|
|
||||||
...rest,
|
|
||||||
applicationID,
|
|
||||||
guildID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalInviteCreate(payload: DiscordPayload) {
|
|
||||||
if (payload.t !== "INVITE_CREATE") return;
|
|
||||||
//TODO: replace with tocamelcase
|
|
||||||
const {
|
|
||||||
channel_id: channelID,
|
|
||||||
created_at: createdAt,
|
|
||||||
max_age: maxAge,
|
|
||||||
guild_id: guildID,
|
|
||||||
target_user: targetUser,
|
|
||||||
target_user_type: targetUserType,
|
|
||||||
max_uses: maxUses,
|
|
||||||
...rest
|
|
||||||
} = payload.d as InviteCreateEvent;
|
|
||||||
|
|
||||||
eventHandlers.inviteCreate?.({
|
|
||||||
...rest,
|
|
||||||
channelID,
|
|
||||||
guildID,
|
|
||||||
maxAge,
|
|
||||||
targetUser,
|
|
||||||
targetUserType,
|
|
||||||
maxUses,
|
|
||||||
createdAt,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleInternalInviteDelete(payload: DiscordPayload) {
|
|
||||||
if (payload.t !== "INVITE_DELETE") return;
|
|
||||||
|
|
||||||
const {
|
|
||||||
channel_id: channelID,
|
|
||||||
guild_id: guildID,
|
|
||||||
...rest
|
|
||||||
} = payload.d as InviteDeleteEvent;
|
|
||||||
|
|
||||||
eventHandlers.inviteDelete?.({
|
|
||||||
...rest,
|
|
||||||
channelID,
|
|
||||||
guildID,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
+134
-99
@@ -1,107 +1,142 @@
|
|||||||
import {
|
import { handleChannelCreate } from "./channels/CHANNEL_CREATE.ts";
|
||||||
handleInternalGuildBanAdd,
|
import { handleChannelDelete } from "./channels/CHANNEL_DELETE.ts";
|
||||||
handleInternalGuildBanRemove,
|
import { handleChannelPinsUpdate } from "./channels/CHANNEL_PINS_UPDATE.ts";
|
||||||
} from "./bans.ts";
|
import { handleChannelUpdate } from "./channels/CHANNEL_UPDATE.ts";
|
||||||
import {
|
import { handleApplicationCommandCreate } from "./commands/APPLICATION_COMMAND_CREATE.ts";
|
||||||
handleInternalChannelCreate,
|
import { handleApplicationCommandDelete } from "./commands/APPLICATION_COMMAND_DELETE.ts";
|
||||||
handleInternalChannelDelete,
|
import { handleApplicationCommandUpdate } from "./commands/APPLICATION_COMMAND_UPDATE.ts";
|
||||||
handleInternalChannelUpdate,
|
import { handleGuildBanAdd } from "./guilds/GUILD_BAN_ADD.ts";
|
||||||
} from "./channels.ts";
|
import { handleGuildBanRemove } from "./guilds/GUILD_BAN_REMOVE.ts";
|
||||||
import { handleChannelPinsUpdate } from "./CHANNEL_PINS_UPDATE.ts";
|
import { handleGuildCreate } from "./guilds/GUILD_CREATE.ts";
|
||||||
import {
|
import { handleGuildDelete } from "./guilds/GUILD_DELETE.ts";
|
||||||
handleInternalGuildCreate,
|
import { handleGuildEmojisUpdate } from "./guilds/GUILD_EMOJIS_UPDATE.ts";
|
||||||
handleInternalGuildDelete,
|
import { handleGuildIntegrationsUpdate } from "./guilds/GUILD_INTEGRATIONS_UPDATE.ts";
|
||||||
handleInternalGuildEmojisUpdate,
|
import { handleGuildMembersChunk } from "./guilds/GUILD_MEMBERS_CHUNK.ts";
|
||||||
handleInternalGuildUpdate,
|
import { handleGuildMemberAdd } from "./guilds/GUILD_MEMBER_ADD.ts";
|
||||||
} from "./guilds.ts";
|
import { handleGuildMemberRemove } from "./guilds/GUILD_MEMBER_REMOVE.ts";
|
||||||
import { handleGuildIntegrationsUpdate } from "./GUILD_INTEGRATIONS_UPDATE.ts";
|
import { handleGuildMemberUpdate } from "./guilds/GUILD_MEMBER_UPDATE.ts";
|
||||||
import {
|
import { handleGuildRoleCreate } from "./guilds/GUILD_ROLE_CREATE.ts";
|
||||||
handleInternalApplicationCommandCreate,
|
import { handleGuildRoleDelete } from "./guilds/GUILD_ROLE_DELETE.ts";
|
||||||
handleInternalApplicationCommandDelete,
|
import { handleGuildRoleUpdate } from "./guilds/GUILD_ROLE_UPDATE.ts";
|
||||||
handleInternalApplicationCommandUpdate,
|
import { handleGuildUpdate } from "./guilds/GUILD_UPDATE.ts";
|
||||||
handleInternalInteractionCreate,
|
import { handleIntegrationCreate } from "./integrations/INTEGRATION_CREATE.ts";
|
||||||
} from "./interactions.ts";
|
import { handleIntegrationDelete } from "./integrations/INTEGRATION_DELETE.ts";
|
||||||
import {
|
import { handleIntegrationUpdate } from "./integrations/INTEGRATION_UPDATE.ts";
|
||||||
handleInternalGuildMemberAdd,
|
import { handleInteractionCreate } from "./interactions/INTERACTION_CREATE.ts";
|
||||||
handleInternalGuildMemberRemove,
|
import { handleInviteCreate } from "./invites/INVITE_CREATE.ts";
|
||||||
handleInternalGuildMembersChunk,
|
import { handleMessageCreate } from "./messages/MESSAGE_CREATE.ts";
|
||||||
handleInternalGuildMemberUpdate,
|
import { handleMessageDelete } from "./messages/MESSAGE_DELETE.ts";
|
||||||
} from "./members.ts";
|
import { handleMessageDeleteBulk } from "./messages/MESSAGE_DELETE_BULK.ts";
|
||||||
import {
|
import { handleMessageReactionAdd } from "./messages/MESSAGE_REACTION_ADD.ts";
|
||||||
handleInternalMessageCreate,
|
import { handleMessageReactionRemove } from "./messages/MESSAGE_REACTION_REMOVE.ts";
|
||||||
handleInternalMessageDelete,
|
import { handleMessageReactionRemoveAll } from "./messages/MESSAGE_REACTION_REMOVE_ALL.ts";
|
||||||
handleInternalMessageDeleteBulk,
|
import { handleMessageReactionRemoveEmoji } from "./messages/MESSAGE_REACTION_REMOVE_EMOJI.ts";
|
||||||
handleInternalMessageUpdate,
|
import { handleMessageUpdate } from "./messages/MESSAGE_UPDATE.ts";
|
||||||
} from "./messages.ts";
|
import { handlePresenceUpdate } from "./presence/PRESENCE_UPDATE.ts";
|
||||||
import {
|
import { handleTypingStart } from "./presence/TYPING_START.ts";
|
||||||
handleInternalIntegrationCreate,
|
import { handleUserUpdate } from "./presence/USER_UPDATE.ts";
|
||||||
handleInternalIntegrationDelete,
|
import { handleReady } from "./READY.ts";
|
||||||
handleInternalIntegrationUpdate,
|
import { handleVoiceServerUpdate } from "./voice/VOICE_SERVER_UPDATE.ts";
|
||||||
handleInternalInviteCreate,
|
import { handleVoiceStateUpdate } from "./voice/VOICE_STATE_UPDATE.ts";
|
||||||
handleInternalInviteDelete,
|
import { handleWebhooksUpdate } from "./webhooks/WEBHOOKS_UPDATE.ts";
|
||||||
handleInternalPresenceUpdate,
|
|
||||||
handleInternalTypingStart,
|
export {
|
||||||
handleInternalUserUpdate,
|
handleApplicationCommandCreate,
|
||||||
handleInternalVoiceStateUpdate,
|
handleApplicationCommandDelete,
|
||||||
handleInternalWebhooksUpdate,
|
handleApplicationCommandUpdate,
|
||||||
} from "./misc.ts";
|
handleChannelCreate,
|
||||||
import {
|
handleChannelDelete,
|
||||||
handleInternalMessageReactionAdd,
|
handleChannelPinsUpdate,
|
||||||
handleInternalMessageReactionRemove,
|
handleChannelUpdate,
|
||||||
handleInternalMessageReactionRemoveAll,
|
handleGuildBanAdd,
|
||||||
handleInternalMessageReactionRemoveEmoji,
|
handleGuildBanRemove,
|
||||||
} from "./reactions.ts";
|
handleGuildCreate,
|
||||||
import { handleInternalReady } from "./READY.ts";
|
handleGuildDelete,
|
||||||
import {
|
handleGuildEmojisUpdate,
|
||||||
handleInternalGuildRoleCreate,
|
handleGuildIntegrationsUpdate,
|
||||||
handleInternalGuildRoleDelete,
|
handleGuildMemberAdd,
|
||||||
handleInternalGuildRoleUpdate,
|
handleGuildMemberRemove,
|
||||||
} from "./roles.ts";
|
handleGuildMembersChunk,
|
||||||
import { handleVoiceServerUpdate } from "./VOICE_SERVER_UPDATE.ts";
|
handleGuildMemberUpdate,
|
||||||
|
handleGuildRoleCreate,
|
||||||
|
handleGuildRoleDelete,
|
||||||
|
handleGuildRoleUpdate,
|
||||||
|
handleGuildUpdate,
|
||||||
|
handleIntegrationCreate,
|
||||||
|
handleIntegrationDelete,
|
||||||
|
handleIntegrationUpdate,
|
||||||
|
handleInteractionCreate,
|
||||||
|
handleInviteCreate,
|
||||||
|
handleMessageCreate,
|
||||||
|
handleMessageDelete,
|
||||||
|
handleMessageDeleteBulk,
|
||||||
|
handleMessageReactionAdd,
|
||||||
|
handleMessageReactionRemove,
|
||||||
|
handleMessageReactionRemoveAll,
|
||||||
|
handleMessageReactionRemoveEmoji,
|
||||||
|
handleMessageUpdate,
|
||||||
|
handlePresenceUpdate,
|
||||||
|
handleReady,
|
||||||
|
handleTypingStart,
|
||||||
|
handleUserUpdate,
|
||||||
|
handleVoiceServerUpdate,
|
||||||
|
handleVoiceStateUpdate,
|
||||||
|
handleWebhooksUpdate,
|
||||||
|
};
|
||||||
|
|
||||||
export let controllers = {
|
export let controllers = {
|
||||||
READY: handleInternalReady,
|
READY: handleReady,
|
||||||
CHANNEL_CREATE: handleInternalChannelCreate,
|
// channels
|
||||||
CHANNEL_DELETE: handleInternalChannelDelete,
|
CHANNEL_CREATE: handleChannelCreate,
|
||||||
CHANNEL_UPDATE: handleInternalChannelUpdate,
|
CHANNEL_DELETE: handleChannelDelete,
|
||||||
CHANNEL_PINS_UPDATE: handleChannelPinsUpdate,
|
CHANNEL_PINS_UPDATE: handleChannelPinsUpdate,
|
||||||
GUILD_CREATE: handleInternalGuildCreate,
|
CHANNEL_UPDATE: handleChannelUpdate,
|
||||||
GUILD_DELETE: handleInternalGuildDelete,
|
// commands
|
||||||
GUILD_UPDATE: handleInternalGuildUpdate,
|
APPLICATION_COMMAND_CREATE: handleApplicationCommandCreate,
|
||||||
GUILD_BAN_ADD: handleInternalGuildBanAdd,
|
APPLICATION_COMMAND_DELETE: handleApplicationCommandDelete,
|
||||||
GUILD_BAN_REMOVE: handleInternalGuildBanRemove,
|
APPLICATION_COMMAND_UPDATE: handleApplicationCommandUpdate,
|
||||||
GUILD_EMOJIS_UPDATE: handleInternalGuildEmojisUpdate,
|
// guilds
|
||||||
|
GUILD_BAN_ADD: handleGuildBanAdd,
|
||||||
|
GUILD_BAN_REMOVE: handleGuildBanRemove,
|
||||||
|
GUILD_CREATE: handleGuildCreate,
|
||||||
|
GUILD_DELETE: handleGuildDelete,
|
||||||
|
GUILD_EMOJIS_UPDATE: handleGuildEmojisUpdate,
|
||||||
GUILD_INTEGRATIONS_UPDATE: handleGuildIntegrationsUpdate,
|
GUILD_INTEGRATIONS_UPDATE: handleGuildIntegrationsUpdate,
|
||||||
GUILD_MEMBER_ADD: handleInternalGuildMemberAdd,
|
GUILD_MEMBER_ADD: handleGuildMemberAdd,
|
||||||
GUILD_MEMBER_REMOVE: handleInternalGuildMemberRemove,
|
GUILD_MEMBER_REMOVE: handleGuildMemberRemove,
|
||||||
GUILD_MEMBER_UPDATE: handleInternalGuildMemberUpdate,
|
GUILD_MEMBER_UPDATE: handleGuildMemberUpdate,
|
||||||
GUILD_MEMBERS_CHUNK: handleInternalGuildMembersChunk,
|
GUILD_MEMBERS_CHUNK: handleGuildMembersChunk,
|
||||||
GUILD_ROLE_CREATE: handleInternalGuildRoleCreate,
|
GUILD_ROLE_CREATE: handleGuildRoleCreate,
|
||||||
GUILD_ROLE_DELETE: handleInternalGuildRoleDelete,
|
GUILD_ROLE_DELETE: handleGuildRoleDelete,
|
||||||
GUILD_ROLE_UPDATE: handleInternalGuildRoleUpdate,
|
GUILD_ROLE_UPDATE: handleGuildRoleUpdate,
|
||||||
INTERACTION_CREATE: handleInternalInteractionCreate,
|
GUILD_UPDATE: handleGuildUpdate,
|
||||||
APPLICATION_COMMAND_CREATE: handleInternalApplicationCommandCreate,
|
// interactions
|
||||||
APPLICATION_COMMAND_DELETE: handleInternalApplicationCommandDelete,
|
INTERACTION_CREATE: handleInteractionCreate,
|
||||||
APPLICATION_COMMAND_UPDATE: handleInternalApplicationCommandUpdate,
|
// invites
|
||||||
MESSAGE_CREATE: handleInternalMessageCreate,
|
INVITE_CREATE: handleInviteCreate,
|
||||||
MESSAGE_DELETE: handleInternalMessageDelete,
|
INVITE_DELETE: handleInviteCreate,
|
||||||
MESSAGE_DELETE_BULK: handleInternalMessageDeleteBulk,
|
// messages
|
||||||
MESSAGE_UPDATE: handleInternalMessageUpdate,
|
MESSAGE_CREATE: handleMessageCreate,
|
||||||
MESSAGE_REACTION_ADD: handleInternalMessageReactionAdd,
|
MESSAGE_DELETE_BULK: handleMessageDeleteBulk,
|
||||||
MESSAGE_REACTION_REMOVE: handleInternalMessageReactionRemove,
|
MESSAGE_DELETE: handleMessageDelete,
|
||||||
MESSAGE_REACTION_REMOVE_ALL: handleInternalMessageReactionRemoveAll,
|
MESSAGE_REACTION_ADD: handleMessageReactionAdd,
|
||||||
MESSAGE_REACTION_REMOVE_EMOJI: handleInternalMessageReactionRemoveEmoji,
|
MESSAGE_REACTION_REMOVE_ALL: handleMessageReactionRemoveAll,
|
||||||
PRESENCE_UPDATE: handleInternalPresenceUpdate,
|
MESSAGE_REACTION_REMOVE_EMOJI: handleMessageReactionRemoveEmoji,
|
||||||
TYPING_START: handleInternalTypingStart,
|
MESSAGE_REACTION_REMOVE: handleMessageReactionRemove,
|
||||||
USER_UPDATE: handleInternalUserUpdate,
|
MESSAGE_UPDATE: handleMessageUpdate,
|
||||||
VOICE_STATE_UPDATE: handleInternalVoiceStateUpdate,
|
// presence
|
||||||
|
PRESENCE_UPDATE: handlePresenceUpdate,
|
||||||
|
TYPING_START: handleTypingStart,
|
||||||
|
USER_UPDATE: handleUserUpdate,
|
||||||
|
// voice
|
||||||
VOICE_SERVER_UPDATE: handleVoiceServerUpdate,
|
VOICE_SERVER_UPDATE: handleVoiceServerUpdate,
|
||||||
WEBHOOKS_UPDATE: handleInternalWebhooksUpdate,
|
VOICE_STATE_UPDATE: handleVoiceStateUpdate,
|
||||||
INTEGRATION_CREATE: handleInternalIntegrationCreate,
|
// webhooks
|
||||||
INTEGRATION_UPDATE: handleInternalIntegrationUpdate,
|
WEBHOOKS_UPDATE: handleWebhooksUpdate,
|
||||||
INTEGRATION_DELETE: handleInternalIntegrationDelete,
|
// integrations
|
||||||
INVITE_CREATE: handleInternalInviteCreate,
|
INTEGRATION_CREATE: handleIntegrationCreate,
|
||||||
INVITE_DELETE: handleInternalInviteDelete,
|
INTEGRATION_UPDATE: handleIntegrationUpdate,
|
||||||
|
INTEGRATION_DELETE: handleIntegrationDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Controllers = typeof controllers;
|
export type Controllers = typeof controllers;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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;
|
||||||
|
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
||||||
|
await cacheHandlers.set("presences", payload.user.id, payload);
|
||||||
|
|
||||||
|
eventHandlers.presenceUpdate?.(payload, oldPresence);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
const member = await cacheHandlers.get("members", userData.id);
|
||||||
|
if (!member) return;
|
||||||
|
|
||||||
|
Object.entries(userData).forEach(([key, value]) => {
|
||||||
|
// @ts-ignore index signatures
|
||||||
|
if (member[key] !== value) return member[key] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
await cacheHandlers.set("members", userData.id, member);
|
||||||
|
|
||||||
|
eventHandlers.botUpdate?.(userData);
|
||||||
|
}
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import { botID, eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
BaseMessageReactionPayload,
|
|
||||||
DiscordPayload,
|
|
||||||
MessageReactionPayload,
|
|
||||||
MessageReactionRemoveEmojiPayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalMessageReactionAdd(data: DiscordPayload) {
|
|
||||||
const payload = data.d as MessageReactionPayload;
|
|
||||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
|
||||||
|
|
||||||
if (message) {
|
|
||||||
const reactionExisted = message.reactions?.find(
|
|
||||||
(reaction) =>
|
|
||||||
reaction.emoji.id === payload.emoji.id &&
|
|
||||||
reaction.emoji.name === payload.emoji.name,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (reactionExisted) reactionExisted.count++;
|
|
||||||
else {
|
|
||||||
const newReaction = {
|
|
||||||
count: 1,
|
|
||||||
me: payload.user_id === botID,
|
|
||||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
|
||||||
};
|
|
||||||
message.reactions = message.reactions
|
|
||||||
? [...message.reactions, newReaction]
|
|
||||||
: [newReaction];
|
|
||||||
}
|
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.member && payload.guild_id) {
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (guild) {
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
payload.member,
|
|
||||||
guild.id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const uncachedOptions = {
|
|
||||||
...payload,
|
|
||||||
id: payload.message_id,
|
|
||||||
channelID: payload.channel_id,
|
|
||||||
guildID: payload.guild_id || "",
|
|
||||||
};
|
|
||||||
|
|
||||||
eventHandlers.reactionAdd?.(
|
|
||||||
uncachedOptions,
|
|
||||||
payload.emoji,
|
|
||||||
payload.user_id,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageReactionRemove(
|
|
||||||
data: DiscordPayload,
|
|
||||||
) {
|
|
||||||
const payload = data.d as MessageReactionPayload;
|
|
||||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
|
||||||
|
|
||||||
if (message) {
|
|
||||||
const reactionExisted = message.reactions?.find(
|
|
||||||
(reaction) =>
|
|
||||||
reaction.emoji.id === payload.emoji.id &&
|
|
||||||
reaction.emoji.name === payload.emoji.name,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (reactionExisted) reactionExisted.count--;
|
|
||||||
else {
|
|
||||||
const newReaction = {
|
|
||||||
count: 1,
|
|
||||||
me: payload.user_id === botID,
|
|
||||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
|
||||||
};
|
|
||||||
message.reactions = message.reactions
|
|
||||||
? [...message.reactions, newReaction]
|
|
||||||
: [newReaction];
|
|
||||||
}
|
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.member && payload.guild_id) {
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (guild) {
|
|
||||||
const memberStruct = await structures.createMemberStruct(
|
|
||||||
payload.member,
|
|
||||||
guild.id,
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const uncachedOptions = {
|
|
||||||
...payload,
|
|
||||||
id: payload.message_id,
|
|
||||||
channelID: payload.channel_id,
|
|
||||||
guildID: payload.guild_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
eventHandlers.reactionRemove?.(
|
|
||||||
uncachedOptions,
|
|
||||||
payload.emoji,
|
|
||||||
payload.user_id,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageReactionRemoveAll(
|
|
||||||
data: DiscordPayload,
|
|
||||||
) {
|
|
||||||
const payload = data.d as BaseMessageReactionPayload;
|
|
||||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
|
||||||
|
|
||||||
if (message?.reactions) {
|
|
||||||
message.reactions = undefined;
|
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventHandlers.reactionRemoveAll?.(data.d as BaseMessageReactionPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalMessageReactionRemoveEmoji(
|
|
||||||
data: DiscordPayload,
|
|
||||||
) {
|
|
||||||
const payload = data.d as MessageReactionRemoveEmojiPayload;
|
|
||||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
|
||||||
|
|
||||||
if (message?.reactions) {
|
|
||||||
message.reactions = message.reactions?.filter(
|
|
||||||
(reaction) =>
|
|
||||||
!(
|
|
||||||
reaction.emoji.id === payload.emoji.id &&
|
|
||||||
reaction.emoji.name === payload.emoji.name
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventHandlers.reactionRemoveEmoji?.(
|
|
||||||
data.d as MessageReactionRemoveEmojiPayload,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
|
||||||
import {
|
|
||||||
DiscordPayload,
|
|
||||||
GuildRoleDeletePayload,
|
|
||||||
GuildRolePayload,
|
|
||||||
} from "../../types/mod.ts";
|
|
||||||
import { structures } from "../structures/mod.ts";
|
|
||||||
import { cacheHandlers } from "./cache.ts";
|
|
||||||
|
|
||||||
export async function handleInternalGuildRoleCreate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildRolePayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const role = await structures.createRoleStruct(payload.role);
|
|
||||||
guild.roles = guild.roles.set(payload.role.id, role);
|
|
||||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
|
||||||
|
|
||||||
eventHandlers.roleCreate?.(guild, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildRoleDelete(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildRoleDeletePayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const cachedRole = guild.roles.get(payload.role_id)!;
|
|
||||||
guild.roles.delete(payload.role_id);
|
|
||||||
|
|
||||||
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
|
|
||||||
|
|
||||||
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
|
|
||||||
cacheHandlers.forEach("members", (member) => {
|
|
||||||
// Not in the relevant guild so just skip.
|
|
||||||
if (!member.guilds.has(guild.id)) return;
|
|
||||||
|
|
||||||
member.guilds.forEach((g) => {
|
|
||||||
// Member does not have this role
|
|
||||||
if (!g.roles.includes(payload.role_id)) return;
|
|
||||||
// Remove this role from the members cache
|
|
||||||
g.roles = g.roles.filter((id) => id !== payload.role_id);
|
|
||||||
cacheHandlers.set("members", member.id, member);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleInternalGuildRoleUpdate(data: DiscordPayload) {
|
|
||||||
const payload = data.d as GuildRolePayload;
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const cachedRole = guild.roles.get(payload.role.id);
|
|
||||||
if (!cachedRole) return;
|
|
||||||
|
|
||||||
const role = await structures.createRoleStruct(payload.role);
|
|
||||||
guild.roles.set(payload.role.id, role);
|
|
||||||
await cacheHandlers.set("guilds", guild.id, guild);
|
|
||||||
|
|
||||||
eventHandlers.roleUpdate?.(guild, role, cachedRole);
|
|
||||||
}
|
|
||||||
+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;
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, VoiceStateUpdatePayload } from "../../../types/mod.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
|
|
||||||
|
export async function handleVoiceStateUpdate(data: DiscordPayload) {
|
||||||
|
const payload = data.d as VoiceStateUpdatePayload;
|
||||||
|
if (!payload.guild_id) return;
|
||||||
|
|
||||||
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const member = payload.member
|
||||||
|
? await structures.createMemberStruct(payload.member, guild.id)
|
||||||
|
: await cacheHandlers.get("members", payload.user_id);
|
||||||
|
if (!member) return;
|
||||||
|
|
||||||
|
// No cached state before so lets make one for em
|
||||||
|
const cachedState = guild.voiceStates.get(payload.user_id);
|
||||||
|
|
||||||
|
guild.voiceStates.set(payload.user_id, {
|
||||||
|
...payload,
|
||||||
|
guildID: payload.guild_id,
|
||||||
|
channelID: payload.channel_id || "",
|
||||||
|
userID: payload.user_id,
|
||||||
|
sessionID: payload.session_id,
|
||||||
|
selfDeaf: payload.self_deaf,
|
||||||
|
selfMute: payload.self_mute,
|
||||||
|
selfStream: payload.self_stream || false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||||
|
|
||||||
|
if (cachedState?.channelID !== payload.channel_id) {
|
||||||
|
// Either joined or moved channels
|
||||||
|
if (payload.channel_id) {
|
||||||
|
if (cachedState?.channelID) { // Was in a channel before
|
||||||
|
eventHandlers.voiceChannelSwitch?.(
|
||||||
|
member,
|
||||||
|
payload.channel_id,
|
||||||
|
cachedState.channelID,
|
||||||
|
);
|
||||||
|
} else { // Was not in a channel before so user just joined
|
||||||
|
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
||||||
|
}
|
||||||
|
} // Left the channel
|
||||||
|
else if (cachedState?.channelID) {
|
||||||
|
guild.voiceStates.delete(payload.user_id);
|
||||||
|
eventHandlers.voiceChannelLeave?.(member, cachedState.channelID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eventHandlers.voiceStateUpdate?.(member, payload);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { eventHandlers } from "../../../bot.ts";
|
||||||
|
import { DiscordPayload, WebhookUpdatePayload } from "../../../types/mod.ts";
|
||||||
|
|
||||||
|
export function handleWebhooksUpdate(data: DiscordPayload) {
|
||||||
|
const options = data.d as WebhookUpdatePayload;
|
||||||
|
eventHandlers.webhooksUpdate?.(
|
||||||
|
options.channel_id,
|
||||||
|
options.guild_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
botHasPermission,
|
botHasPermission,
|
||||||
calculateBits,
|
calculateBits,
|
||||||
} from "../../util/permissions.ts";
|
} from "../../util/permissions.ts";
|
||||||
import { cacheHandlers } from "../controllers/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 */
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import {
|
|||||||
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 "../controllers/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. */
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
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 "../controllers/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";
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ 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 "../controllers/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. */
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
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 "../controllers/cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import {
|
import {
|
||||||
ban,
|
ban,
|
||||||
deleteServer,
|
deleteServer,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
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 "../controllers/cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { ban } from "../handlers/guild.ts";
|
import { ban } from "../handlers/guild.ts";
|
||||||
import {
|
import {
|
||||||
addRole,
|
addRole,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
} 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 "../controllers/cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { sendMessage } from "../handlers/channel.ts";
|
import { sendMessage } from "../handlers/channel.ts";
|
||||||
import { sendDirectMessage } from "../handlers/member.ts";
|
import { sendDirectMessage } from "../handlers/member.ts";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// deno-lint-ignore-file require-await no-explicit-any prefer-const
|
// deno-lint-ignore-file require-await no-explicit-any prefer-const
|
||||||
|
|
||||||
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 "../structures/mod.ts";
|
import { Channel, Guild, Member, Message } from "./api/structures/mod.ts";
|
||||||
|
|
||||||
export type TableName =
|
export type TableName =
|
||||||
| "guilds"
|
| "guilds"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { cacheHandlers } from "../api/controllers/cache.ts";
|
import { cacheHandlers } from "../cache.ts";
|
||||||
import { Guild, Role } from "../api/structures/mod.ts";
|
import { Guild, Role } from "../api/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";
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
DiscordPayload,
|
DiscordPayload,
|
||||||
FetchMembersOptions,
|
FetchMembersOptions,
|
||||||
GatewayOpcode,
|
GatewayOpcode,
|
||||||
GatewayStatusUpdatePayload,
|
|
||||||
} 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";
|
||||||
|
|||||||
Reference in New Issue
Block a user