mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
refactor(controllers): remove redundant DiscordPayload#t check (#653)
This commit is contained in:
@@ -380,8 +380,6 @@ function createTimeout(userID: String) {
|
||||
}
|
||||
|
||||
controllers.TYPING_START = function (data) {
|
||||
if (data.t !== "TYPING_START") return;
|
||||
|
||||
const payload = data.d as TypingStartPayload;
|
||||
eventHandlers.typingStart?.(payload);
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ import { DiscordPayload, GuildBanPayload } from "../../types/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalGuildBanAdd(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_BAN_ADD") return;
|
||||
|
||||
const payload = data.d as GuildBanPayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -14,8 +12,6 @@ export async function handleInternalGuildBanAdd(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildBanRemove(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_BAN_REMOVE") return;
|
||||
|
||||
const payload = data.d as GuildBanPayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -8,8 +8,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalChannelCreate(data: DiscordPayload) {
|
||||
if (data.t !== "CHANNEL_CREATE") return;
|
||||
|
||||
const payload = data.d as ChannelCreatePayload;
|
||||
|
||||
const channelStruct = await structures.createChannelStruct(payload);
|
||||
@@ -19,8 +17,6 @@ export async function handleInternalChannelCreate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalChannelDelete(data: DiscordPayload) {
|
||||
if (data.t !== "CHANNEL_DELETE") return;
|
||||
|
||||
const payload = data.d as ChannelCreatePayload;
|
||||
|
||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||
@@ -54,8 +50,6 @@ export async function handleInternalChannelDelete(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalChannelUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "CHANNEL_UPDATE") return;
|
||||
|
||||
const payload = data.d as ChannelCreatePayload;
|
||||
const cachedChannel = await cacheHandlers.get("channels", payload.id);
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ export async function handleInternalGuildCreate(
|
||||
data: DiscordPayload,
|
||||
shardID: number,
|
||||
) {
|
||||
if (data.t !== "GUILD_CREATE") return;
|
||||
|
||||
const payload = data.d as CreateGuildPayload;
|
||||
// When shards resume they emit GUILD_CREATE again.
|
||||
if (await cacheHandlers.has("guilds", payload.id)) return;
|
||||
@@ -37,8 +35,6 @@ export async function handleInternalGuildCreate(
|
||||
}
|
||||
|
||||
export async function handleInternalGuildDelete(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_DELETE") return;
|
||||
|
||||
const payload = data.d as GuildDeletePayload;
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
if (message.guildID === payload.id) {
|
||||
@@ -65,8 +61,6 @@ export async function handleInternalGuildDelete(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_UPDATE") return;
|
||||
|
||||
const payload = data.d as UpdateGuildPayload;
|
||||
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
|
||||
if (!cachedGuild) return;
|
||||
@@ -108,8 +102,6 @@ export async function handleInternalGuildUpdate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildEmojisUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_EMOJIS_UPDATE") return;
|
||||
|
||||
const payload = data.d as GuildEmojisUpdatePayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -8,8 +8,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalInteractionCreate(data: DiscordPayload) {
|
||||
if (data.t !== "INTERACTION_CREATE") return;
|
||||
|
||||
const payload = data.d as InteractionCommandPayload;
|
||||
const memberStruct = await structures.createMemberStruct(
|
||||
payload.member,
|
||||
@@ -28,8 +26,6 @@ export async function handleInternalInteractionCreate(data: DiscordPayload) {
|
||||
export function handleInternalApplicationCommandCreate(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "APPLICATION_COMMAND_CREATE") return;
|
||||
|
||||
const {
|
||||
guild_id: guildID,
|
||||
application_id: applicationID,
|
||||
@@ -44,8 +40,6 @@ export function handleInternalApplicationCommandCreate(
|
||||
}
|
||||
|
||||
export function handleInternalApplicationCommandUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "APPLICATION_COMMAND_UPDATE") return;
|
||||
|
||||
const {
|
||||
application_id: applicationID,
|
||||
guild_id: guildID,
|
||||
@@ -60,8 +54,6 @@ export function handleInternalApplicationCommandUpdate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export function handleInternalApplicationCommandDelete(data: DiscordPayload) {
|
||||
if (data.t !== "APPLICATION_COMMAND_DELETE") return;
|
||||
|
||||
const {
|
||||
application_id: applicationID,
|
||||
guild_id: guildID,
|
||||
|
||||
@@ -12,8 +12,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalGuildMemberAdd(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_MEMBER_ADD") return;
|
||||
|
||||
const payload = data.d as GuildMemberAddPayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -29,8 +27,6 @@ export async function handleInternalGuildMemberAdd(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildMemberRemove(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_MEMBER_REMOVE") return;
|
||||
|
||||
const payload = data.d as GuildBanPayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -46,8 +42,6 @@ export async function handleInternalGuildMemberRemove(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildMemberUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_MEMBER_UPDATE") return;
|
||||
|
||||
const payload = data.d as GuildMemberUpdatePayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -103,8 +97,6 @@ export async function handleInternalGuildMemberUpdate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildMembersChunk(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_MEMBERS_CHUNK") return;
|
||||
|
||||
const payload = data.d as GuildMemberChunkPayload;
|
||||
|
||||
const members = await Promise.all(
|
||||
|
||||
@@ -9,8 +9,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalMessageCreate(data: DiscordPayload) {
|
||||
if (data.t !== "MESSAGE_CREATE") return;
|
||||
|
||||
const payload = data.d as MessageCreateOptions;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
if (channel) channel.lastMessageID = payload.id;
|
||||
@@ -48,8 +46,6 @@ export async function handleInternalMessageCreate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalMessageDelete(data: DiscordPayload) {
|
||||
if (data.t !== "MESSAGE_DELETE") return;
|
||||
|
||||
const payload = data.d as MessageDeletePayload;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
if (!channel) return;
|
||||
@@ -63,8 +59,6 @@ export async function handleInternalMessageDelete(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalMessageDeleteBulk(data: DiscordPayload) {
|
||||
if (data.t !== "MESSAGE_DELETE_BULK") return;
|
||||
|
||||
const payload = data.d as MessageDeleteBulkPayload;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
if (!channel) return;
|
||||
@@ -79,8 +73,6 @@ export async function handleInternalMessageDeleteBulk(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalMessageUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "MESSAGE_UPDATE") return;
|
||||
|
||||
const payload = data.d as MessageCreateOptions;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
if (!channel) return;
|
||||
|
||||
@@ -24,8 +24,6 @@ export async function handleInternalReady(
|
||||
data: DiscordPayload,
|
||||
shardID: number,
|
||||
) {
|
||||
if (data.t !== "READY") return;
|
||||
|
||||
const payload = data.d as ReadyPayload;
|
||||
setBotID(payload.user.id);
|
||||
setApplicationID(payload.application.id);
|
||||
@@ -80,8 +78,6 @@ export async function handleInternalReady(
|
||||
|
||||
/** 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) {
|
||||
if (data.t !== "PRESENCE_UPDATE") return;
|
||||
|
||||
const payload = data.d as PresenceUpdatePayload;
|
||||
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
||||
await cacheHandlers.set("presences", payload.user.id, payload);
|
||||
@@ -91,14 +87,11 @@ export async function handleInternalPresenceUpdate(data: DiscordPayload) {
|
||||
|
||||
/** This function is the internal handler for the typings event. Users can override this with controllers if desired. */
|
||||
export function handleInternalTypingStart(data: DiscordPayload) {
|
||||
if (data.t !== "TYPING_START") return;
|
||||
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) {
|
||||
if (data.t !== "USER_UPDATE") return;
|
||||
|
||||
const userData = data.d as UserPayload;
|
||||
|
||||
const member = await cacheHandlers.get("members", userData.id);
|
||||
@@ -116,8 +109,6 @@ export async function handleInternalUserUpdate(data: DiscordPayload) {
|
||||
|
||||
/** 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) {
|
||||
if (data.t !== "VOICE_STATE_UPDATE") return;
|
||||
|
||||
const payload = data.d as VoiceStateUpdatePayload;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
@@ -169,8 +160,6 @@ export async function handleInternalVoiceStateUpdate(data: DiscordPayload) {
|
||||
|
||||
/** This function is the internal handler for the webhooks update event. Users can override this with controllers if desired. */
|
||||
export function handleInternalWebhooksUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "WEBHOOKS_UPDATE") return;
|
||||
|
||||
const options = data.d as WebhookUpdatePayload;
|
||||
eventHandlers.webhooksUpdate?.(
|
||||
options.channel_id,
|
||||
@@ -181,8 +170,6 @@ export function handleInternalWebhooksUpdate(data: DiscordPayload) {
|
||||
export function handleInternalIntegrationCreate(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "INTEGRATION_CREATE") return;
|
||||
|
||||
const {
|
||||
guild_id: guildID,
|
||||
enable_emoticons: enableEmoticons,
|
||||
@@ -207,8 +194,6 @@ export function handleInternalIntegrationCreate(
|
||||
}
|
||||
|
||||
export function handleInternalIntegrationUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "INTEGRATION_UPDATE") return;
|
||||
|
||||
const {
|
||||
enable_emoticons: enableEmoticons,
|
||||
expire_behavior: expireBehavior,
|
||||
@@ -233,8 +218,6 @@ export function handleInternalIntegrationUpdate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export function handleInternalIntegrationDelete(data: DiscordPayload) {
|
||||
if (data.t !== "INTEGRATION_DELETE") return;
|
||||
|
||||
const {
|
||||
guild_id: guildID,
|
||||
application_id: applicationID,
|
||||
|
||||
@@ -9,8 +9,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalMessageReactionAdd(data: DiscordPayload) {
|
||||
if (data.t !== "MESSAGE_REACTION_ADD") return;
|
||||
|
||||
const payload = data.d as MessageReactionPayload;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
|
||||
@@ -65,8 +63,6 @@ export async function handleInternalMessageReactionAdd(data: DiscordPayload) {
|
||||
export async function handleInternalMessageReactionRemove(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "MESSAGE_REACTION_REMOVE") return;
|
||||
|
||||
const payload = data.d as MessageReactionPayload;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
|
||||
@@ -121,8 +117,6 @@ export async function handleInternalMessageReactionRemove(
|
||||
export async function handleInternalMessageReactionRemoveAll(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "MESSAGE_REACTION_REMOVE_ALL") return;
|
||||
|
||||
const payload = data.d as BaseMessageReactionPayload;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
|
||||
@@ -138,8 +132,6 @@ export async function handleInternalMessageReactionRemoveAll(
|
||||
export async function handleInternalMessageReactionRemoveEmoji(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "MESSAGE_REACTION_REMOVE_EMOJI") return;
|
||||
|
||||
const payload = data.d as MessageReactionRemoveEmojiPayload;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
export async function handleInternalGuildRoleCreate(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_ROLE_CREATE") return;
|
||||
|
||||
const payload = data.d as GuildRolePayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -22,8 +20,6 @@ export async function handleInternalGuildRoleCreate(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildRoleDelete(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_ROLE_DELETE") return;
|
||||
|
||||
const payload = data.d as GuildRoleDeletePayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
@@ -49,8 +45,6 @@ export async function handleInternalGuildRoleDelete(data: DiscordPayload) {
|
||||
}
|
||||
|
||||
export async function handleInternalGuildRoleUpdate(data: DiscordPayload) {
|
||||
if (data.t !== "GUILD_ROLE_UPDATE") return;
|
||||
|
||||
const payload = data.d as GuildRolePayload;
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
Reference in New Issue
Block a user