mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
fix
This commit is contained in:
@@ -1,19 +1,17 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordApplicationCommandCreateUpdateDelete } from "../../types/interactions/application_command_create_update_delete.ts";
|
import {
|
||||||
|
ApplicationCommandCreateUpdateDelete,
|
||||||
|
DiscordApplicationCommandCreateUpdateDelete,
|
||||||
|
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandCreate(
|
export function handleApplicationCommandCreate(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
) {
|
) {
|
||||||
const {
|
eventHandlers.applicationCommandCreate?.(
|
||||||
guild_id: guildId,
|
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||||
application_id: applicationId,
|
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||||
...rest
|
),
|
||||||
} = data.d as DiscordApplicationCommandCreateUpdateDelete;
|
);
|
||||||
|
|
||||||
eventHandlers.applicationCommandCreate?.({
|
|
||||||
...rest,
|
|
||||||
guildId,
|
|
||||||
applicationId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordApplicationCommandCreateUpdateDelete } from "../../types/interactions/application_command_create_update_delete.ts";
|
import {
|
||||||
|
ApplicationCommandCreateUpdateDelete,
|
||||||
|
DiscordApplicationCommandCreateUpdateDelete,
|
||||||
|
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
||||||
const {
|
eventHandlers.applicationCommandDelete?.(
|
||||||
application_id: applicationId,
|
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||||
guild_id: guildId,
|
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||||
...rest
|
),
|
||||||
} = data.d as DiscordApplicationCommandCreateUpdateDelete;
|
);
|
||||||
|
|
||||||
eventHandlers.applicationCommandDelete?.({
|
|
||||||
...rest,
|
|
||||||
guildId,
|
|
||||||
applicationId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordApplicationCommandCreateUpdateDelete } from "../../types/interactions/application_command_create_update_delete.ts";
|
import {
|
||||||
|
ApplicationCommandCreateUpdateDelete,
|
||||||
|
DiscordApplicationCommandCreateUpdateDelete,
|
||||||
|
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
||||||
const {
|
const {
|
||||||
@@ -9,9 +13,9 @@ export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
|||||||
...rest
|
...rest
|
||||||
} = data.d as DiscordApplicationCommandCreateUpdateDelete;
|
} = data.d as DiscordApplicationCommandCreateUpdateDelete;
|
||||||
|
|
||||||
eventHandlers.applicationCommandUpdate?.({
|
eventHandlers.applicationCommandUpdate?.(
|
||||||
...rest,
|
snakeKeysToCamelCase<ApplicationCommandCreateUpdateDelete>(
|
||||||
guildId,
|
data.d as DiscordApplicationCommandCreateUpdateDelete,
|
||||||
applicationId,
|
),
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
|
||||||
import { DiscordGuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
|
import { DiscordGuildEmojisUpdate } 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) {
|
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuildEmojisUpdate;
|
const payload = data.d as DiscordGuildEmojisUpdate;
|
||||||
@@ -11,7 +11,7 @@ export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
const cachedEmojis = guild.emojis;
|
const cachedEmojis = guild.emojis;
|
||||||
guild.emojis = new Collection(
|
guild.emojis = new Collection(
|
||||||
payload.emojis.map((emoji) => [emoji.id ?? emoji.name, emoji]),
|
payload.emojis.map((emoji) => [emoji.id!, emoji]),
|
||||||
);
|
);
|
||||||
|
|
||||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
|||||||
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
||||||
const different = (cachedValue.length !== value.length) ||
|
const different = (cachedValue.length !== value.length) ||
|
||||||
cachedValue.find((val) => !value.includes(val)) ||
|
cachedValue.find((val) => !value.includes(val)) ||
|
||||||
|
// TODO: check if this really works hehe
|
||||||
|
// @ts-ignore this works ts is wrong
|
||||||
value.find((val) => !cachedValue.includes(val));
|
value.find((val) => !cachedValue.includes(val));
|
||||||
if (!different) return;
|
if (!different) return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|||||||
export function handleIntegrationCreate(
|
export function handleIntegrationCreate(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
) {
|
) {
|
||||||
const payload = data.d as DiscordIntegrationCreateUpdate;
|
|
||||||
|
|
||||||
eventHandlers.integrationCreate?.(
|
eventHandlers.integrationCreate?.(
|
||||||
snakeKeysToCamelCase(payload) as IntegrationCreateUpdate,
|
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||||
|
data.d as DiscordIntegrationCreateUpdate,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
|
import { IntegrationCreateUpdate } from "../../types/integration/integration_create_update.ts";
|
||||||
import {
|
import {
|
||||||
DiscordIntegrationDelete,
|
DiscordIntegrationDelete,
|
||||||
IntegrationDelete,
|
|
||||||
} from "../../types/integration/integration_delete.ts";
|
} from "../../types/integration/integration_delete.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleIntegrationDelete(data: DiscordGatewayPayload) {
|
export function handleIntegrationDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordIntegrationDelete;
|
|
||||||
|
|
||||||
eventHandlers.integrationDelete?.(
|
eventHandlers.integrationDelete?.(
|
||||||
snakeKeysToCamelCase(payload) as IntegrationDelete,
|
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||||
|
data.d as DiscordIntegrationDelete,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import {
|
|||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
|
export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordIntegrationCreateUpdate;
|
|
||||||
|
|
||||||
eventHandlers.integrationUpdate?.(
|
eventHandlers.integrationUpdate?.(
|
||||||
snakeKeysToCamelCase(payload) as IntegrationCreateUpdate,
|
snakeKeysToCamelCase<IntegrationCreateUpdate>(
|
||||||
|
data.d as DiscordIntegrationCreateUpdate,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
// TODO: DM support idk need to discuss how we solve this
|
||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
|
import { Interaction } from "../../types/mod.ts";
|
||||||
|
|
||||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as InteractionCommandPayload;
|
const payload = data.d as Interaction;
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
payload.member,
|
payload.member,
|
||||||
payload.guild_id,
|
payload.guild_id,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordInviteCreate;
|
eventHandlers.inviteCreate?.(
|
||||||
|
snakeKeysToCamelCase<InviteCreate>(data.d as DiscordInviteCreate),
|
||||||
eventHandlers.inviteCreate?.(snakeKeysToCamelCase(payload) as InviteCreate);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordInviteDelete;
|
eventHandlers.inviteDelete?.(
|
||||||
|
snakeKeysToCamelCase<InviteDelete>(data.d as DiscordInviteDelete),
|
||||||
eventHandlers.inviteDelete?.(snakeKeysToCamelCase(payload) as InviteDelete);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
|||||||
guild,
|
guild,
|
||||||
discordenoMember,
|
discordenoMember,
|
||||||
payload.nick!,
|
payload.nick!,
|
||||||
guildMember.nick,
|
guildMember.nick ?? undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { botId, eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordMessageReactionAdd } from "../../types/messages/message_reaction_add.ts";
|
import {
|
||||||
|
DiscordMessageReactionAdd,
|
||||||
|
MessageReactionAdd,
|
||||||
|
} from "../../types/messages/message_reaction_add.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordMessageReactionAdd;
|
const payload = data.d as DiscordMessageReactionAdd;
|
||||||
@@ -41,17 +45,8 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uncachedOptions = {
|
|
||||||
...payload,
|
|
||||||
id: payload.message_id,
|
|
||||||
channelId: payload.channel_id,
|
|
||||||
guildId: payload.guild_id || "",
|
|
||||||
};
|
|
||||||
|
|
||||||
eventHandlers.reactionAdd?.(
|
eventHandlers.reactionAdd?.(
|
||||||
uncachedOptions,
|
snakeKeysToCamelCase<MessageReactionAdd>(payload),
|
||||||
payload.emoji,
|
|
||||||
payload.user_id,
|
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordMessageReactionRemove } from "../../types/messages/message_reaction_remove.ts";
|
import {
|
||||||
|
DiscordMessageReactionRemove,
|
||||||
|
MessageReactionRemove,
|
||||||
|
} from "../../types/messages/message_reaction_remove.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemove(
|
export async function handleMessageReactionRemove(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
@@ -18,24 +22,17 @@ export async function handleMessageReactionRemove(
|
|||||||
|
|
||||||
if (reaction) {
|
if (reaction) {
|
||||||
reaction.count--;
|
reaction.count--;
|
||||||
if (reaction.count === 0) message.reactions = message.reactions?.filter(r => r.count !== 0);
|
if (reaction.count === 0) {
|
||||||
|
message.reactions = message.reactions?.filter((r) => r.count !== 0);
|
||||||
|
}
|
||||||
if (!message.reactions?.length) message.reactions = undefined;
|
if (!message.reactions?.length) message.reactions = undefined;
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uncachedOptions = {
|
|
||||||
...payload,
|
|
||||||
id: payload.message_id,
|
|
||||||
channelId: payload.channel_id,
|
|
||||||
guildId: payload.guild_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
eventHandlers.reactionRemove?.(
|
eventHandlers.reactionRemove?.(
|
||||||
uncachedOptions,
|
snakeKeysToCamelCase<MessageReactionRemove>(payload),
|
||||||
payload.emoji,
|
|
||||||
payload.user_id,
|
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordMessageReactionRemoveAll } from "../../types/messages/message_reaction_remove_all.ts";
|
import {
|
||||||
|
DiscordMessageReactionRemoveAll,
|
||||||
|
MessageReactionRemoveAll,
|
||||||
|
} from "../../types/messages/message_reaction_remove_all.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemoveAll(
|
export async function handleMessageReactionRemoveAll(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
@@ -15,5 +19,8 @@ export async function handleMessageReactionRemoveAll(
|
|||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventHandlers.reactionRemoveAll?.(payload);
|
eventHandlers.reactionRemoveAll?.(
|
||||||
|
snakeKeysToCamelCase<MessageReactionRemoveAll>(payload),
|
||||||
|
message,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,15 @@ export async function handleMessageReactionRemoveEmoji(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!message.reactions.length) message.reactions = undefined
|
if (!message.reactions.length) message.reactions = undefined;
|
||||||
|
|
||||||
await cacheHandlers.set("messages", payload.message_id, message);
|
await cacheHandlers.set("messages", payload.message_id, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventHandlers.reactionRemoveEmoji?.(
|
eventHandlers.reactionRemoveEmoji?.(
|
||||||
data.d,
|
payload.emoji,
|
||||||
|
payload.message_id,
|
||||||
|
payload.channel_id,
|
||||||
|
payload.guild_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,22 +9,13 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
|||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
const cachedMessage = await cacheHandlers.get("messages", payload.id);
|
const oldMessage = await cacheHandlers.get("messages", payload.id);
|
||||||
if (!cachedMessage) return;
|
if (!oldMessage) return;
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
attachments: cachedMessage.attachments,
|
|
||||||
content: cachedMessage.content,
|
|
||||||
embeds: cachedMessage.embeds,
|
|
||||||
editedTimestamp: cachedMessage.editedTimestamp,
|
|
||||||
tts: cachedMessage.tts,
|
|
||||||
pinned: cachedMessage.pinned,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Messages with embeds can trigger update but they wont have edited_timestamp
|
// Messages with embeds can trigger update but they wont have edited_timestamp
|
||||||
if (
|
if (
|
||||||
!payload.edited_timestamp ||
|
!payload.edited_timestamp ||
|
||||||
(cachedMessage.content === payload.content)
|
(oldMessage.content === payload.content)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordPresenceUpdate } from "../../types/misc/presence_update.ts";
|
import {
|
||||||
|
DiscordPresenceUpdate,
|
||||||
|
PresenceUpdate,
|
||||||
|
} from "../../types/misc/presence_update.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordPresenceUpdate;
|
const payload = snakeKeysToCamelCase<PresenceUpdate>(
|
||||||
|
data.d as DiscordPresenceUpdate,
|
||||||
|
);
|
||||||
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
|
||||||
await cacheHandlers.set("presences", payload.user.id, payload);
|
await cacheHandlers.set("presences", payload.user.id, payload);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
|||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordReady } from "../../types/gateway/ready.ts";
|
import { DiscordReady } from "../../types/gateway/ready.ts";
|
||||||
import { delay, snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { DiscordGuildMemberWithUser } from "../../types/mod.ts";
|
||||||
|
import { camelKeysToSnakeCase, delay } from "../../util/utils.ts";
|
||||||
import { ws } from "../../ws/ws.ts";
|
import { ws } from "../../ws/ws.ts";
|
||||||
|
|
||||||
export async function handleReady(
|
export async function handleReady(
|
||||||
@@ -103,7 +104,7 @@ async function loaded(shardId: number) {
|
|||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
members.map(async (member) => {
|
members.map(async (member) => {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
snakeKeysToCamelCase(member),
|
camelKeysToSnakeCase<DiscordGuildMemberWithUser>(member),
|
||||||
guildId,
|
guildId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordTypingStart } from "../../types/misc/typing_start.ts";
|
import {
|
||||||
|
DiscordTypingStart,
|
||||||
|
TypingStart,
|
||||||
|
} from "../../types/misc/typing_start.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export function handleTypingStart(data: DiscordGatewayPayload) {
|
export function handleTypingStart(data: DiscordGatewayPayload) {
|
||||||
eventHandlers.typingStart?.(data.d as DiscordTypingStart);
|
eventHandlers.typingStart?.(
|
||||||
|
snakeKeysToCamelCase<TypingStart>(data.d as DiscordTypingStart),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
|
import { DiscordGuildRoleCreate } from "../../types/mod.ts";
|
||||||
|
|
||||||
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuildRoleCreateUpdate;
|
const payload = data.d as DiscordGuildRoleCreate;
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
|
import { DiscordGuildRoleUpdate } from "../../types/mod.ts";
|
||||||
|
|
||||||
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordGuildRoleCreateUpdate;
|
const payload = data.d as DiscordGuildRoleUpdate;
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordVoiceServerUpdate, VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
|
import {
|
||||||
|
DiscordVoiceServerUpdate,
|
||||||
|
VoiceServerUpdate,
|
||||||
|
} from "../../types/voice/voice_server_update.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = snakeKeysToCamelCase(data.d as DiscordVoiceServerUpdate) as VoiceServerUpdate;
|
const payload = snakeKeysToCamelCase<VoiceServerUpdate>(
|
||||||
|
data.d as DiscordVoiceServerUpdate,
|
||||||
|
);
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|||||||
@@ -2,51 +2,58 @@ import { eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordVoiceState } from "../../types/voice/voice_state.ts";
|
import { DiscordGuildMemberWithUser } from "../../types/mod.ts";
|
||||||
|
import {
|
||||||
|
DiscordVoiceState,
|
||||||
|
VoiceState,
|
||||||
|
} from "../../types/voice/voice_state.ts";
|
||||||
|
import {
|
||||||
|
camelKeysToSnakeCase,
|
||||||
|
snakeKeysToCamelCase,
|
||||||
|
} from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordVoiceState;
|
const payload = snakeKeysToCamelCase<VoiceState>(
|
||||||
if (!payload.guild_id) return;
|
data.d as DiscordVoiceState,
|
||||||
|
);
|
||||||
|
if (!payload.guildId) return;
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
const guild = await cacheHandlers.get("guilds", payload.guildId);
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const member = payload.member
|
const member = payload.member
|
||||||
? await structures.createDiscordenoMember(payload.member, guild.id)
|
? await structures.createDiscordenoMember(
|
||||||
: await cacheHandlers.get("members", payload.user_id);
|
camelKeysToSnakeCase<DiscordGuildMemberWithUser>(payload),
|
||||||
|
guild.id,
|
||||||
|
)
|
||||||
|
: await cacheHandlers.get("members", payload.userId);
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
|
|
||||||
// No cached state before so lets make one for em
|
// No cached state before so lets make one for em
|
||||||
const cachedState = guild.voiceStates.get(payload.user_id);
|
const cachedState = guild.voiceStates.get(payload.userId);
|
||||||
|
|
||||||
guild.voiceStates.set(payload.user_id, {
|
guild.voiceStates.set(
|
||||||
...payload,
|
payload.userId,
|
||||||
guildId: payload.guild_id,
|
payload,
|
||||||
channelId: payload.channel_id || "",
|
);
|
||||||
userId: payload.user_id,
|
|
||||||
sessionId: payload.session_id,
|
|
||||||
selfDeaf: payload.self_deaf,
|
|
||||||
selfMute: payload.self_mute,
|
|
||||||
selfStream: payload.self_stream || false,
|
|
||||||
});
|
|
||||||
|
|
||||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
await cacheHandlers.set("guilds", payload.guildId, guild);
|
||||||
|
|
||||||
if (cachedState?.channelId !== payload.channel_id) {
|
if (cachedState?.channelId !== payload.channelId) {
|
||||||
// Either joined or moved channels
|
// Either joined or moved channels
|
||||||
if (payload.channel_id) {
|
if (payload.channelId) {
|
||||||
if (cachedState?.channelId) { // Was in a channel before
|
if (cachedState?.channelId) { // Was in a channel before
|
||||||
eventHandlers.voiceChannelSwitch?.(
|
eventHandlers.voiceChannelSwitch?.(
|
||||||
member,
|
member,
|
||||||
payload.channel_id,
|
payload.channelId,
|
||||||
cachedState.channelId,
|
cachedState.channelId,
|
||||||
);
|
);
|
||||||
} else { // Was not in a channel before so user just joined
|
} else { // Was not in a channel before so user just joined
|
||||||
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
eventHandlers.voiceChannelJoin?.(member, payload.channelId);
|
||||||
}
|
}
|
||||||
} // Left the channel
|
} // Left the channel
|
||||||
else if (cachedState?.channelId) {
|
else if (cachedState?.channelId) {
|
||||||
guild.voiceStates.delete(payload.user_id);
|
guild.voiceStates.delete(payload.userId);
|
||||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
|
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ export async function createEmoji(
|
|||||||
image,
|
image,
|
||||||
});
|
});
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as Emoji;
|
return snakeKeysToCamelCase<Emoji>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ export async function editWidget(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as GuildWidget;
|
return snakeKeysToCamelCase<GuildWidget>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,5 +26,5 @@ export async function getAuditLogs(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as AuditLog;
|
return snakeKeysToCamelCase<AuditLog>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ export async function getBan(guildId: string, memberId: string) {
|
|||||||
endpoints.GUILD_BAN(guildId, memberId),
|
endpoints.GUILD_BAN(guildId, memberId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as Ban;
|
return snakeKeysToCamelCase<Ban>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ export async function getBans(guildId: string) {
|
|||||||
)) as DiscordBan[];
|
)) as DiscordBan[];
|
||||||
|
|
||||||
return new Collection<string, Ban>(
|
return new Collection<string, Ban>(
|
||||||
results.map((res) => [res.user.id, snakeKeysToCamelCase(res) as Ban]),
|
results.map((res) => [res.user.id, snakeKeysToCamelCase<Ban>(res)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ export async function getGuild(guildId: string, counts = true) {
|
|||||||
with_counts: counts,
|
with_counts: counts,
|
||||||
});
|
});
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as Guild;
|
return snakeKeysToCamelCase<Guild>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|||||||
export async function getGuildPreview(guildId: string) {
|
export async function getGuildPreview(guildId: string) {
|
||||||
const result = await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId));
|
const result = await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId));
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as GuildPreview;
|
return snakeKeysToCamelCase<GuildPreview>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ export async function getVanityURL(guildId: string) {
|
|||||||
endpoints.GUILD_VANITY_URL(guildId),
|
endpoints.GUILD_VANITY_URL(guildId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result) as
|
return snakeKeysToCamelCase<
|
||||||
| (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
|
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
|
||||||
| { code: null };
|
code: null;
|
||||||
|
}
|
||||||
|
>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export async function createDiscordenoChannel(
|
|||||||
guildId: rawGuildId = "",
|
guildId: rawGuildId = "",
|
||||||
lastPinTimestamp,
|
lastPinTimestamp,
|
||||||
...rest
|
...rest
|
||||||
} = snakeKeysToCamelCase(data) as Channel;
|
} = snakeKeysToCamelCase<Channel>(data);
|
||||||
|
|
||||||
const props: Record<string, PropertyDescriptor> = {};
|
const props: Record<string, PropertyDescriptor> = {};
|
||||||
Object.keys(rest).forEach((key) => {
|
Object.keys(rest).forEach((key) => {
|
||||||
|
|||||||
@@ -18,14 +18,13 @@ import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts";
|
|||||||
import { DiscordGuild, Guild } from "../types/guilds/guild.ts";
|
import { DiscordGuild, Guild } from "../types/guilds/guild.ts";
|
||||||
import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts";
|
import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts";
|
||||||
import {
|
import {
|
||||||
DiscordGuildMember,
|
DiscordGuildMemberWithUser,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
} from "../types/guilds/guild_member.ts";
|
} from "../types/guilds/guild_member.ts";
|
||||||
import { ModifyGuild } from "../types/guilds/modify_guild.ts";
|
import { ModifyGuild } from "../types/guilds/modify_guild.ts";
|
||||||
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
||||||
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
||||||
import { PresenceUpdate } from "../types/misc/presence_update.ts";
|
import { PresenceUpdate } from "../types/misc/presence_update.ts";
|
||||||
import { DiscordUser } from "../types/users/user.ts";
|
|
||||||
import { VoiceState } from "../types/voice/voice_state.ts";
|
import { VoiceState } from "../types/voice/voice_state.ts";
|
||||||
import { Collection } from "../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import {
|
import {
|
||||||
@@ -128,7 +127,7 @@ export async function createDiscordenoGuild(
|
|||||||
emojis,
|
emojis,
|
||||||
members = [],
|
members = [],
|
||||||
...rest
|
...rest
|
||||||
} = snakeKeysToCamelCase(data) as Guild;
|
} = snakeKeysToCamelCase<Guild>(data);
|
||||||
|
|
||||||
const roles = await Promise.all(
|
const roles = await Promise.all(
|
||||||
(data.roles || []).map((role) =>
|
(data.roles || []).map((role) =>
|
||||||
@@ -189,9 +188,7 @@ export async function createDiscordenoGuild(
|
|||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
members.map(async (member) => {
|
members.map(async (member) => {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
camelKeysToSnakeCase(member) as Omit<DiscordGuildMember, "user"> & {
|
camelKeysToSnakeCase(member) as DiscordGuildMemberWithUser,
|
||||||
user: DiscordUser;
|
|
||||||
},
|
|
||||||
guild.id,
|
guild.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -220,7 +217,7 @@ export interface DiscordenoGuild extends
|
|||||||
| "emojis"
|
| "emojis"
|
||||||
> {
|
> {
|
||||||
/** Total number of members in this guild */
|
/** Total number of members in this guild */
|
||||||
memberCount?: number;
|
memberCount: number;
|
||||||
/** The roles in the guild */
|
/** The roles in the guild */
|
||||||
roles: Collection<string, DiscordenoRole>;
|
roles: Collection<string, DiscordenoRole>;
|
||||||
/** The presences of all the users in the guild. */
|
/** The presences of all the users in the guild. */
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import { addRole } from "../helpers/roles/add_role.ts";
|
|||||||
import { removeRole } from "../helpers/roles/remove_role.ts";
|
import { removeRole } from "../helpers/roles/remove_role.ts";
|
||||||
import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts";
|
import { CreateGuildBan } from "../types/guilds/create_guild_ban.ts";
|
||||||
import {
|
import {
|
||||||
DiscordGuildMember,
|
DiscordGuildMemberWithUser,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
|
GuildMemberWithUser,
|
||||||
} from "../types/guilds/guild_member.ts";
|
} from "../types/guilds/guild_member.ts";
|
||||||
import { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts";
|
import { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts";
|
||||||
import { CreateMessage } from "../types/messages/create_message.ts";
|
import { CreateMessage } from "../types/messages/create_message.ts";
|
||||||
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
import { DiscordImageFormat } from "../types/misc/image_format.ts";
|
||||||
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
import { DiscordImageSize } from "../types/misc/image_size.ts";
|
||||||
import { DiscordUser, User } from "../types/users/user.ts";
|
import { User } from "../types/users/user.ts";
|
||||||
import { Collection } from "../util/collection.ts";
|
import { Collection } from "../util/collection.ts";
|
||||||
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts";
|
||||||
import { DiscordenoGuild } from "./guild.ts";
|
import { DiscordenoGuild } from "./guild.ts";
|
||||||
@@ -73,7 +74,7 @@ const baseMember: Partial<DiscordenoMember> = {
|
|||||||
|
|
||||||
export async function createDiscordenoMember(
|
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
|
// 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: Omit<DiscordGuildMember, "user"> & { user: DiscordUser },
|
data: DiscordGuildMemberWithUser,
|
||||||
guildId: string,
|
guildId: string,
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
@@ -81,9 +82,7 @@ export async function createDiscordenoMember(
|
|||||||
joinedAt,
|
joinedAt,
|
||||||
premiumSince,
|
premiumSince,
|
||||||
...rest
|
...rest
|
||||||
} = snakeKeysToCamelCase(data) as Omit<GuildMember, "user"> & {
|
} = snakeKeysToCamelCase<GuildMemberWithUser>(data);
|
||||||
user: DiscordUser;
|
|
||||||
};
|
|
||||||
|
|
||||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||||
|
|
||||||
|
|||||||
+12
-14
@@ -39,9 +39,8 @@ const baseMessage: Partial<DiscordenoMessage> = {
|
|||||||
return this.member?.guilds.get(this.guildId);
|
return this.member?.guilds.get(this.guildId);
|
||||||
},
|
},
|
||||||
get link() {
|
get link() {
|
||||||
return `https://discord.com/channels/${this.guildId || "@me"}/${
|
return `https://discord.com/channels/${this.guildId ||
|
||||||
this.channelId
|
"@me"}/${this.channelId}/${this.id}`;
|
||||||
}/${this.id}`;
|
|
||||||
},
|
},
|
||||||
get mentionedRoles() {
|
get mentionedRoles() {
|
||||||
return this.mentionedRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
|
return this.mentionedRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
|
||||||
@@ -70,8 +69,7 @@ const baseMessage: Partial<DiscordenoMessage> = {
|
|||||||
return addReactions(this.channelId!, this.id!, reactions, ordered);
|
return addReactions(this.channelId!, this.id!, reactions, ordered);
|
||||||
},
|
},
|
||||||
reply(content) {
|
reply(content) {
|
||||||
const contentWithMention =
|
const contentWithMention = typeof content === "string"
|
||||||
typeof content === "string"
|
|
||||||
? {
|
? {
|
||||||
content,
|
content,
|
||||||
mentions: { repliedUser: true },
|
mentions: { repliedUser: true },
|
||||||
@@ -133,21 +131,21 @@ export async function createDiscordenoMessage(data: DiscordMessage) {
|
|||||||
mentionRoles,
|
mentionRoles,
|
||||||
editedTimestamp,
|
editedTimestamp,
|
||||||
...rest
|
...rest
|
||||||
} = snakeKeysToCamelCase(data) as Message;
|
} = snakeKeysToCamelCase<Message>(data);
|
||||||
|
|
||||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||||
for (const key of Object.keys(rest)) {
|
for (const key of Object.keys(rest)) {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.(
|
||||||
"loop",
|
"loop",
|
||||||
`Running for of loop in createDiscordenoMessage function.`
|
`Running for of loop in createDiscordenoMessage function.`,
|
||||||
);
|
);
|
||||||
// @ts-ignore index signature
|
// @ts-ignore index signature
|
||||||
props[key] = createNewProp(rest[key]);
|
props[key] = createNewProp(rest[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discord doesnt give guild id for getMessage() so this will fill it in
|
// Discord doesnt give guild id for getMessage() so this will fill it in
|
||||||
const guildIdFinal =
|
const guildIdFinal = guildId ||
|
||||||
guildId || (await cacheHandlers.get("channels", channelId))?.guildId || "";
|
(await cacheHandlers.get("channels", channelId))?.guildId || "";
|
||||||
|
|
||||||
const message: DiscordenoMessage = Object.create(baseMessage, {
|
const message: DiscordenoMessage = Object.create(baseMessage, {
|
||||||
...props,
|
...props,
|
||||||
@@ -167,7 +165,7 @@ export async function createDiscordenoMessage(data: DiscordMessage) {
|
|||||||
]),
|
]),
|
||||||
timestamp: createNewProp(Date.parse(data.timestamp)),
|
timestamp: createNewProp(Date.parse(data.timestamp)),
|
||||||
editedTimestamp: createNewProp(
|
editedTimestamp: createNewProp(
|
||||||
editedTimestamp ? Date.parse(editedTimestamp) : undefined
|
editedTimestamp ? Date.parse(editedTimestamp) : undefined,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,7 +207,7 @@ export interface DiscordenoMessage extends Message {
|
|||||||
/** Delete the message */
|
/** Delete the message */
|
||||||
delete(
|
delete(
|
||||||
reason?: string,
|
reason?: string,
|
||||||
delayMilliseconds?: number
|
delayMilliseconds?: number,
|
||||||
): ReturnType<typeof deleteMessage>;
|
): ReturnType<typeof deleteMessage>;
|
||||||
/** Edit the message */
|
/** Edit the message */
|
||||||
edit(content: string | EditMessage): ReturnType<typeof editMessage>;
|
edit(content: string | EditMessage): ReturnType<typeof editMessage>;
|
||||||
@@ -220,7 +218,7 @@ export interface DiscordenoMessage extends Message {
|
|||||||
/** Add multiple reactions to the message without or without order. */
|
/** Add multiple reactions to the message without or without order. */
|
||||||
addReactions(
|
addReactions(
|
||||||
reactions: string[],
|
reactions: string[],
|
||||||
ordered?: boolean
|
ordered?: boolean,
|
||||||
): ReturnType<typeof addReactions>;
|
): ReturnType<typeof addReactions>;
|
||||||
/** Send a inline reply to this message */
|
/** Send a inline reply to this message */
|
||||||
reply(content: string | CreateMessage): ReturnType<typeof sendMessage>;
|
reply(content: string | CreateMessage): ReturnType<typeof sendMessage>;
|
||||||
@@ -230,13 +228,13 @@ export interface DiscordenoMessage extends Message {
|
|||||||
alert(
|
alert(
|
||||||
content: string | CreateMessage,
|
content: string | CreateMessage,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
reason?: string
|
reason?: string,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
/** Send a inline reply to this message but then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */
|
/** Send a inline reply to this message but then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */
|
||||||
alertReply(
|
alertReply(
|
||||||
content: string | CreateMessage,
|
content: string | CreateMessage,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
reason?: string
|
reason?: string,
|
||||||
): Promise<unknown>;
|
): Promise<unknown>;
|
||||||
/** Remove all reactions */
|
/** Remove all reactions */
|
||||||
removeAllReactions(): ReturnType<typeof removeAllReactions>;
|
removeAllReactions(): ReturnType<typeof removeAllReactions>;
|
||||||
|
|||||||
@@ -71,9 +71,11 @@ export async function createDiscordenoRole(data: DiscordGuildRoleCreate) {
|
|||||||
const {
|
const {
|
||||||
tags = {},
|
tags = {},
|
||||||
...rest
|
...rest
|
||||||
} = snakeKeysToCamelCase({ guildId: data.guild_id, ...data.role }) as Role & {
|
} = snakeKeysToCamelCase<
|
||||||
|
Role & {
|
||||||
guildId: string;
|
guildId: string;
|
||||||
};
|
}
|
||||||
|
>({ guildId: data.guild_id, ...data.role });
|
||||||
|
|
||||||
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
const props: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||||
for (const key of Object.keys(rest)) {
|
for (const key of Object.keys(rest)) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { ApplicationCommandCreateUpdateDelete } from "../interactions/applicatio
|
|||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
DiscordGatewayPayload,
|
DiscordGatewayPayload,
|
||||||
DiscordMessageReactionRemoveAll,
|
|
||||||
Emoji,
|
Emoji,
|
||||||
GatewayPayload,
|
GatewayPayload,
|
||||||
IntegrationDelete,
|
IntegrationDelete,
|
||||||
@@ -18,6 +17,7 @@ import {
|
|||||||
InviteDelete,
|
InviteDelete,
|
||||||
MessageReactionAdd,
|
MessageReactionAdd,
|
||||||
MessageReactionRemove,
|
MessageReactionRemove,
|
||||||
|
MessageReactionRemoveAll,
|
||||||
PresenceUpdate,
|
PresenceUpdate,
|
||||||
TypingStart,
|
TypingStart,
|
||||||
User,
|
User,
|
||||||
@@ -30,15 +30,15 @@ import { GuildUpdateChange } from "./guild_update_change.ts";
|
|||||||
export interface EventHandlers {
|
export interface EventHandlers {
|
||||||
/** Sent when a new Slash Command is created, relevant to the current user. */
|
/** Sent when a new Slash Command is created, relevant to the current user. */
|
||||||
applicationCommandCreate?: (
|
applicationCommandCreate?: (
|
||||||
data: ApplicationCommandCreateUpdateDelete
|
data: ApplicationCommandCreateUpdateDelete,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a Slash Command relevant to the current user is updated. */
|
/** Sent when a Slash Command relevant to the current user is updated. */
|
||||||
applicationCommandUpdate?: (
|
applicationCommandUpdate?: (
|
||||||
data: ApplicationCommandCreateUpdateDelete
|
data: ApplicationCommandCreateUpdateDelete,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a Slash Command relevant to the current user is deleted. */
|
/** Sent when a Slash Command relevant to the current user is deleted. */
|
||||||
applicationCommandDelete?: (
|
applicationCommandDelete?: (
|
||||||
data: ApplicationCommandCreateUpdateDelete
|
data: ApplicationCommandCreateUpdateDelete,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when properties about the user change. */
|
/** Sent when properties about the user change. */
|
||||||
botUpdate?: (user: User) => unknown;
|
botUpdate?: (user: User) => unknown;
|
||||||
@@ -48,23 +48,29 @@ export interface EventHandlers {
|
|||||||
channelUpdate?: (channel: Channel, oldChannel: Channel) => unknown;
|
channelUpdate?: (channel: Channel, oldChannel: Channel) => unknown;
|
||||||
/** Sent when a channel relevant to the current user is deleted. */
|
/** Sent when a channel relevant to the current user is deleted. */
|
||||||
channelDelete?: (channel: Channel) => unknown;
|
channelDelete?: (channel: Channel) => unknown;
|
||||||
|
/** Sent when a message pin is updated */
|
||||||
|
channelPinsUpdate?: (
|
||||||
|
channel: DiscordenoChannel,
|
||||||
|
guild?: DiscordenoGuild,
|
||||||
|
lastPinTimestamp?: string | null,
|
||||||
|
) => unknown;
|
||||||
debug?: (args: string | DebugArg, data?: string) => unknown;
|
debug?: (args: string | DebugArg, data?: string) => unknown;
|
||||||
/** Sent before every event. Discordeno awaits the execution of this event before main event gets sent. */
|
/** Sent before every event. Discordeno awaits the execution of this event before main event gets sent. */
|
||||||
dispatchRequirements?: (
|
dispatchRequirements?: (
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
shardId: number
|
shardId: number,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user is banned from a guild. */
|
/** Sent when a user is banned from a guild. */
|
||||||
guildBanAdd?: (
|
guildBanAdd?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
user: User,
|
user: User,
|
||||||
member?: DiscordenoMember
|
member?: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user is unbanned from a guild. */
|
/** Sent when a user is unbanned from a guild. */
|
||||||
guildBanRemove?: (
|
guildBanRemove?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
user: User,
|
user: User,
|
||||||
member?: DiscordenoMember
|
member?: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/**
|
/**
|
||||||
* This event can be sent in three different scenarios:
|
* This event can be sent in three different scenarios:
|
||||||
@@ -77,12 +83,16 @@ export interface EventHandlers {
|
|||||||
guildCreate?: (guild: DiscordenoGuild) => unknown;
|
guildCreate?: (guild: DiscordenoGuild) => unknown;
|
||||||
/** This event does get sent on start when shards are loading the guilds */
|
/** This event does get sent on start when shards are loading the guilds */
|
||||||
guildLoaded?: (guild: DiscordenoGuild) => unknown;
|
guildLoaded?: (guild: DiscordenoGuild) => unknown;
|
||||||
/** When a guild goes unavailable this event will be ran. */
|
/** When a guild goes available this event will be ran. */
|
||||||
guildAvailable?: (guild: DiscordenoGuild) => unknown;
|
guildAvailable?: (guild: DiscordenoGuild) => unknown;
|
||||||
|
/** When a guild goes unavailable this event will be ran. */
|
||||||
|
guildUnavailable?: (guild: DiscordenoGuild) => unknown;
|
||||||
|
/** Sent when a guilds integration gets updated */
|
||||||
|
guildIntegrationsUpdate?: (guild: DiscordenoGuild) => unknown;
|
||||||
/** Sent when a guild is updated. */
|
/** Sent when a guild is updated. */
|
||||||
guildUpdate?: (
|
guildUpdate?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
changes: GuildUpdateChange[]
|
changes: GuildUpdateChange[],
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. If the `unavailable` field is not set, the user was removed from the guild. */
|
/** Sent when a guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. If the `unavailable` field is not set, the user was removed from the guild. */
|
||||||
guildDelete?: (guild: DiscordenoGuild) => unknown;
|
guildDelete?: (guild: DiscordenoGuild) => unknown;
|
||||||
@@ -90,54 +100,54 @@ export interface EventHandlers {
|
|||||||
guildEmojisUpdate?: (
|
guildEmojisUpdate?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
emojis: Collection<string, Emoji>,
|
emojis: Collection<string, Emoji>,
|
||||||
oldEmojis: Collection<string, Emoji>
|
oldEmojis: Collection<string, Emoji>,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a new user joins a guild. */
|
/** Sent when a new user joins a guild. */
|
||||||
guildMemberAdd?: (
|
guildMemberAdd?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember
|
member: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user is removed from a guild (leave/kick/ban). */
|
/** Sent when a user is removed from a guild (leave/kick/ban). */
|
||||||
guildMemberRemove?: (
|
guildMemberRemove?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
user: User,
|
user: User,
|
||||||
member?: DiscordenoMember
|
member?: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a guild member is updated. This will also fire when the user object of a guild member changes. */
|
/** Sent when a guild member is updated. This will also fire when the user object of a guild member changes. */
|
||||||
guildMemberUpdate?: (
|
guildMemberUpdate?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
oldMember?: DiscordenoMember
|
oldMember?: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
// TODO: remove this?
|
// TODO: remove this?
|
||||||
//heartbeat?: () => unknown;
|
//heartbeat?: () => unknown;
|
||||||
/** Sent when a user in a guild uses a Slash Command. */
|
/** Sent when a user in a guild uses a Slash Command. */
|
||||||
interactionCreate?: (
|
interactionCreate?: (
|
||||||
data: Omit<Interaction, "member"> & { member: DiscordenoMember }
|
data: Omit<Interaction, "member"> & { member: DiscordenoMember },
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a message is created. */
|
/** Sent when a message is created. */
|
||||||
messageCreate?: (message: DiscordenoMessage) => unknown;
|
messageCreate?: (message: DiscordenoMessage) => unknown;
|
||||||
/** Sent when a message is deleted. */
|
/** Sent when a message is deleted. */
|
||||||
messageDelete?: (
|
messageDelete?: (
|
||||||
partial: { id: string; channel: DiscordenoChannel },
|
partial: { id: string; channel: DiscordenoChannel },
|
||||||
message?: DiscordenoMessage
|
message?: DiscordenoMessage,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a message is updated. */
|
/** Sent when a message is updated. */
|
||||||
messageUpdate?: (
|
messageUpdate?: (
|
||||||
message: DiscordenoMessage,
|
message: DiscordenoMessage,
|
||||||
oldMessage: DiscordenoMessage
|
oldMessage: DiscordenoMessage,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user updates its nickname */
|
/** Sent when a user updates its nickname */
|
||||||
nicknameUpdate?: (
|
nicknameUpdate?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
nickname: string,
|
nickname: string,
|
||||||
oldNickname?: string
|
oldNickname?: string,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** A user's presence is their current state on a guild. This event is sent when a user's presence or info, such as name or avatar, is updated. */
|
/** A user's presence is their current state on a guild. This event is sent when a user's presence or info, such as name or avatar, is updated. */
|
||||||
presenceUpdate?: (
|
presenceUpdate?: (
|
||||||
presence: PresenceUpdate,
|
presence: PresenceUpdate,
|
||||||
oldPresence?: PerformanceEntry
|
oldPresence?: PresenceUpdate,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent before every event execution. Discordeno will not await its execution. */
|
/** Sent before every event execution. Discordeno will not await its execution. */
|
||||||
raw?: (data: GatewayPayload) => unknown;
|
raw?: (data: GatewayPayload) => unknown;
|
||||||
@@ -148,22 +158,24 @@ export interface EventHandlers {
|
|||||||
/** Sent when a user adds a reaction to a message. */
|
/** Sent when a user adds a reaction to a message. */
|
||||||
reactionAdd?: (
|
reactionAdd?: (
|
||||||
data: MessageReactionAdd,
|
data: MessageReactionAdd,
|
||||||
member?: DiscordenoMember,
|
message?: DiscordenoMessage,
|
||||||
message?: DiscordenoMessage
|
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user removes a reaction from a message. */
|
/** Sent when a user removes a reaction from a message. */
|
||||||
reactionRemove?: (
|
reactionRemove?: (
|
||||||
data: MessageReactionRemove,
|
data: MessageReactionRemove,
|
||||||
message?: DiscordenoMessage
|
message?: DiscordenoMessage,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a user explicitly removes all reactions from a message. */
|
/** Sent when a user explicitly removes all reactions from a message. */
|
||||||
reactionRemoveAll?: (payload: DiscordMessageReactionRemoveAll) => unknown;
|
reactionRemoveAll?: (
|
||||||
|
payload: MessageReactionRemoveAll,
|
||||||
|
message?: DiscordenoMessage,
|
||||||
|
) => unknown;
|
||||||
/** Sent when a bot removes all instances of a given emoji from the reactions of a message. */
|
/** Sent when a bot removes all instances of a given emoji from the reactions of a message. */
|
||||||
reactionRemoveEmoji?: (
|
reactionRemoveEmoji?: (
|
||||||
emoji: Partial<Emoji>,
|
emoji: Partial<Emoji>,
|
||||||
messageId: string,
|
messageId: string,
|
||||||
channelId: string,
|
channelId: string,
|
||||||
guildId?: string
|
guildId?: string,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a guild role is created. */
|
/** Sent when a guild role is created. */
|
||||||
roleCreate?: (guild: DiscordenoGuild, role: DiscordenoRole) => unknown;
|
roleCreate?: (guild: DiscordenoGuild, role: DiscordenoRole) => unknown;
|
||||||
@@ -173,19 +185,24 @@ export interface EventHandlers {
|
|||||||
roleUpdate?: (
|
roleUpdate?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
role: DiscordenoRole,
|
role: DiscordenoRole,
|
||||||
old: DiscordenoRole
|
old: DiscordenoRole,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
roleGained?: (
|
roleGained?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
roleId: string
|
roleId: string,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
roleLost?: (
|
roleLost?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
roleId: string
|
roleId: string,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
shardReady?: (shardId: number) => unknown;
|
shardReady?: (shardId: number) => unknown;
|
||||||
|
/** Sent when a shard failed to load. */
|
||||||
|
shardFailedToLoad?: (
|
||||||
|
shardId: number,
|
||||||
|
unavailableGuildIds: Set<string>,
|
||||||
|
) => unknown;
|
||||||
/** Sent when a user starts typing in a channel. */
|
/** Sent when a user starts typing in a channel. */
|
||||||
typingStart?: (data: TypingStart) => unknown;
|
typingStart?: (data: TypingStart) => unknown;
|
||||||
/** Sent when a user joins a voice channel */
|
/** Sent when a user joins a voice channel */
|
||||||
@@ -196,24 +213,24 @@ export interface EventHandlers {
|
|||||||
voiceChannelSwitch?: (
|
voiceChannelSwitch?: (
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
channelId: string,
|
channelId: string,
|
||||||
oldChannelId: string
|
oldChannelId: string,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a voice server is updated with information for making the bot connect to a voice channel. */
|
/** Sent when a voice server is updated with information for making the bot connect to a voice channel. */
|
||||||
voiceServerUpdate?: (
|
voiceServerUpdate?: (
|
||||||
payload: VoiceServerUpdate,
|
payload: VoiceServerUpdate,
|
||||||
guild: DiscordenoGuild
|
guild: DiscordenoGuild,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when someone joins/leaves/moves voice channels. */
|
/** Sent when someone joins/leaves/moves voice channels. */
|
||||||
voiceStateUpdate?: (
|
voiceStateUpdate?: (
|
||||||
member: DiscordenoMember,
|
member: DiscordenoMember,
|
||||||
voiceState: VoiceState
|
voiceState: VoiceState,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when a guild channel's webhook is created, updated, or deleted. */
|
/** Sent when a guild channel's webhook is created, updated, or deleted. */
|
||||||
webhooksUpdate?: (channelId: string, guildId: string) => unknown;
|
webhooksUpdate?: (channelId: string, guildId: string) => unknown;
|
||||||
/** Sent when a member has passed the guild's Membership Screening requirements */
|
/** Sent when a member has passed the guild's Membership Screening requirements */
|
||||||
membershipScreeningPassed?: (
|
membershipScreeningPassed?: (
|
||||||
guild: DiscordenoGuild,
|
guild: DiscordenoGuild,
|
||||||
member: DiscordenoMember
|
member: DiscordenoMember,
|
||||||
) => unknown;
|
) => unknown;
|
||||||
/** Sent when an integration is created on a server such as twitch, youtube etc.. */
|
/** Sent when an integration is created on a server such as twitch, youtube etc.. */
|
||||||
integrationCreate?: (data: IntegrationCreateUpdate) => unknown;
|
integrationCreate?: (data: IntegrationCreateUpdate) => unknown;
|
||||||
|
|||||||
@@ -22,3 +22,11 @@ export interface GuildMember {
|
|||||||
|
|
||||||
/** https://discord.com/developers/docs/resources/guild#guild-member-object */
|
/** https://discord.com/developers/docs/resources/guild#guild-member-object */
|
||||||
export type DiscordGuildMember = SnakeCasedPropertiesDeep<GuildMember>;
|
export type DiscordGuildMember = SnakeCasedPropertiesDeep<GuildMember>;
|
||||||
|
|
||||||
|
// We use these types much since user always exists unless its a `CREATE_MESSAGE` or `MESSAGE_UPDATE` event
|
||||||
|
|
||||||
|
export type GuildMemberWithUser = Omit<GuildMember, "user"> & { user: User };
|
||||||
|
/** https://discord.com/developers/docs/resources/guild#guild-member-object */
|
||||||
|
export type DiscordGuildMemberWithUser = SnakeCasedPropertiesDeep<
|
||||||
|
GuildMemberWithUser
|
||||||
|
>;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { GuildMember } from "../guilds/guild_member.ts";
|
import { GuildMemberWithUser } from "../guilds/guild_member.ts";
|
||||||
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
||||||
|
|
||||||
export interface GuildMemberAdd extends GuildMember {
|
export interface GuildMemberAdd extends GuildMemberWithUser {
|
||||||
/** id of the guild */
|
/** id of the guild */
|
||||||
guildId: string;
|
guildId: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GuildMember } from "../guilds/guild_member.ts";
|
import { GuildMemberWithUser } from "../guilds/guild_member.ts";
|
||||||
import { PresenceUpdate } from "../misc/presence_update.ts";
|
import { PresenceUpdate } from "../misc/presence_update.ts";
|
||||||
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ export interface GuildMembersChunk {
|
|||||||
/** The id of the guild */
|
/** The id of the guild */
|
||||||
guildId: string;
|
guildId: string;
|
||||||
/** Set of guild members */
|
/** Set of guild members */
|
||||||
members: GuildMember[];
|
members: GuildMemberWithUser[];
|
||||||
/** The chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count) */
|
/** The chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count) */
|
||||||
chunkIndex: number;
|
chunkIndex: number;
|
||||||
/** The total number of expected chunks for this response */
|
/** The total number of expected chunks for this response */
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export interface Message {
|
|||||||
* Users specifically mentioned in the message
|
* Users specifically mentioned in the message
|
||||||
* Note: The user objects in the mentions array will only have the partial member field present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events from text-based guild channels.
|
* Note: The user objects in the mentions array will only have the partial member field present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events from text-based guild channels.
|
||||||
*/
|
*/
|
||||||
mentions: User[];
|
mentions: (User & { member?: Partial<GuildMember> })[];
|
||||||
/** Roles specifically mentioned in this message */
|
/** Roles specifically mentioned in this message */
|
||||||
mentionRoles: string[];
|
mentionRoles: string[];
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Emoji } from "../emojis/emoji.ts";
|
import { Emoji } from "../emojis/emoji.ts";
|
||||||
import { GuildMember } from "../guilds/guild_member.ts";
|
import { GuildMemberWithUser } from "../guilds/guild_member.ts";
|
||||||
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
||||||
|
|
||||||
export interface MessageReactionAdd {
|
export interface MessageReactionAdd {
|
||||||
@@ -12,7 +12,7 @@ export interface MessageReactionAdd {
|
|||||||
/** The id of the guild */
|
/** The id of the guild */
|
||||||
guildId?: string;
|
guildId?: string;
|
||||||
/** The member who reacted if this happened in a guild */
|
/** The member who reacted if this happened in a guild */
|
||||||
member?: GuildMember;
|
member?: GuildMemberWithUser;
|
||||||
/** The emoji used to react */
|
/** The emoji used to react */
|
||||||
emoji: Partial<Emoji>;
|
emoji: Partial<Emoji>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GuildMember } from "../guilds/guild_member.ts";
|
import { GuildMemberWithUser } from "../guilds/guild_member.ts";
|
||||||
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
import { SnakeCasedPropertiesDeep } from "../util.ts";
|
||||||
|
|
||||||
export interface VoiceState {
|
export interface VoiceState {
|
||||||
@@ -9,7 +9,7 @@ export interface VoiceState {
|
|||||||
/** The user id this voice state is for */
|
/** The user id this voice state is for */
|
||||||
userId: string;
|
userId: string;
|
||||||
/** The guild member this voice state is for */
|
/** The guild member this voice state is for */
|
||||||
member?: GuildMember;
|
member?: GuildMemberWithUser;
|
||||||
/** The session id for this voice state */
|
/** The session id for this voice state */
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
/** Whether this user is deafened by the server */
|
/** Whether this user is deafened by the server */
|
||||||
|
|||||||
Reference in New Issue
Block a user