mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat: base plugin lib idea (#2308)
* feat: base plugin lib idea * fix: stuff * fmt * fix: imports and exports * fix: errors & tests * fix: remove logs
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) {
|
||||
const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel });
|
||||
|
||||
bot.events.channelCreate(bot, channel);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
bot.events.channelDelete(
|
||||
bot,
|
||||
bot.transformers.channel(bot, {
|
||||
channel: payload,
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannelPinsUpdate, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannelPinsUpdate;
|
||||
|
||||
bot.events.channelPinsUpdate(bot, {
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
lastPinTimestamp: payload.last_pin_timestamp ? Date.parse(payload.last_pin_timestamp) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
const channel = bot.transformers.channel(bot, { channel: payload });
|
||||
|
||||
bot.events.channelUpdate(bot, channel);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceCreate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic,
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic,
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
topic: payload.topic,
|
||||
});
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
|
||||
bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordThreadListSync } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordThreadListSync;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
return {
|
||||
guildId,
|
||||
channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)),
|
||||
threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })),
|
||||
members: payload.members.map((member) => ({
|
||||
id: member.id ? bot.transformers.snowflake(member.id) : undefined,
|
||||
userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined,
|
||||
joinTimestamp: Date.parse(member.join_timestamp),
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordThreadMembersUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordThreadMembersUpdate;
|
||||
bot.events.threadMembersUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
addedMembers: payload.added_members?.map((member) => bot.transformers.threadMember(bot, member)),
|
||||
removedMemberIds: payload.removed_member_ids?.map((id) => bot.transformers.snowflake(id)),
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordThreadMemberUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordThreadMemberUpdate;
|
||||
|
||||
bot.events.threadMemberUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
joinedAt: Date.parse(payload.joined_at),
|
||||
flags: payload.flags,
|
||||
});
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordChannel;
|
||||
|
||||
bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export * from "./CHANNEL_CREATE.ts";
|
||||
export * from "./CHANNEL_DELETE.ts";
|
||||
export * from "./CHANNEL_PINS_UPDATE.ts";
|
||||
export * from "./CHANNEL_UPDATE.ts";
|
||||
export * from "./STAGE_INSTANCE_CREATE.ts";
|
||||
export * from "./STAGE_INSTANCE_DELETE.ts";
|
||||
export * from "./STAGE_INSTANCE_UPDATE.ts";
|
||||
export * from "./THREAD_CREATE.ts";
|
||||
export * from "./THREAD_DELETE.ts";
|
||||
export * from "./THREAD_LIST_SYNC.ts";
|
||||
export * from "./THREAD_MEMBERS_UPDATE.ts";
|
||||
export * from "./THREAD_UPDATE.ts";
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from "../../types/discord.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildEmojisUpdate;
|
||||
|
||||
bot.events.guildEmojisUpdate(bot, {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
emojis: new Collection(payload.emojis.map((emoji) => [bot.transformers.snowflake(emoji.id!), emoji])),
|
||||
});
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./GUILD_EMOJIS_UPDATE.ts";
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
|
||||
await bot.events.guildBanRemove(
|
||||
bot,
|
||||
bot.transformers.user(bot, payload.user),
|
||||
bot.transformers.snowflake(payload.guild_id),
|
||||
);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordUnavailableGuild } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordUnavailableGuild;
|
||||
bot.events.guildDelete(bot, bot.transformers.snowflake(payload.id), shardId);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildIntegrationsUpdate;
|
||||
|
||||
bot.events.integrationUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id) });
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildLoaded(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
const guild = bot.transformers.guild(bot, { guild: payload, shardId });
|
||||
bot.events.guildLoaded(bot, guild as Guild);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordAutoModerationActionExecution, DiscordGatewayPayload } from "../../../types/discord.ts";
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationActionExecution(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordAutoModerationActionExecution;
|
||||
bot.events.automodActionExecution(bot, bot.transformers.automodActionExecution(bot, payload));
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../types/discord.ts";
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordAutoModerationRule;
|
||||
bot.events.automodRuleCreate(bot, bot.transformers.automodRule(bot, payload));
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../types/discord.ts";
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordAutoModerationRule;
|
||||
bot.events.automodRuleDelete(bot, bot.transformers.automodRule(bot, payload));
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../types/discord.ts";
|
||||
|
||||
/** Requires the MANAGE_GUILD permission. */
|
||||
export function handleAutoModerationRuleUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordAutoModerationRule;
|
||||
bot.events.automodRuleUpdate(bot, bot.transformers.automodRule(bot, payload));
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export * from "./scheduledEvents/mod.ts";
|
||||
|
||||
export * from "./GUILD_BAN_ADD.ts";
|
||||
export * from "./GUILD_BAN_REMOVE.ts";
|
||||
export * from "./GUILD_CREATE.ts";
|
||||
export * from "./GUILD_DELETE.ts";
|
||||
export * from "./GUILD_INTEGRATIONS_UPDATE.ts";
|
||||
export * from "./GUILD_LOADED_DD.ts";
|
||||
export * from "./GUILD_UPDATE.ts";
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventCreate(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventDelete(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventUpdate(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordScheduledEventUserAdd;
|
||||
|
||||
return bot.events.scheduledEventUserAdd(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordScheduledEventUserRemove;
|
||||
|
||||
return bot.events.scheduledEventUserRemove(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
});
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export * from "./GUILD_SCHEDULED_EVENT_CREATE.ts";
|
||||
export * from "./GUILD_SCHEDULED_EVENT_DELETE.ts";
|
||||
export * from "./GUILD_SCHEDULED_EVENT_UPDATE.ts";
|
||||
export * from "./GUILD_SCHEDULED_EVENT_USER_ADD.ts";
|
||||
export * from "./GUILD_SCHEDULED_EVENT_USER_REMOVE.ts";
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.integrationCreate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationDelete } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordIntegrationDelete;
|
||||
|
||||
bot.events.integrationDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
applicationId: payload.application_id ? bot.transformers.snowflake(payload.application_id) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.integrationUpdate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "./INTEGRATION_CREATE.ts";
|
||||
export * from "./INTEGRATION_DELETE.ts";
|
||||
export * from "./INTEGRATION_UPDATE.ts";
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordInteraction } from "../../types/discord.ts";
|
||||
|
||||
export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as DiscordInteraction).id));
|
||||
bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as DiscordInteraction));
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./INTERACTION_CREATE.ts";
|
||||
@@ -1,6 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordInviteCreate } from "../../types/discord.ts";
|
||||
|
||||
export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as DiscordInviteCreate));
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordInviteDelete } from "../../types/discord.ts";
|
||||
|
||||
export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordInviteDelete;
|
||||
|
||||
bot.events.inviteDelete(bot, {
|
||||
/** The channel of the invite */
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
/** The guild of the invite */
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
/** The unique invite code */
|
||||
code: payload.code,
|
||||
});
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./INVITE_CREATE.ts";
|
||||
export * from "./INVITE_DELETE.ts";
|
||||
@@ -1,37 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { statusTypes } from "../../transformers/presence.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMembersChunk } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMembersChunk;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
|
||||
if (payload.nonce && payload.chunk_index >= payload.chunk_count - 1) {
|
||||
bot.cache.fetchAllMembersProcessingRequests.get(payload.nonce)?.(
|
||||
`Member fetching complete. Nonce: ${payload.nonce}`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
guildId,
|
||||
members: payload.members.map((m) =>
|
||||
bot.transformers.member(bot, m, guildId, bot.transformers.snowflake(m.user.id))
|
||||
),
|
||||
chunkIndex: payload.chunk_index,
|
||||
chunkCount: payload.chunk_count,
|
||||
notFound: payload.not_found?.map((id) => bot.transformers.snowflake(id)),
|
||||
presences: payload.presences?.map((presence) => ({
|
||||
user: bot.transformers.user(bot, presence.user),
|
||||
guildId,
|
||||
status: statusTypes[presence.status],
|
||||
activities: presence.activities.map((activity) => bot.transformers.activity(bot, activity)),
|
||||
clientStatus: {
|
||||
desktop: presence.client_status.desktop,
|
||||
mobile: presence.client_status.mobile,
|
||||
web: presence.client_status.web,
|
||||
},
|
||||
})),
|
||||
nonce: payload.nonce,
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberAdd } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberAdd;
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
const member = bot.transformers.member(bot, payload, guildId, user.id);
|
||||
bot.events.guildMemberAdd(bot, member, user);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberRemove;
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
|
||||
bot.events.guildMemberRemove(bot, user, guildId);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildMemberUpdate;
|
||||
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
bot.events.guildMemberUpdate(
|
||||
bot,
|
||||
bot.transformers.member(bot, payload, bot.transformers.snowflake(payload.guild_id), user.id),
|
||||
user,
|
||||
);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from "./GUILD_MEMBER_ADD.ts";
|
||||
export * from "./GUILD_MEMBER_REMOVE.ts";
|
||||
export * from "./GUILD_MEMBER_UPDATE.ts";
|
||||
export * from "./GUILD_MEMBERS_CHUNK.ts";
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessage;
|
||||
|
||||
bot.events.messageCreate(bot, bot.transformers.message(bot, payload));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageDelete } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageDelete;
|
||||
|
||||
bot.events.messageDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageDeleteBulk } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageDeleteBulk;
|
||||
|
||||
const channelId = bot.transformers.snowflake(payload.channel_id);
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
|
||||
bot.events.messageDeleteBulk(bot, {
|
||||
ids: payload.ids.map((id) => bot.transformers.snowflake(id)),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionAdd } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageReactionAdd;
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
const userId = bot.transformers.snowflake(payload.user_id);
|
||||
bot.events.reactionAdd(bot, {
|
||||
userId,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId,
|
||||
member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
|
||||
user: payload.member ? bot.transformers.user(bot, payload.member.user) : undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji),
|
||||
});
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageReactionRemove;
|
||||
|
||||
bot.events.reactionRemove(bot, {
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji),
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageReactionRemoveAll;
|
||||
|
||||
bot.events.reactionRemoveAll(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessageReactionRemoveEmoji;
|
||||
|
||||
bot.events.reactionRemoveEmoji(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji),
|
||||
});
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessage;
|
||||
if (!payload.edited_timestamp) return;
|
||||
|
||||
bot.events.messageUpdate(bot, bot.transformers.message(bot, payload));
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export * from "./MESSAGE_CREATE.ts";
|
||||
export * from "./MESSAGE_DELETE_BULK.ts";
|
||||
export * from "./MESSAGE_DELETE.ts";
|
||||
export * from "./MESSAGE_REACTION_ADD.ts";
|
||||
export * from "./MESSAGE_REACTION_REMOVE_ALL.ts";
|
||||
export * from "./MESSAGE_REACTION_REMOVE_EMOJI.ts";
|
||||
export * from "./MESSAGE_REACTION_REMOVE.ts";
|
||||
export * from "./MESSAGE_UPDATE.ts";
|
||||
@@ -1,6 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordPresenceUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.presenceUpdate(bot, bot.transformers.presence(bot, data.d as DiscordPresenceUpdate));
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordReady } from "../../types/discord.ts";
|
||||
|
||||
export function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordReady;
|
||||
// Triggered on each shard
|
||||
bot.events.ready(
|
||||
bot,
|
||||
{
|
||||
shardId,
|
||||
v: payload.v,
|
||||
user: bot.transformers.user(bot, payload.user),
|
||||
guilds: payload.guilds.map((p) => bot.transformers.snowflake(p.id)),
|
||||
sessionId: payload.session_id,
|
||||
shard: payload.shard,
|
||||
applicationId: bot.transformers.snowflake(payload.application.id),
|
||||
},
|
||||
payload,
|
||||
);
|
||||
|
||||
if (!bot.id) bot.id = bot.transformers.snowflake(payload.user.id);
|
||||
if (!bot.applicationId) bot.applicationId = bot.transformers.snowflake(payload.application.id);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordTypingStart } from "../../types/discord.ts";
|
||||
|
||||
export function handleTypingStart(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordTypingStart;
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
const userId = bot.transformers.snowflake(payload.user_id);
|
||||
|
||||
bot.events.typingStart(bot, {
|
||||
guildId,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
userId,
|
||||
timestamp: payload.timestamp,
|
||||
member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordUser } from "../../types/discord.ts";
|
||||
|
||||
export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordUser;
|
||||
bot.events.botUpdate(bot, bot.transformers.user(bot, payload));
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from "./PRESENCE_UPDATE.ts";
|
||||
export * from "./READY.ts";
|
||||
export * from "./TYPING_START.ts";
|
||||
export * from "./USER_UPDATE.ts";
|
||||
@@ -1,12 +0,0 @@
|
||||
export * from "./channels/mod.ts";
|
||||
export * from "./emojis/mod.ts";
|
||||
export * from "./guilds/mod.ts";
|
||||
export * from "./integrations/mod.ts";
|
||||
export * from "./interactions/mod.ts";
|
||||
export * from "./invites/mod.ts";
|
||||
export * from "./members/mod.ts";
|
||||
export * from "./messages/mod.ts";
|
||||
export * from "./misc/mod.ts";
|
||||
export * from "./roles/mod.ts";
|
||||
export * from "./voice/mod.ts";
|
||||
export * from "./webhooks/mod.ts";
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleCreate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleCreate;
|
||||
bot.events.roleCreate(
|
||||
bot,
|
||||
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }),
|
||||
);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleDelete } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleDelete;
|
||||
bot.events.roleDelete(bot, {
|
||||
roleId: bot.transformers.snowflake(payload.role_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
});
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordGuildRoleUpdate;
|
||||
|
||||
bot.events.roleUpdate(
|
||||
bot,
|
||||
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }),
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "./GUILD_ROLE_CREATE.ts";
|
||||
export * from "./GUILD_ROLE_DELETE.ts";
|
||||
export * from "./GUILD_ROLE_UPDATE.ts";
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordVoiceServerUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordVoiceServerUpdate;
|
||||
|
||||
bot.events.voiceServerUpdate(bot, {
|
||||
token: payload.token,
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
endpoint: payload.endpoint ?? undefined,
|
||||
});
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordVoiceState } from "../../types/discord.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordVoiceState;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
|
||||
bot.events.voiceStateUpdate(bot, bot.transformers.voiceState(bot, { voiceState: payload, guildId }));
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./VOICE_SERVER_UPDATE.ts";
|
||||
export * from "./VOICE_STATE_UPDATE.ts";
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload, DiscordWebhookUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordWebhookUpdate;
|
||||
bot.events.webhooksUpdate(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
});
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./WEBHOOKS_UPDATE.ts";
|
||||
Reference in New Issue
Block a user