mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
autoconvert handler messages
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordChannel } from "../../types/channels/channel.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleChannelCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
const payload = data.d as Channel;
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordChannel } from "../../types/channels/channel.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
const payload = data.d as Channel;
|
||||
|
||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
if (
|
||||
cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guild_id
|
||||
cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId
|
||||
) {
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
|
||||
if (guild) {
|
||||
return Promise.all(guild.voiceStates.map(async (vs, key) => {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
|
||||
import { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannelPinsUpdate;
|
||||
const payload = data.d as ChannelPinsUpdate;
|
||||
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (!channel) return;
|
||||
|
||||
const guild = payload.guild_id
|
||||
? await cacheHandlers.get("guilds", payload.guild_id)
|
||||
const guild = payload.guildId
|
||||
? await cacheHandlers.get("guilds", payload.guildId)
|
||||
: undefined;
|
||||
|
||||
eventHandlers.channelPinsUpdate?.(channel, guild, payload.last_pin_timestamp);
|
||||
eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordChannel } from "../../types/channels/channel.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
const payload = data.d as Channel;
|
||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||
|
||||
@@ -2,16 +2,12 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
DiscordApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export function handleApplicationCommandCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
eventHandlers.applicationCommandCreate?.(
|
||||
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||
),
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
DiscordApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.applicationCommandDelete?.(
|
||||
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||
),
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
DiscordApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.applicationCommandUpdate?.(
|
||||
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||
),
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
|
||||
import { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildEmojisUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildEmojisUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedEmojis = guild.emojis;
|
||||
@@ -14,7 +14,7 @@ export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||
payload.emojis.map((emoji) => [emoji.id!, emoji]),
|
||||
);
|
||||
|
||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
await cacheHandlers.set("guilds", payload.guildId, guild);
|
||||
|
||||
eventHandlers.guildEmojisUpdate?.(
|
||||
guild,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
|
||||
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const member = await cacheHandlers.get("members", payload.user.id);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
|
||||
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const member = await cacheHandlers.get("members", payload.user.id);
|
||||
|
||||
@@ -2,14 +2,14 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export async function handleGuildCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
const payload = data.d as Guild;
|
||||
// When shards resume they emit GUILD_CREATE again.
|
||||
if (await cacheHandlers.has("guilds", payload.id)) return;
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordUnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
||||
import { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export async function handleGuildDelete(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
) {
|
||||
const payload = data.d as DiscordUnavailableGuild;
|
||||
const payload = data.d as UnavailableGuild;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.id);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts";
|
||||
import { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts";
|
||||
|
||||
export async function handleGuildIntegrationsUpdate(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
const payload = data.d as DiscordGuildIntegrationsUpdate;
|
||||
const payload = data.d as GuildIntegrationsUpdate;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
eventHandlers.guildIntegrationsUpdate?.(guild);
|
||||
|
||||
@@ -2,10 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuild } from "../../types/guilds/guild.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
|
||||
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
const payload = data.d as Guild;
|
||||
const newGuild = await cacheHandlers.get("guilds", payload.id);
|
||||
if (!newGuild) return;
|
||||
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordIntegrationCreateUpdate,
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integration/integration_create_update.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export function handleIntegrationCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
eventHandlers.integrationCreate?.(
|
||||
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||
data.d as DiscordIntegrationCreateUpdate,
|
||||
),
|
||||
data.d as IntegrationCreateUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { IntegrationCreateUpdate } from "../../types/integration/integration_create_update.ts";
|
||||
import {
|
||||
DiscordIntegrationDelete,
|
||||
} from "../../types/integration/integration_delete.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { IntegrationDelete } from "../../types/integration/integration_delete.ts";
|
||||
|
||||
export function handleIntegrationDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationDelete?.(
|
||||
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||
data.d as DiscordIntegrationDelete,
|
||||
),
|
||||
data.d as IntegrationDelete,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordIntegrationCreateUpdate,
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integration/integration_create_update.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationUpdate?.(
|
||||
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||
data.d as DiscordIntegrationCreateUpdate,
|
||||
),
|
||||
data.d as IntegrationCreateUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { DiscordInteraction } from "../../types/interactions/interaction.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { Interaction } from "../../types/interactions/interaction.ts";
|
||||
|
||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordInteraction;
|
||||
const discordenoMember = payload.guild_id
|
||||
const payload = data.d as Interaction;
|
||||
const discordenoMember = payload.guildId
|
||||
? await structures.createDiscordenoMember(
|
||||
payload.member as DiscordGuildMemberWithUser,
|
||||
payload.guild_id,
|
||||
payload.member as GuildMemberWithUser,
|
||||
payload.guildId,
|
||||
)
|
||||
: undefined;
|
||||
if (discordenoMember) {
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordInviteCreate,
|
||||
InviteCreate,
|
||||
} from "../../types/invites/invite_create.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||
|
||||
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteCreate?.(
|
||||
snakeKeysToCamelCase<InviteCreate>(data.d as DiscordInviteCreate),
|
||||
data.d as InviteCreate,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordInviteDelete,
|
||||
InviteDelete,
|
||||
} from "../../types/invites/invite_delete.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { InviteDelete } from "../../types/invites/invite_delete.ts";
|
||||
|
||||
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteDelete?.(
|
||||
snakeKeysToCamelCase<InviteDelete>(data.d as DiscordInviteDelete),
|
||||
data.d as InviteDelete,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
||||
import { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMembersChunk;
|
||||
const payload = data.d as GuildMembersChunk;
|
||||
|
||||
const members = await Promise.all(
|
||||
payload.members.map(async (member) => {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
member,
|
||||
payload.guild_id,
|
||||
payload.guildId,
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
@@ -26,17 +26,17 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
||||
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
||||
if (!resolve) return;
|
||||
|
||||
if (payload.chunk_index + 1 === payload.chunk_count) {
|
||||
if (payload.chunkIndex + 1 === payload.chunkCount) {
|
||||
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) {
|
||||
if (payload.chunkCount === 1) {
|
||||
return resolve(new Collection(members.map((m) => [m.id, m])));
|
||||
}
|
||||
|
||||
return resolve(
|
||||
await cacheHandlers.filter(
|
||||
"members",
|
||||
(m) => m.guilds.has(payload.guild_id),
|
||||
(m) => m.guilds.has(payload.guildId),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
||||
import { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
||||
|
||||
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberAdd;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildMemberAdd;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
guild.memberCount++;
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload,
|
||||
payload.guild_id,
|
||||
payload.guildId,
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
||||
import { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
||||
|
||||
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildMemberRemove;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
guild.memberCount--;
|
||||
|
||||
@@ -2,22 +2,20 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
||||
import { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
||||
|
||||
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildMemberUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedMember = await cacheHandlers.get("members", payload.user.id);
|
||||
const guildMember = cachedMember?.guilds.get(payload.guild_id);
|
||||
const guildMember = cachedMember?.guilds.get(payload.guildId);
|
||||
|
||||
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())
|
||||
premiumSince: payload.premiumSince || undefined,
|
||||
joinedAt: new Date(guildMember?.joinedAt || Date.now())
|
||||
.toISOString(),
|
||||
deaf: guildMember?.deaf || false,
|
||||
mute: guildMember?.mute || false,
|
||||
@@ -25,7 +23,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
};
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
newMemberData,
|
||||
payload.guild_id,
|
||||
payload.guildId,
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { DiscordMessage, Message } from "../../types/messages/message.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { Message } from "../../types/messages/message.ts";
|
||||
|
||||
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
const payload = snakeKeysToCamelCase(data.d as DiscordMessage) as Message;
|
||||
const payload = data.d as Message;
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (channel) channel.lastMessageId = payload.id;
|
||||
|
||||
@@ -18,7 +17,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
if (payload.member && guild) {
|
||||
// If in a guild cache the author as a member
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...payload.member, user: payload.author } as DiscordGuildMemberWithUser,
|
||||
{ ...payload.member, user: payload.author } as GuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
@@ -29,7 +28,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
// Cache the member if its a valid member
|
||||
if (mention.member && guild) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...mention.member, user: mention } as DiscordGuildMemberWithUser,
|
||||
{ ...mention.member, user: mention } as GuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
|
||||
@@ -43,7 +42,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
}
|
||||
|
||||
const message = await structures.createDiscordenoMessage(
|
||||
data.d as DiscordMessage,
|
||||
data.d as Message,
|
||||
);
|
||||
// Cache the message
|
||||
await cacheHandlers.set("messages", payload.id, message);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordMessageDelete } from "../../types/messages/message_delete.ts";
|
||||
import { MessageDelete } from "../../types/messages/message_delete.ts";
|
||||
|
||||
export async function handleMessageDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageDelete;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
const payload = data.d as MessageDelete;
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (!channel) return;
|
||||
|
||||
eventHandlers.messageDelete?.(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordMessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts";
|
||||
import { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts";
|
||||
|
||||
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageDeleteBulk;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
const payload = data.d as MessageDeleteBulk;
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (!channel) return;
|
||||
|
||||
return Promise.all(payload.ids.map(async (id) => {
|
||||
|
||||
@@ -3,14 +3,13 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordMessageReactionAdd,
|
||||
MessageReactionAdd,
|
||||
} from "../../types/messages/message_reaction_add.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageReactionAdd;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
const payload = data.d as MessageReactionAdd;
|
||||
const message = await cacheHandlers.get("messages", payload.messageId);
|
||||
|
||||
if (message) {
|
||||
const reactionExisted = message.reactions?.find(
|
||||
@@ -23,7 +22,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
else {
|
||||
const newReaction = {
|
||||
count: 1,
|
||||
me: payload.user_id === botId,
|
||||
me: payload.userId === botId,
|
||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||
};
|
||||
message.reactions = message.reactions
|
||||
@@ -31,11 +30,11 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
: [newReaction];
|
||||
}
|
||||
|
||||
await cacheHandlers.set("messages", payload.message_id, message);
|
||||
await cacheHandlers.set("messages", payload.messageId, message);
|
||||
}
|
||||
|
||||
if (payload.member && payload.guild_id) {
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (payload.member && payload.guildId) {
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (guild) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload.member,
|
||||
|
||||
@@ -2,16 +2,14 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordMessageReactionRemove,
|
||||
MessageReactionRemove,
|
||||
} from "../../types/messages/message_reaction_remove.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleMessageReactionRemove(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
const payload = data.d as DiscordMessageReactionRemove;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
const payload = data.d as MessageReactionRemove;
|
||||
const message = await cacheHandlers.get("messages", payload.messageId);
|
||||
|
||||
if (message) {
|
||||
const reaction = message.reactions?.find((reaction) =>
|
||||
@@ -27,12 +25,12 @@ export async function handleMessageReactionRemove(
|
||||
}
|
||||
if (!message.reactions?.length) message.reactions = undefined;
|
||||
|
||||
await cacheHandlers.set("messages", payload.message_id, message);
|
||||
await cacheHandlers.set("messages", payload.messageId, message);
|
||||
}
|
||||
}
|
||||
|
||||
eventHandlers.reactionRemove?.(
|
||||
snakeKeysToCamelCase<MessageReactionRemove>(payload),
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,25 +2,23 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordMessageReactionRemoveAll,
|
||||
MessageReactionRemoveAll,
|
||||
} from "../../types/messages/message_reaction_remove_all.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveAll(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
const payload = data.d as DiscordMessageReactionRemoveAll;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
const payload = data.d as MessageReactionRemoveAll;
|
||||
const message = await cacheHandlers.get("messages", payload.messageId);
|
||||
|
||||
if (message?.reactions) {
|
||||
message.reactions = undefined;
|
||||
|
||||
await cacheHandlers.set("messages", payload.message_id, message);
|
||||
await cacheHandlers.set("messages", payload.messageId, message);
|
||||
}
|
||||
|
||||
eventHandlers.reactionRemoveAll?.(
|
||||
snakeKeysToCamelCase<MessageReactionRemoveAll>(payload),
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordMessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
||||
import { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
const payload = data.d as DiscordMessageReactionRemoveEmoji;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
const payload = data.d as MessageReactionRemoveEmoji;
|
||||
const message = await cacheHandlers.get("messages", payload.messageId);
|
||||
|
||||
if (message?.reactions) {
|
||||
message.reactions = message.reactions.filter(
|
||||
@@ -21,13 +21,13 @@ export async function handleMessageReactionRemoveEmoji(
|
||||
|
||||
if (!message.reactions.length) message.reactions = undefined;
|
||||
|
||||
await cacheHandlers.set("messages", payload.message_id, message);
|
||||
await cacheHandlers.set("messages", payload.messageId, message);
|
||||
}
|
||||
|
||||
eventHandlers.reactionRemoveEmoji?.(
|
||||
payload.emoji,
|
||||
payload.message_id,
|
||||
payload.channel_id,
|
||||
payload.guild_id,
|
||||
payload.messageId,
|
||||
payload.channelId,
|
||||
payload.guildId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { Message } from "../../types/messages/message.ts";
|
||||
|
||||
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessage;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
const payload = data.d as Message;
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (!channel) return;
|
||||
|
||||
const oldMessage = await cacheHandlers.get("messages", payload.id);
|
||||
@@ -14,7 +14,7 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
// Messages with embeds can trigger update but they wont have edited_timestamp
|
||||
if (
|
||||
!payload.edited_timestamp ||
|
||||
!payload.editedTimestamp ||
|
||||
(oldMessage.content === payload.content)
|
||||
) {
|
||||
return;
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordPresenceUpdate,
|
||||
PresenceUpdate,
|
||||
} from "../../types/misc/presence_update.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { PresenceUpdate } from "../../types/misc/presence_update.ts";
|
||||
|
||||
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = snakeKeysToCamelCase<PresenceUpdate>(
|
||||
data.d as DiscordPresenceUpdate,
|
||||
);
|
||||
const payload = data.d as PresenceUpdate;
|
||||
|
||||
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
||||
await cacheHandlers.set("presences", payload.user.id, payload);
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordReady } from "../../types/gateway/ready.ts";
|
||||
import { DiscordGuildMemberWithUser } from "../../types/mod.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { Ready } from "../../types/gateway/ready.ts";
|
||||
import { GuildMemberWithUser } from "../../types/mod.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export function handleReady(
|
||||
@@ -15,7 +14,7 @@ export function handleReady(
|
||||
// The bot has already started, the last shard is resumed, however.
|
||||
if (cache.isReady) return;
|
||||
|
||||
const payload = data.d as DiscordReady;
|
||||
const payload = data.d as Ready;
|
||||
setBotId(payload.user.id);
|
||||
setApplicationId(payload.application.id);
|
||||
|
||||
@@ -44,7 +43,7 @@ export function handleReady(
|
||||
|
||||
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
|
||||
/** This function checks if the shard is fully loaded */
|
||||
async function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
||||
async function checkReady(payload: Ready, shardId: number, now: number) {
|
||||
const shard = ws.shards.get(shardId);
|
||||
if (!shard) return;
|
||||
|
||||
@@ -100,7 +99,7 @@ async function loaded(shardId: number) {
|
||||
await Promise.allSettled(
|
||||
members.map(async (member) => {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
camelKeysToSnakeCase<DiscordGuildMemberWithUser>(member),
|
||||
member as GuildMemberWithUser,
|
||||
guildId,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordTypingStart,
|
||||
TypingStart,
|
||||
} from "../../types/misc/typing_start.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { TypingStart } from "../../types/misc/typing_start.ts";
|
||||
|
||||
export function handleTypingStart(data: DiscordGatewayPayload) {
|
||||
eventHandlers.typingStart?.(
|
||||
snakeKeysToCamelCase<TypingStart>(data.d as DiscordTypingStart),
|
||||
data.d as TypingStart,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordUser, User } from "../../types/users/user.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { User } from "../../types/users/user.ts";
|
||||
|
||||
export async function handleUserUpdate(data: DiscordGatewayPayload) {
|
||||
const userData = camelKeysToSnakeCase(data.d as DiscordUser) as User;
|
||||
const userData = data.d as User;
|
||||
|
||||
const member = await cacheHandlers.get("members", userData.id);
|
||||
if (!member) return;
|
||||
|
||||
@@ -2,16 +2,16 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildRoleCreate } from "../../types/mod.ts";
|
||||
import { GuildRoleCreate } from "../../types/mod.ts";
|
||||
|
||||
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleCreate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildRoleCreate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const role = await structures.createDiscordenoRole(payload);
|
||||
guild.roles = guild.roles.set(payload.role.id, role);
|
||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||
await cacheHandlers.set("guilds", payload.guildId, guild);
|
||||
|
||||
eventHandlers.roleCreate?.(guild, role);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
|
||||
import { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
|
||||
|
||||
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleDelete;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildRoleDelete;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedRole = guild.roles.get(payload.role_id)!;
|
||||
guild.roles.delete(payload.role_id);
|
||||
const cachedRole = guild.roles.get(payload.roleId)!;
|
||||
guild.roles.delete(payload.roleId);
|
||||
|
||||
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
|
||||
|
||||
@@ -28,9 +28,9 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
`2. Running forEach loop in CHANNEL_DELTE file.`,
|
||||
);
|
||||
// Member does not have this role
|
||||
if (!g.roles.includes(payload.role_id)) return;
|
||||
if (!g.roles.includes(payload.roleId)) return;
|
||||
// Remove this role from the members cache
|
||||
g.roles = g.roles.filter((id) => id !== payload.role_id);
|
||||
g.roles = g.roles.filter((id) => id !== payload.roleId);
|
||||
cacheHandlers.set("members", member.id, member);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,11 +2,11 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildRoleUpdate } from "../../types/mod.ts";
|
||||
import { GuildRoleUpdate } from "../../types/mod.ts";
|
||||
|
||||
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
const payload = data.d as GuildRoleUpdate;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedRole = guild.roles.get(payload.role.id);
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
DiscordVoiceServerUpdate,
|
||||
VoiceServerUpdate,
|
||||
} from "../../types/voice/voice_server_update.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
|
||||
|
||||
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = snakeKeysToCamelCase<VoiceServerUpdate>(
|
||||
data.d as DiscordVoiceServerUpdate,
|
||||
);
|
||||
const payload = data.d as VoiceServerUpdate;
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -2,15 +2,11 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordGuildMemberWithUser } from "../../types/mod.ts";
|
||||
import {
|
||||
DiscordVoiceState,
|
||||
VoiceState,
|
||||
} from "../../types/voice/voice_state.ts";
|
||||
import {
|
||||
camelKeysToSnakeCase,
|
||||
snakeKeysToCamelCase,
|
||||
} from "../../util/utils.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = snakeKeysToCamelCase<VoiceState>(
|
||||
@@ -23,7 +19,7 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const member = payload.member
|
||||
? await structures.createDiscordenoMember(
|
||||
camelKeysToSnakeCase<DiscordGuildMemberWithUser>(payload),
|
||||
payload.member,
|
||||
guild.id,
|
||||
)
|
||||
: await cacheHandlers.get("members", payload.userId);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordWebhookUpdate } from "../../types/webhooks/webhooks_update.ts";
|
||||
import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts";
|
||||
|
||||
export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
|
||||
const options = data.d as DiscordWebhookUpdate;
|
||||
const options = data.d as WebhookUpdate;
|
||||
eventHandlers.webhooksUpdate?.(
|
||||
options.channel_id,
|
||||
options.guild_id,
|
||||
options.channelId,
|
||||
options.guildId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts";
|
||||
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
@@ -72,7 +71,7 @@ export async function editSlashResponse(
|
||||
if (!options.messageId) return result as undefined;
|
||||
|
||||
const message = await structures.createDiscordenoMessage(
|
||||
result as DiscordMessage,
|
||||
result,
|
||||
);
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function getGuild(
|
||||
|
||||
const structure = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
(BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards),
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { GuildMember } from "../../types/guilds/guild_member.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { ModifyGuildMember } from "../../types/mod.ts";
|
||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
@@ -69,7 +69,7 @@ export async function editMember(
|
||||
|
||||
await requireBotGuildPermissions(guildId, [...requiredPerms]);
|
||||
|
||||
const result = await rest.runMethod<GuildMember>(
|
||||
const result = await rest.runMethod<GuildMemberWithUser>(
|
||||
"patch",
|
||||
endpoints.GUILD_MEMBER(guildId, memberId),
|
||||
camelKeysToSnakeCase(options),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordenoMember } from "../../structures/member.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
|
||||
import { GuildMember } from "../../types/guilds/guild_member.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
@@ -46,7 +46,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) {
|
||||
);
|
||||
}
|
||||
|
||||
const result = (await rest.runMethod<GuildMember[]>(
|
||||
const result = (await rest.runMethod<GuildMemberWithUser[]>(
|
||||
"get",
|
||||
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
|
||||
membersLeft > 1000 ? 1000 : membersLeft
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function createRole(
|
||||
|
||||
const role = await structures.createDiscordenoRole({
|
||||
role: result,
|
||||
guild_id: guildId,
|
||||
guildId,
|
||||
});
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
guild?.roles.set(role.id, role);
|
||||
|
||||
@@ -26,5 +26,5 @@ export async function editRole(
|
||||
},
|
||||
);
|
||||
|
||||
return await structures.createDiscordenoRole(result);
|
||||
return await structures.createDiscordenoRole({ role: result, guildId });
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ import { editChannel } from "../helpers/channels/edit_channel.ts";
|
||||
import { editChannelOverwrite } from "../helpers/channels/edit_channel_overwrite.ts";
|
||||
import { sendMessage } from "../helpers/messages/send_message.ts";
|
||||
import { disconnectMember } from "../helpers/mod.ts";
|
||||
import { Channel, DiscordChannel } from "../types/channels/channel.ts";
|
||||
import { Channel } from "../types/channels/channel.ts";
|
||||
import { ModifyChannel } from "../types/channels/modify_channel.ts";
|
||||
import { DiscordOverwrite, Overwrite } from "../types/channels/overwrite.ts";
|
||||
import { CreateMessage } from "../types/messages/create_message.ts";
|
||||
import { PermissionStrings } from "../types/permissions/permission_strings.ts";
|
||||
import { VoiceState } from "../types/voice/voice_state.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||
import { createNewProp } from "../util/utils.ts";
|
||||
import { DiscordenoGuild } from "./guild.ts";
|
||||
import { DiscordenoMember } from "./member.ts";
|
||||
import { DiscordenoMessage } from "./message.ts";
|
||||
@@ -77,14 +77,14 @@ const baseChannel: Partial<DiscordenoChannel> = {
|
||||
/** Create a structure object */
|
||||
// deno-lint-ignore require-await
|
||||
export async function createDiscordenoChannel(
|
||||
data: DiscordChannel,
|
||||
data: Channel,
|
||||
guildId?: string,
|
||||
) {
|
||||
const {
|
||||
guildId: rawGuildId = "",
|
||||
lastPinTimestamp,
|
||||
...rest
|
||||
} = snakeKeysToCamelCase<Channel>(data);
|
||||
} = data;
|
||||
|
||||
const props: Record<string, PropertyDescriptor> = {};
|
||||
Object.keys(rest).forEach((key) => {
|
||||
|
||||
@@ -15,11 +15,11 @@ import { unbanMember } from "../helpers/members/unban_member.ts";
|
||||
import { GetGuildAuditLog } from "../types/audit_log/get_guild_audit_log.ts";
|
||||
import { Emoji } from "../types/emojis/emoji.ts";
|
||||
import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts";
|
||||
import { DiscordGuild, Guild } from "../types/guilds/guild.ts";
|
||||
import { Guild } from "../types/guilds/guild.ts";
|
||||
import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts";
|
||||
import {
|
||||
DiscordGuildMemberWithUser,
|
||||
GuildMember,
|
||||
GuildMemberWithUser,
|
||||
} from "../types/guilds/guild_member.ts";
|
||||
import { ModifyGuild } from "../types/guilds/modify_guild.ts";
|
||||
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
||||
@@ -27,11 +27,7 @@ import { DiscordImageSize } from "../types/misc/image_size.ts";
|
||||
import { PresenceUpdate } from "../types/misc/presence_update.ts";
|
||||
import { VoiceState } from "../types/voice/voice_state.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import {
|
||||
camelKeysToSnakeCase,
|
||||
createNewProp,
|
||||
snakeKeysToCamelCase,
|
||||
} from "../util/utils.ts";
|
||||
import { createNewProp } from "../util/utils.ts";
|
||||
import { DiscordenoChannel } from "./channel.ts";
|
||||
import { DiscordenoMember } from "./member.ts";
|
||||
import { structures } from "./mod.ts";
|
||||
@@ -115,7 +111,7 @@ const baseGuild: Partial<DiscordenoGuild> = {
|
||||
};
|
||||
|
||||
export async function createDiscordenoGuild(
|
||||
data: DiscordGuild,
|
||||
data: Guild,
|
||||
shardId: number,
|
||||
) {
|
||||
const {
|
||||
@@ -127,11 +123,11 @@ export async function createDiscordenoGuild(
|
||||
emojis,
|
||||
members = [],
|
||||
...rest
|
||||
} = snakeKeysToCamelCase<Guild>(data);
|
||||
} = data;
|
||||
|
||||
const roles = await Promise.all(
|
||||
(data.roles || []).map((role) =>
|
||||
structures.createDiscordenoRole({ role, guild_id: rest.id })
|
||||
structures.createDiscordenoRole({ role, guildId: rest.id })
|
||||
),
|
||||
);
|
||||
|
||||
@@ -188,7 +184,7 @@ export async function createDiscordenoGuild(
|
||||
await Promise.allSettled(
|
||||
members.map(async (member) => {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
camelKeysToSnakeCase(member) as DiscordGuildMemberWithUser,
|
||||
member as GuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import { addRole } from "../helpers/roles/add_role.ts";
|
||||
import { removeRole } from "../helpers/roles/remove_role.ts";
|
||||
import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts";
|
||||
import {
|
||||
DiscordGuildMemberWithUser,
|
||||
GuildMember,
|
||||
GuildMemberWithUser,
|
||||
} from "../types/guilds/guild_member.ts";
|
||||
@@ -19,7 +18,7 @@ import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
||||
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
||||
import { User } from "../types/users/user.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||
import { createNewProp } from "../util/utils.ts";
|
||||
import { DiscordenoGuild } from "./guild.ts";
|
||||
|
||||
const baseMember: Partial<DiscordenoMember> = {
|
||||
@@ -74,7 +73,7 @@ const baseMember: Partial<DiscordenoMember> = {
|
||||
|
||||
export async function createDiscordenoMember(
|
||||
// The `user` param in `DiscordGuildMember` is optional since discord does not send it in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events. But this data in there is required to build this structure so it is required in this case
|
||||
data: DiscordGuildMemberWithUser,
|
||||
data: GuildMemberWithUser,
|
||||
guildId: string,
|
||||
) {
|
||||
const {
|
||||
@@ -82,7 +81,7 @@ export async function createDiscordenoMember(
|
||||
joinedAt,
|
||||
premiumSince,
|
||||
...rest
|
||||
} = snakeKeysToCamelCase<GuildMemberWithUser>(data);
|
||||
} = data;
|
||||
|
||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import { sendMessage } from "../helpers/messages/send_message.ts";
|
||||
import { GuildMember } from "../types/guilds/guild_member.ts";
|
||||
import { CreateMessage } from "../types/messages/create_message.ts";
|
||||
import { EditMessage } from "../types/messages/edit_message.ts";
|
||||
import { DiscordMessage, Message } from "../types/messages/message.ts";
|
||||
import { Message } from "../types/messages/message.ts";
|
||||
import { CHANNEL_MENTION_REGEX } from "../util/constants.ts";
|
||||
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||
import { createNewProp } from "../util/utils.ts";
|
||||
import { DiscordenoChannel } from "./channel.ts";
|
||||
import { DiscordenoGuild } from "./guild.ts";
|
||||
import { DiscordenoMember } from "./member.ts";
|
||||
@@ -126,7 +126,7 @@ const baseMessage: Partial<DiscordenoMessage> = {
|
||||
},
|
||||
};
|
||||
|
||||
export async function createDiscordenoMessage(data: DiscordMessage) {
|
||||
export async function createDiscordenoMessage(data: Message) {
|
||||
const {
|
||||
guildId = "",
|
||||
channelId,
|
||||
@@ -135,7 +135,7 @@ export async function createDiscordenoMessage(data: DiscordMessage) {
|
||||
mentionRoles = [],
|
||||
editedTimestamp,
|
||||
...rest
|
||||
} = snakeKeysToCamelCase<Message>(data);
|
||||
} = data;
|
||||
|
||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
|
||||
@@ -3,12 +3,11 @@ import { cache } from "../cache.ts";
|
||||
import { deleteRole } from "../helpers/roles/delete_role.ts";
|
||||
import { editRole } from "../helpers/roles/edit_role.ts";
|
||||
import { CreateGuildRole } from "../types/guilds/create_guild_role.ts";
|
||||
import { DiscordGuildRoleCreate } from "../types/guilds/guild_role_create.ts";
|
||||
import { Errors } from "../types/misc/errors.ts";
|
||||
import { Role } from "../types/permissions/role.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { highestRole } from "../util/permissions.ts";
|
||||
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||
import { createNewProp } from "../util/utils.ts";
|
||||
import { DiscordenoGuild } from "./guild.ts";
|
||||
import { DiscordenoMember } from "./member.ts";
|
||||
|
||||
@@ -30,7 +29,7 @@ const baseRole: Partial<DiscordenoRole> = {
|
||||
|
||||
// METHODS
|
||||
delete() {
|
||||
return deleteRole(this.guildId!, this.id!).catch(console.error);
|
||||
return deleteRole(this.guildId!, this.id!);
|
||||
},
|
||||
edit(options) {
|
||||
return editRole(this.guildId!, this.id!, options);
|
||||
@@ -67,15 +66,15 @@ const baseRole: Partial<DiscordenoRole> = {
|
||||
};
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
export async function createDiscordenoRole(data: DiscordGuildRoleCreate) {
|
||||
export async function createDiscordenoRole(
|
||||
data: { role: Role } & {
|
||||
guildId: string;
|
||||
},
|
||||
) {
|
||||
const {
|
||||
tags = {},
|
||||
...rest
|
||||
} = snakeKeysToCamelCase<
|
||||
Role & {
|
||||
guildId: string;
|
||||
}
|
||||
>({ guildId: data.guild_id, ...data.role });
|
||||
} = ({ guildId: data.guildId, ...data.role });
|
||||
|
||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
||||
import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts";
|
||||
import { DiscordHello } from "../types/gateway/hello.ts";
|
||||
import { DiscordReady } from "../types/gateway/ready.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { delay, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
import { identify } from "./identify.ts";
|
||||
import { resume } from "./resume.ts";
|
||||
@@ -127,7 +127,10 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
|
||||
if (!messageData.t) return;
|
||||
|
||||
return handlers[messageData.t]?.(messageData, shardId);
|
||||
return handlers[messageData.t]?.(
|
||||
snakeKeysToCamelCase(messageData),
|
||||
shardId,
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user