mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Merge branch 'main' of https://github.com/discordeno/discordeno into main
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Contributing
|
||||
|
||||
- Read the [style guide](#style-guide).
|
||||
- Ask for help on the [official Discord server](https:)
|
||||
- Ask for help on the [official Discord server](https://discord.gg/5vBgXk3UcZ)
|
||||
- If you are going to work on an issue, mention so in the issue comments before
|
||||
you start working on the issue.
|
||||
- If you are going to work on a new feature, create an issue and discuss with
|
||||
@@ -38,10 +38,9 @@
|
||||
|
||||
## Types Guide
|
||||
|
||||
- Must use snake case (according to Discord API).
|
||||
- Must use camel case (same property name as in the docs just in camel case).
|
||||
- Each field or property must be accompanied with a reasonable JSDoc comment
|
||||
right above its type definition.
|
||||
- The name of the type must be prefixed with `Discord`.
|
||||
- Must be placed inside of the types module (in `src/types` directory).
|
||||
|
||||
Example:
|
||||
@@ -61,6 +60,4 @@ export interface User {
|
||||
flags?: number;
|
||||
premiumType?: number;
|
||||
}
|
||||
|
||||
export type DiscordUser = SnakeCasedPropertiesDeep<DiscordUserInternal>;
|
||||
```
|
||||
|
||||
@@ -18,8 +18,10 @@ jobs:
|
||||
if: ${{ github.actor == 'Skillz4Killz' || github.actor == 'itohatweb' }}
|
||||
run: deno test --unstable --coverage=coverage -A tests/mod.ts
|
||||
- name: Create coverage report
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: deno --unstable coverage ./coverage --lcov > coverage.lcov
|
||||
- name: Collect and upload the coverage report
|
||||
if: github.ref == 'refs/heads/main'
|
||||
uses: codecov/codecov-action@v1.0.10
|
||||
with:
|
||||
file: ./coverage.lcov
|
||||
|
||||
@@ -38,7 +38,7 @@ import { startBot } from "https://deno.land/x/discordeno/mod.ts";
|
||||
|
||||
startBot({
|
||||
token: "BOT TOKEN",
|
||||
intents: ["GUILDS", "GUILD_MESSAGES"],
|
||||
intents: ["Guilds", "GuildMessages"],
|
||||
eventHandlers: {
|
||||
ready() {
|
||||
console.log("Successfully connected to gateway");
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts";
|
||||
import { rest } from "./rest/rest.ts";
|
||||
import { EventHandlers } from "./types/discordeno/eventHandlers.ts";
|
||||
import type { EventHandlers } from "./types/discordeno/eventHandlers.ts";
|
||||
import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts";
|
||||
import { snowflakeToBigint } from "./util/bigint.ts";
|
||||
import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
// deno-lint-ignore-file require-await no-explicit-any prefer-const
|
||||
import { DiscordenoChannel } from "./structures/channel.ts";
|
||||
import { DiscordenoGuild } from "./structures/guild.ts";
|
||||
import { DiscordenoMember } from "./structures/member.ts";
|
||||
import { DiscordenoMessage } from "./structures/message.ts";
|
||||
import { Emoji } from "./types/emojis/emoji.ts";
|
||||
import { PresenceUpdate } from "./types/misc/presence_update.ts";
|
||||
import type { DiscordenoChannel } from "./structures/channel.ts";
|
||||
import type { DiscordenoGuild } from "./structures/guild.ts";
|
||||
import type { DiscordenoMember } from "./structures/member.ts";
|
||||
import type { DiscordenoMessage } from "./structures/message.ts";
|
||||
import type { PresenceUpdate } from "./types/activity/presence_update.ts";
|
||||
import type { Emoji } from "./types/emojis/emoji.ts";
|
||||
import { Collection } from "./util/collection.ts";
|
||||
|
||||
export const cache = {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleChannelCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
@@ -15,7 +15,7 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
if (!cachedChannel) return;
|
||||
|
||||
if (
|
||||
cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId
|
||||
cachedChannel.type === DiscordChannelTypes.GuildVoice && payload.guildId
|
||||
) {
|
||||
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
|
||||
|
||||
@@ -34,15 +34,27 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
[
|
||||
DiscordChannelTypes.GuildText,
|
||||
DiscordChannelTypes.DM,
|
||||
DiscordChannelTypes.GroupDm,
|
||||
DiscordChannelTypes.GuildNews,
|
||||
].includes(payload.type)
|
||||
) {
|
||||
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
);
|
||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
);
|
||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
}
|
||||
});
|
||||
|
||||
eventHandlers.channelDelete?.(cachedChannel);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
||||
@@ -11,11 +11,10 @@ export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||
|
||||
if (!cachedChannel) return;
|
||||
|
||||
eventHandlers.channelUpdate?.(discordenoChannel, cachedChannel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
|
||||
export async function handleThreadCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||
|
||||
eventHandlers.threadCreate?.(discordenoChannel);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
|
||||
const cachedChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
);
|
||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
}
|
||||
});
|
||||
|
||||
eventHandlers.threadDelete?.(cachedChannel);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordenoChannel } from "../../structures/channel.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { ThreadListSync } from "../../types/channels/threads/thread_list_sync.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleThreadListSync(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as ThreadListSync;
|
||||
|
||||
const discordenoChannels = await Promise.all(
|
||||
payload.threads.map(async (thread) => {
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||
thread,
|
||||
snowflakeToBigint(payload.guildId),
|
||||
);
|
||||
|
||||
await cacheHandlers.set(
|
||||
"channels",
|
||||
discordenoChannel.id,
|
||||
discordenoChannel,
|
||||
);
|
||||
|
||||
return discordenoChannel;
|
||||
}),
|
||||
);
|
||||
|
||||
const threads = new Collection<bigint, DiscordenoChannel>(
|
||||
discordenoChannels.map((t) => [t.id, t]),
|
||||
);
|
||||
|
||||
eventHandlers.threadListSync?.(
|
||||
threads,
|
||||
payload.members,
|
||||
snowflakeToBigint(payload.guildId),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { ThreadMembersUpdate } from "../../types/channels/threads/thread_members_update.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as ThreadMembersUpdate;
|
||||
const thread = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
);
|
||||
if (!thread) return;
|
||||
|
||||
thread.memberCount = payload.memberCount;
|
||||
await cacheHandlers.set("channels", thread.id, thread);
|
||||
|
||||
eventHandlers.threadMembersUpdate?.(payload);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { ThreadMember } from "../../types/channels/threads/thread_member.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as ThreadMember;
|
||||
const thread = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
);
|
||||
if (!thread) return;
|
||||
|
||||
thread.member = payload;
|
||||
|
||||
await cacheHandlers.set("channels", thread.id, thread);
|
||||
|
||||
eventHandlers.threadMemberUpdate?.(payload);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleThreadUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
const oldChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
);
|
||||
if (!oldChannel) return;
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||
|
||||
eventHandlers.threadUpdate?.(discordenoChannel, oldChannel);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
} from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||
|
||||
export function handleApplicationCommandCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
} from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||
|
||||
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.applicationCommandDelete?.(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
ApplicationCommandCreateUpdateDelete,
|
||||
} from "../../types/interactions/application_command_create_update_delete.ts";
|
||||
} from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||
|
||||
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.applicationCommandUpdate?.(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildIntegrationsUpdate(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integration/integration_create_update.ts";
|
||||
} from "../../types/integrations/integration_create_update.ts";
|
||||
|
||||
export function handleIntegrationCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { IntegrationDelete } from "../../types/integration/integration_delete.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { IntegrationDelete } from "../../types/integrations/integration_delete.ts";
|
||||
|
||||
export function handleIntegrationDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationDelete?.(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integration/integration_create_update.ts";
|
||||
} from "../../types/integrations/integration_create_update.ts";
|
||||
|
||||
export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationUpdate?.(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { Interaction } from "../../types/interactions/interaction.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Interaction } from "../../types/interactions/interaction.ts";
|
||||
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||
|
||||
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteCreate?.(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { InviteDelete } from "../../types/invites/invite_delete.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { InviteDelete } from "../../types/invites/invite_delete.ts";
|
||||
|
||||
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteDelete?.(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
|
||||
import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||
import { Message } from "../../types/messages/message.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { MessageDelete } from "../../types/messages/message_delete.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { MessageDelete } from "../../types/messages/message_delete.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageDelete(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { botId, eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
MessageReactionAdd,
|
||||
} from "../../types/messages/message_reaction_add.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as MessageReactionAdd;
|
||||
@@ -56,7 +55,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
}
|
||||
|
||||
eventHandlers.reactionAdd?.(
|
||||
snakeKeysToCamelCase<MessageReactionAdd>(payload),
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
MessageReactionRemove,
|
||||
} from "../../types/messages/message_reaction_remove.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import {
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
MessageReactionRemoveAll,
|
||||
} from "../../types/messages/message_reaction_remove_all.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Message } from "../../types/messages/message.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { PresenceUpdate } from "../../types/misc/presence_update.ts";
|
||||
import type { PresenceUpdate } from "../../types/activity/presence_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
+14
-39
@@ -1,10 +1,7 @@
|
||||
import { eventHandlers, setApplicationId, setBotId } from "../../bot.ts";
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Ready } from "../../types/gateway/ready.ts";
|
||||
import { GuildMemberWithUser } from "../../types/mod.ts";
|
||||
import { cache } from "../../cache.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { Ready } from "../../types/gateway/ready.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
@@ -35,18 +32,18 @@ export function handleReady(
|
||||
);
|
||||
|
||||
// Start ready check in 2 seconds
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`1. Running setTimeout in READY file.`,
|
||||
);
|
||||
await checkReady(payload, shardId, now);
|
||||
checkReady(payload, shardId, now);
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
|
||||
/** This function checks if the shard is fully loaded */
|
||||
async function checkReady(payload: Ready, shardId: number, now: number) {
|
||||
function checkReady(payload: Ready, shardId: number, now: number) {
|
||||
const shard = ws.shards.get(shardId);
|
||||
if (!shard) return;
|
||||
|
||||
@@ -55,24 +52,24 @@ async function checkReady(payload: Ready, shardId: number, now: number) {
|
||||
if (Date.now() - now > 10000) {
|
||||
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
|
||||
// Force execute the loaded function to prevent infinite loop
|
||||
await loaded(shardId);
|
||||
loaded(shardId);
|
||||
} else {
|
||||
// Not all guilds were loaded but 10 seconds haven't passed so check again
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`2. Running setTimeout in READY file.`,
|
||||
);
|
||||
await checkReady(payload, shardId, now);
|
||||
checkReady(payload, shardId, now);
|
||||
}, 2000);
|
||||
}
|
||||
} else {
|
||||
// All guilds were loaded
|
||||
await loaded(shardId);
|
||||
loaded(shardId);
|
||||
}
|
||||
}
|
||||
|
||||
async function loaded(shardId: number) {
|
||||
function loaded(shardId: number) {
|
||||
const shard = ws.shards.get(shardId);
|
||||
if (!shard) return;
|
||||
|
||||
@@ -82,38 +79,16 @@ async function loaded(shardId: number) {
|
||||
if (shardId === ws.lastShardId - 1) {
|
||||
// Still some shards are loading so wait another 2 seconds for them
|
||||
if (ws.shards.some((shard) => !shard.ready)) {
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`3. Running setTimeout in CHANNEL_DELTE file.`,
|
||||
`3. Running setTimeout in READY file.`,
|
||||
);
|
||||
await loaded(shardId);
|
||||
loaded(shardId);
|
||||
}, 2000);
|
||||
} else {
|
||||
cache.isReady = true;
|
||||
eventHandlers.ready?.();
|
||||
|
||||
// All the members that came in on guild creates should now be processed 1 by 1
|
||||
for (const [guildId, members] of initialMemberLoadQueue.entries()) {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
"Running for of loop in READY file for loading members.",
|
||||
);
|
||||
await Promise.allSettled(
|
||||
members.map(async (member) => {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
member as GuildMemberWithUser,
|
||||
guildId,
|
||||
);
|
||||
|
||||
return cacheHandlers.set(
|
||||
"members",
|
||||
discordenoMember.id,
|
||||
discordenoMember,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { TypingStart } from "../../types/misc/typing_start.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { TypingStart } from "../../types/misc/typing_start.ts";
|
||||
|
||||
export function handleTypingStart(data: DiscordGatewayPayload) {
|
||||
eventHandlers.typingStart?.(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { User } from "../../types/users/user.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { User } from "../../types/users/user.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleUserUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -2,6 +2,12 @@ import { handleChannelCreate } from "./channels/CHANNEL_CREATE.ts";
|
||||
import { handleChannelDelete } from "./channels/CHANNEL_DELETE.ts";
|
||||
import { handleChannelPinsUpdate } from "./channels/CHANNEL_PINS_UPDATE.ts";
|
||||
import { handleChannelUpdate } from "./channels/CHANNEL_UPDATE.ts";
|
||||
import { handleThreadCreate } from "./channels/THREAD_CREATE.ts";
|
||||
import { handleThreadDelete } from "./channels/THREAD_DELETE.ts";
|
||||
import { handleThreadListSync } from "./channels/THREAD_LIST_SYNC.ts";
|
||||
import { handleThreadMembersUpdate } from "./channels/THREAD_MEMBERS_UPDATE.ts";
|
||||
import { handleThreadMemberUpdate } from "./channels/THREAD_MEMBER_UPDATE.ts";
|
||||
import { handleThreadUpdate } from "./channels/THREAD_UPDATE.ts";
|
||||
import { handleApplicationCommandCreate } from "./commands/APPLICATION_COMMAND_CREATE.ts";
|
||||
import { handleApplicationCommandDelete } from "./commands/APPLICATION_COMMAND_DELETE.ts";
|
||||
import { handleApplicationCommandUpdate } from "./commands/APPLICATION_COMMAND_UPDATE.ts";
|
||||
@@ -77,6 +83,12 @@ export {
|
||||
handleMessageUpdate,
|
||||
handlePresenceUpdate,
|
||||
handleReady,
|
||||
handleThreadCreate,
|
||||
handleThreadDelete,
|
||||
handleThreadListSync,
|
||||
handleThreadMembersUpdate,
|
||||
handleThreadMemberUpdate,
|
||||
handleThreadUpdate,
|
||||
handleTypingStart,
|
||||
handleUserUpdate,
|
||||
handleVoiceServerUpdate,
|
||||
@@ -92,6 +104,12 @@ export let handlers = {
|
||||
CHANNEL_DELETE: handleChannelDelete,
|
||||
CHANNEL_PINS_UPDATE: handleChannelPinsUpdate,
|
||||
CHANNEL_UPDATE: handleChannelUpdate,
|
||||
THREAD_CREATE: handleThreadCreate,
|
||||
THREAD_UPDATE: handleThreadUpdate,
|
||||
THREAD_DELETE: handleThreadDelete,
|
||||
THREAD_LIST_SYNC: handleThreadListSync,
|
||||
THREAD_MEMBER_UPDATE: handleThreadMemberUpdate,
|
||||
THREAD_MEMBERS_UPDATE: handleThreadMembersUpdate,
|
||||
// commands
|
||||
APPLICATION_COMMAND_CREATE: handleApplicationCommandCreate,
|
||||
APPLICATION_COMMAND_DELETE: handleApplicationCommandDelete,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildRoleCreate } from "../../types/mod.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildRoleCreate } from "../../types/mod.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { GuildRoleUpdate } from "../../types/mod.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildRoleUpdate } from "../../types/mod.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { VoiceState } from "../../types/voice/voice_state.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { VoiceState } from "../../types/voice/voice_state.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DiscordOverwrite } from "../../types/channels/overwrite.ts";
|
||||
import type { DiscordOverwrite } from "../../types/channels/overwrite.ts";
|
||||
import { DiscordBitwisePermissionFlags } from "../../types/permissions/bitwise_permission_flags.ts";
|
||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
|
||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||
export function channelOverwriteHasPermission(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import type { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { bigintToSnowflake } from "../../util/bigint.ts";
|
||||
import { calculatePermissions } from "../../util/permissions.ts";
|
||||
import { createChannel } from "./create_channel.ts";
|
||||
@@ -15,7 +15,7 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
|
||||
//Check for DM channel
|
||||
if (
|
||||
channelToClone.type === DiscordChannelTypes.DM ||
|
||||
channelToClone.type === DiscordChannelTypes.GROUP_DM
|
||||
channelToClone.type === DiscordChannelTypes.GroupDm
|
||||
) {
|
||||
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import {
|
||||
import type {
|
||||
CreateGuildChannel,
|
||||
DiscordCreateGuildChannel,
|
||||
} from "../../types/guilds/create_guild_channel.ts";
|
||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
calculateBits,
|
||||
requireBotGuildPermissions,
|
||||
requireOverwritePermissions,
|
||||
} from "../../util/permissions.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function createChannel(
|
||||
@@ -22,18 +20,12 @@ export async function createChannel(
|
||||
options?: CreateGuildChannel,
|
||||
reason?: string,
|
||||
) {
|
||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||
|
||||
options?.permissionOverwrites?.forEach((overwrite) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach loop in create_channel file.`,
|
||||
if (options?.permissionOverwrites) {
|
||||
await requireOverwritePermissions(
|
||||
guildId,
|
||||
options.permissionOverwrites,
|
||||
);
|
||||
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||
});
|
||||
|
||||
await requireBotGuildPermissions(guildId, [...requiredPerms]);
|
||||
}
|
||||
|
||||
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
||||
@@ -42,13 +34,13 @@ export async function createChannel(
|
||||
"post",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
{
|
||||
...camelKeysToSnakeCase<DiscordCreateGuildChannel>(options ?? {}),
|
||||
...snakelize<DiscordCreateGuildChannel>(options ?? {}),
|
||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
...perm,
|
||||
allow: calculateBits(perm.allow),
|
||||
deny: calculateBits(perm.deny),
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
||||
type: options?.type || DiscordChannelTypes.GuildText,
|
||||
reason,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { ChannelTypes } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function deleteChannel(
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
reason?: string,
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]);
|
||||
) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
if (channel?.guildId) {
|
||||
const guild = await cacheHandlers.get("guilds", channel.guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
if (guild?.rulesChannelId === channelId) {
|
||||
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
||||
}
|
||||
// TODO(threads): check if this requires guild perms or channel is enough
|
||||
await requireBotGuildPermissions(
|
||||
guild,
|
||||
[
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
? ["MANAGE_THREADS"]
|
||||
: ["MANAGE_CHANNELS"],
|
||||
);
|
||||
if (guild.rulesChannelId === channelId) {
|
||||
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
||||
}
|
||||
|
||||
if (guild?.publicUpdatesChannelId === channelId) {
|
||||
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
||||
if (guild.publicUpdatesChannelId === channelId) {
|
||||
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -1,22 +1,68 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyChannel } from "../../types/channels/modify_channel.ts";
|
||||
import { Channel } from "../../types/mod.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
|
||||
import type { ModifyThread } from "../../types/channels/threads/modify_thread.ts";
|
||||
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
calculateBits,
|
||||
requireBotChannelPermissions,
|
||||
requireOverwritePermissions,
|
||||
} from "../../util/permissions.ts";
|
||||
import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||
|
||||
//TODO: implement DM group channel edit
|
||||
//TODO(threads): check thread perms
|
||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||
export async function editChannel(
|
||||
channelId: bigint,
|
||||
options: ModifyChannel,
|
||||
options: ModifyChannel | ModifyThread,
|
||||
reason?: string,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
if (options.name || options.topic) {
|
||||
if (channel) {
|
||||
if (
|
||||
[
|
||||
DiscordChannelTypes.GuildNewsThread,
|
||||
DiscordChannelTypes.GuildPivateThread,
|
||||
DiscordChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
) {
|
||||
const permissions = new Set<PermissionStrings>();
|
||||
|
||||
if (hasOwnProperty(options, "archive") && options.archive === false) {
|
||||
permissions.add("SEND_MESSAGES");
|
||||
}
|
||||
|
||||
// TODO(threads): change this to a better check
|
||||
// hacky way of checking if more is being modified
|
||||
if (Object.keys(options).length > 1) {
|
||||
permissions.add("MANAGE_THREADS");
|
||||
}
|
||||
|
||||
await requireBotChannelPermissions(channel.parentId ?? 0n, [
|
||||
...permissions,
|
||||
]);
|
||||
}
|
||||
|
||||
if (
|
||||
hasOwnProperty<ModifyChannel>(
|
||||
options,
|
||||
"permissionOverwrites",
|
||||
) && Array.isArray(options.permissionOverwrites)
|
||||
) {
|
||||
await requireOverwritePermissions(
|
||||
channel.guildId,
|
||||
options.permissionOverwrites,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.name || (options as ModifyChannel).topic) {
|
||||
const request = editChannelNameTopicQueue.get(channelId);
|
||||
if (!request) {
|
||||
// If this hasnt been done before simply add 1 for it
|
||||
@@ -42,21 +88,18 @@ export async function editChannel(
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...options,
|
||||
...snakelize<Record<string, unknown>>(options),
|
||||
// deno-lint-ignore camelcase
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
// deno-lint-ignore camelcase
|
||||
parent_id: options.parentId,
|
||||
// deno-lint-ignore camelcase
|
||||
user_limit: options.userLimit,
|
||||
// deno-lint-ignore camelcase
|
||||
permission_overwrites: options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
}),
|
||||
permission_overwrites:
|
||||
hasOwnProperty<ModifyChannel>(options, "permissionOverwrites")
|
||||
? options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
};
|
||||
|
||||
return await rest.runMethod<Channel>(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Overwrite } from "../../types/channels/overwrite.ts";
|
||||
import type { Overwrite } from "../../types/channels/overwrite.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
calculateBits,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { FollowedChannel } from "../../types/channels/followed_channel.ts";
|
||||
import type { FollowedChannel } from "../../types/channels/followed_channel.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Webhook } from "../../types/webhooks/webhook.ts";
|
||||
import type { Webhook } from "../../types/webhooks/webhook.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Message } from "../../types/messages/message.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Get pinned messages in this channel. */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -17,8 +17,11 @@ export async function startTyping(channelId: bigint) {
|
||||
if (
|
||||
![
|
||||
DiscordChannelTypes.DM,
|
||||
DiscordChannelTypes.GUILD_NEWS,
|
||||
DiscordChannelTypes.GUILD_TEXT,
|
||||
DiscordChannelTypes.GuildNews,
|
||||
DiscordChannelTypes.GuildText,
|
||||
DiscordChannelTypes.GuildNewsThread,
|
||||
DiscordChannelTypes.GuildPivateThread,
|
||||
DiscordChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
) {
|
||||
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyGuildChannelPositions } from "../../types/guilds/modify_guild_channel_position.ts";
|
||||
import type { ModifyGuildChannelPositions } from "../../types/guilds/modify_guild_channel_position.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ChannelTypes, Errors } from "../../../types/mod.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
//TODO(threads): this does not work rn
|
||||
/** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event.Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event.
|
||||
* @param userId the user to add to the thread defaults to bot
|
||||
*/
|
||||
export async function addToThread(channelId: bigint, userId?: bigint) {
|
||||
// TODO(threads): perm check
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (channel) {
|
||||
if (
|
||||
![
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
) {
|
||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
"put",
|
||||
userId
|
||||
? endpoints.THREAD_USER(channelId, userId)
|
||||
: endpoints.THREAD_ME(channelId),
|
||||
);
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
userId
|
||||
? endpoints.THREAD_USER(channelId, userId)
|
||||
: endpoints.THREAD_ME(channelId),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
|
||||
/** Returns all active threads in the channel, including public and private threads. Threads are ordered by their id, in descending order. Requires the READ_MESSAGE_HISTORY permission. */
|
||||
export async function getActiveThreads(channelId: bigint) {
|
||||
// TODO(threads): perm check
|
||||
// TODO(threads): test if it works
|
||||
return await rest.runMethod(
|
||||
"get",
|
||||
endpoints.THREAD_ACTIVE(channelId),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_public_archived_threads.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
import { snakelize } from "../../../util/utils.ts";
|
||||
|
||||
export async function getArchivedThreads(
|
||||
channelId: bigint,
|
||||
options?: ListPublicArchivedThreads & {
|
||||
type?: "public" | "private" | "privateJoinedThreads";
|
||||
},
|
||||
) {
|
||||
// TODO(threads): perm check
|
||||
// TODO(threads): check if this works
|
||||
|
||||
return await rest.runMethod(
|
||||
"get",
|
||||
options?.type === "privateJoinedThreads"
|
||||
? endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId)
|
||||
: options?.type === "private"
|
||||
? endpoints.THREAD_ARCHIVED_PRIVATE(channelId)
|
||||
: endpoints.THREAD_ARCHIVED_PUBLIC(channelId),
|
||||
snakelize(options ?? {}),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
|
||||
// TODO(threads): it seems like the documented return type is wrong
|
||||
/** Returns array of thread members objects that are members of the thread. */
|
||||
export async function getThreadMembers(channelId: bigint) {
|
||||
// TODO(threads): perm check
|
||||
// TODO(threads): intents check
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (channel) {
|
||||
if (
|
||||
![
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
) {
|
||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(channelId));
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
|
||||
/** Removes another user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. */
|
||||
export async function removeFromThread(channelId: bigint, userId?: bigint) {
|
||||
// TODO(threads): perm check
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (channel) {
|
||||
if (
|
||||
![
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
) {
|
||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod(
|
||||
"delete",
|
||||
userId
|
||||
? endpoints.THREAD_USER(channelId, userId)
|
||||
: endpoints.THREAD_ME(channelId),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
|
||||
import { StartThread } from "../../../types/channels/threads/start_thread.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
import { snakelize } from "../../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Creates a new public thread from an existing message. Returns a channel on success, and a 400 BAD REQUEST on invalid parameters. Fires a Thread Create Gateway event.
|
||||
* @param messageId when provided the thread will be public
|
||||
*/
|
||||
export async function startThread(
|
||||
channelId: bigint,
|
||||
options: StartThread & { messageId?: bigint },
|
||||
) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (channel) {
|
||||
// TODO(threads): perm check
|
||||
if (
|
||||
![ChannelTypes.GuildText, ChannelTypes.GuildNews].includes(channel.type)
|
||||
) {
|
||||
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
|
||||
}
|
||||
|
||||
if (!options.messageId && channel.type === ChannelTypes.GuildNews) {
|
||||
throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS);
|
||||
}
|
||||
}
|
||||
|
||||
return rest.runMethod(
|
||||
"post",
|
||||
options?.messageId
|
||||
? endpoints.THREAD_START_PUBLIC(channelId, options.messageId)
|
||||
: endpoints.THREAD_START_PRIVATE(channelId),
|
||||
snakelize(options),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts";
|
||||
import type {
|
||||
UpdateSelfVoiceState,
|
||||
} from "../../types/guilds/update_self_voice_state.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Updates the a user's voice state, defaults to the current user
|
||||
* Caveats:
|
||||
* - `channel_id` must currently point to a stage channel.
|
||||
* - User must already have joined `channel_id`.
|
||||
* - You must have the `MUTE_MEMBERS` permission. But can always suppress yourself.
|
||||
* - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not.
|
||||
* - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak.
|
||||
* - You are able to set `request_to_speak_timestamp` to any present or future time.
|
||||
* - When suppressed, the user will have their `request_to_speak_timestamp` removed.
|
||||
*/
|
||||
export async function updateBotVoiceState(
|
||||
guildId: bigint,
|
||||
options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState,
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.UPDATE_VOICE_STATE(
|
||||
guildId,
|
||||
hasOwnProperty(options, "userId") ? options.userId : undefined,
|
||||
),
|
||||
snakelize(options),
|
||||
);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { applicationId } from "../../bot.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Edits command permissions for a specific command for your application in a guild. */
|
||||
export async function editSlashCommandPermissions(
|
||||
guildId: bigint,
|
||||
commandId: bigint,
|
||||
options: ApplicationCommandPermissions[],
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
{ permissions: camelKeysToSnakeCase(options) },
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import {
|
||||
import type {
|
||||
AddGuildDiscoverySubcategory,
|
||||
} from "../../types/discovery/add_guild_discovery_subcategory.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts";
|
||||
import { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts";
|
||||
import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts";
|
||||
import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
|
||||
export async function editDiscovery(
|
||||
@@ -15,6 +15,6 @@ export async function editDiscovery(
|
||||
return await rest.runMethod<DiscoveryMetadata>(
|
||||
"patch",
|
||||
endpoints.DISCOVERY_MODIFY(guildId),
|
||||
camelKeysToSnakeCase(data),
|
||||
snakelize(data),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscoveryCategory } from "../../types/discovery/discovery_category.ts";
|
||||
import type { DiscoveryCategory } from "../../types/discovery/discovery_category.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts";
|
||||
import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
export async function validDiscoveryTerm(term: string) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts";
|
||||
import { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts";
|
||||
import { Emoji } from "../../types/mod.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import type { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
@@ -2,8 +2,8 @@ import { botId } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { CreateGuild } from "../../types/guilds/create_guild.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { CreateGuild } from "../../types/guilds/create_guild.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { getMember } from "../members/get_member.ts";
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import { ModifyGuild } from "../../types/guilds/modify_guild.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { ModifyGuild } from "../../types/guilds/modify_guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { urlToBase64 } from "../../util/utils.ts";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts";
|
||||
import { WelcomeScreen } from "../../types/mod.ts";
|
||||
import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts";
|
||||
import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
export async function editWelcomeScreen(
|
||||
guildId: bigint,
|
||||
@@ -11,6 +11,6 @@ export async function editWelcomeScreen(
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"patch",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
camelKeysToSnakeCase(options),
|
||||
snakelize(options),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import type { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { AuditLog } from "../../types/audit_log/audit_log.ts";
|
||||
import { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts";
|
||||
import type { AuditLog } from "../../types/audit_log/audit_log.ts";
|
||||
import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(
|
||||
@@ -15,7 +15,7 @@ export async function getAuditLogs(
|
||||
return await rest.runMethod<AuditLog>(
|
||||
"get",
|
||||
endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
camelKeysToSnakeCase({
|
||||
snakelize({
|
||||
...options,
|
||||
limit: options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import type { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns an array of voice regions that can be used when creating servers. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Ban } from "../../types/guilds/ban.ts";
|
||||
import type { Ban } from "../../types/guilds/ban.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Ban } from "../../types/guilds/ban.ts";
|
||||
import type { Ban } from "../../types/guilds/ban.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildPreview } from "../../types/guilds/guild_preview.ts";
|
||||
import type { GuildPreview } from "../../types/guilds/guild_preview.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
export async function getPruneCount(
|
||||
@@ -20,7 +20,7 @@ export async function getPruneCount(
|
||||
const result = await rest.runMethod(
|
||||
"get",
|
||||
endpoints.GUILD_PRUNE(guildId),
|
||||
camelKeysToSnakeCase(options ?? {}),
|
||||
snakelize(options ?? {}),
|
||||
);
|
||||
|
||||
return result.pruned as number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import type { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { WelcomeScreen } from "../../types/mod.ts";
|
||||
import type { WelcomeScreen } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
export async function getWelcomeScreen(guildId: bigint) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import type { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the widget for the guild. */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the widget image URL for the guild. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import type { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user