mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Prettified Code!
This commit is contained in:
+2
-4
@@ -20,16 +20,14 @@ export async function startBot(config: BotConfig) {
|
|||||||
ws.identifyPayload.token = `Bot ${config.token}`;
|
ws.identifyPayload.token = `Bot ${config.token}`;
|
||||||
rest.token = `Bot ${config.token}`;
|
rest.token = `Bot ${config.token}`;
|
||||||
ws.identifyPayload.intents = config.intents.reduce(
|
ws.identifyPayload.intents = config.intents.reduce(
|
||||||
(bits, next) =>
|
(bits, next) => (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
||||||
(bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initial API connection to get info about bots connection
|
// Initial API connection to get info about bots connection
|
||||||
ws.botGatewayData = await getGatewayBot();
|
ws.botGatewayData = await getGatewayBot();
|
||||||
ws.maxShards = ws.maxShards || ws.botGatewayData.shards;
|
ws.maxShards = ws.maxShards || ws.botGatewayData.shards;
|
||||||
ws.lastShardId =
|
ws.lastShardId = ws.lastShardId === 1 ? ws.botGatewayData.shards - 1 : ws.lastShardId;
|
||||||
ws.lastShardId === 1 ? ws.botGatewayData.shards - 1 : ws.lastShardId;
|
|
||||||
|
|
||||||
// Explicitly append gateway version and encoding
|
// Explicitly append gateway version and encoding
|
||||||
ws.botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`;
|
ws.botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`;
|
||||||
|
|||||||
+21
-98
@@ -23,19 +23,12 @@ export const cache = {
|
|||||||
presences: new Collection<bigint, PresenceUpdate>(),
|
presences: new Collection<bigint, PresenceUpdate>(),
|
||||||
fetchAllMembersProcessingRequests: new Collection<
|
fetchAllMembersProcessingRequests: new Collection<
|
||||||
string,
|
string,
|
||||||
(
|
(value: Collection<bigint, DiscordenoMember> | PromiseLike<Collection<bigint, DiscordenoMember>>) => void
|
||||||
value:
|
|
||||||
| Collection<bigint, DiscordenoMember>
|
|
||||||
| PromiseLike<Collection<bigint, DiscordenoMember>>
|
|
||||||
) => void
|
|
||||||
>(),
|
>(),
|
||||||
executedSlashCommands: new Set<string>(),
|
executedSlashCommands: new Set<string>(),
|
||||||
get emojis() {
|
get emojis() {
|
||||||
return new Collection<bigint, Emoji>(
|
return new Collection<bigint, Emoji>(
|
||||||
this.guilds.reduce(
|
this.guilds.reduce((a, b) => [...a, ...b.emojis.map((e) => [e.id, e])], [] as any[])
|
||||||
(a, b) => [...a, ...b.emojis.map((e) => [e.id, e])],
|
|
||||||
[] as any[]
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -70,83 +63,31 @@ export let cacheHandlers = {
|
|||||||
filter,
|
filter,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TableName =
|
export type TableName = "guilds" | "unavailableGuilds" | "channels" | "messages" | "members" | "presences";
|
||||||
| "guilds"
|
|
||||||
| "unavailableGuilds"
|
|
||||||
| "channels"
|
|
||||||
| "messages"
|
|
||||||
| "members"
|
|
||||||
| "presences";
|
|
||||||
|
|
||||||
function set(
|
function set(table: "guilds", key: bigint, value: DiscordenoGuild): Promise<Collection<bigint, DiscordenoGuild>>;
|
||||||
table: "guilds",
|
function set(table: "channels", key: bigint, value: DiscordenoChannel): Promise<Collection<bigint, DiscordenoChannel>>;
|
||||||
key: bigint,
|
function set(table: "messages", key: bigint, value: DiscordenoMessage): Promise<Collection<bigint, DiscordenoMessage>>;
|
||||||
value: DiscordenoGuild
|
function set(table: "members", key: bigint, value: DiscordenoMember): Promise<Collection<bigint, DiscordenoMember>>;
|
||||||
): Promise<Collection<bigint, DiscordenoGuild>>;
|
function set(table: "presences", key: bigint, value: PresenceUpdate): Promise<Collection<bigint, PresenceUpdate>>;
|
||||||
function set(
|
function set(table: "unavailableGuilds", key: bigint, value: number): Promise<Collection<bigint, number>>;
|
||||||
table: "channels",
|
|
||||||
key: bigint,
|
|
||||||
value: DiscordenoChannel
|
|
||||||
): Promise<Collection<bigint, DiscordenoChannel>>;
|
|
||||||
function set(
|
|
||||||
table: "messages",
|
|
||||||
key: bigint,
|
|
||||||
value: DiscordenoMessage
|
|
||||||
): Promise<Collection<bigint, DiscordenoMessage>>;
|
|
||||||
function set(
|
|
||||||
table: "members",
|
|
||||||
key: bigint,
|
|
||||||
value: DiscordenoMember
|
|
||||||
): Promise<Collection<bigint, DiscordenoMember>>;
|
|
||||||
function set(
|
|
||||||
table: "presences",
|
|
||||||
key: bigint,
|
|
||||||
value: PresenceUpdate
|
|
||||||
): Promise<Collection<bigint, PresenceUpdate>>;
|
|
||||||
function set(
|
|
||||||
table: "unavailableGuilds",
|
|
||||||
key: bigint,
|
|
||||||
value: number
|
|
||||||
): Promise<Collection<bigint, number>>;
|
|
||||||
async function set(table: TableName, key: bigint, value: any) {
|
async function set(table: TableName, key: bigint, value: any) {
|
||||||
return cache[table].set(key, value);
|
return cache[table].set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get(
|
function get(table: "guilds", key: bigint): Promise<DiscordenoGuild | undefined>;
|
||||||
table: "guilds",
|
function get(table: "channels", key: bigint): Promise<DiscordenoChannel | undefined>;
|
||||||
key: bigint
|
function get(table: "messages", key: bigint): Promise<DiscordenoMessage | undefined>;
|
||||||
): Promise<DiscordenoGuild | undefined>;
|
function get(table: "members", key: bigint): Promise<DiscordenoMember | undefined>;
|
||||||
function get(
|
function get(table: "presences", key: bigint): Promise<PresenceUpdate | undefined>;
|
||||||
table: "channels",
|
function get(table: "unavailableGuilds", key: bigint): Promise<number | undefined>;
|
||||||
key: bigint
|
|
||||||
): Promise<DiscordenoChannel | undefined>;
|
|
||||||
function get(
|
|
||||||
table: "messages",
|
|
||||||
key: bigint
|
|
||||||
): Promise<DiscordenoMessage | undefined>;
|
|
||||||
function get(
|
|
||||||
table: "members",
|
|
||||||
key: bigint
|
|
||||||
): Promise<DiscordenoMember | undefined>;
|
|
||||||
function get(
|
|
||||||
table: "presences",
|
|
||||||
key: bigint
|
|
||||||
): Promise<PresenceUpdate | undefined>;
|
|
||||||
function get(
|
|
||||||
table: "unavailableGuilds",
|
|
||||||
key: bigint
|
|
||||||
): Promise<number | undefined>;
|
|
||||||
async function get(table: TableName, key: bigint) {
|
async function get(table: TableName, key: bigint) {
|
||||||
return cache[table].get(key);
|
return cache[table].get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "guilds",
|
table: "guilds",
|
||||||
callback: (
|
callback: (value: DiscordenoGuild, key: bigint, map: Map<bigint, DiscordenoGuild>) => unknown
|
||||||
value: DiscordenoGuild,
|
|
||||||
key: bigint,
|
|
||||||
map: Map<bigint, DiscordenoGuild>
|
|
||||||
) => unknown
|
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "unavailableGuilds",
|
table: "unavailableGuilds",
|
||||||
@@ -154,32 +95,17 @@ function forEach(
|
|||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "channels",
|
table: "channels",
|
||||||
callback: (
|
callback: (value: DiscordenoChannel, key: bigint, map: Map<bigint, DiscordenoChannel>) => unknown
|
||||||
value: DiscordenoChannel,
|
|
||||||
key: bigint,
|
|
||||||
map: Map<bigint, DiscordenoChannel>
|
|
||||||
) => unknown
|
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "messages",
|
table: "messages",
|
||||||
callback: (
|
callback: (value: DiscordenoMessage, key: bigint, map: Map<bigint, DiscordenoMessage>) => unknown
|
||||||
value: DiscordenoMessage,
|
|
||||||
key: bigint,
|
|
||||||
map: Map<bigint, DiscordenoMessage>
|
|
||||||
) => unknown
|
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(
|
||||||
table: "members",
|
table: "members",
|
||||||
callback: (
|
callback: (value: DiscordenoMember, key: bigint, map: Map<bigint, DiscordenoMember>) => unknown
|
||||||
value: DiscordenoMember,
|
|
||||||
key: bigint,
|
|
||||||
map: Map<bigint, DiscordenoMember>
|
|
||||||
) => unknown
|
|
||||||
): void;
|
): void;
|
||||||
function forEach(
|
function forEach(table: TableName, callback: (value: any, key: bigint, map: Map<bigint, any>) => unknown) {
|
||||||
table: TableName,
|
|
||||||
callback: (value: any, key: bigint, map: Map<bigint, any>) => unknown
|
|
||||||
) {
|
|
||||||
return cache[table].forEach(callback);
|
return cache[table].forEach(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +129,6 @@ function filter(
|
|||||||
table: "members",
|
table: "members",
|
||||||
callback: (value: DiscordenoMember, key: bigint) => boolean
|
callback: (value: DiscordenoMember, key: bigint) => boolean
|
||||||
): Promise<Collection<bigint, DiscordenoMember>>;
|
): Promise<Collection<bigint, DiscordenoMember>>;
|
||||||
async function filter(
|
async function filter(table: TableName, callback: (value: any, key: bigint) => boolean) {
|
||||||
table: TableName,
|
|
||||||
callback: (value: any, key: bigint) => boolean
|
|
||||||
) {
|
|
||||||
return cache[table].filter(callback);
|
return cache[table].filter(callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,10 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Channel;
|
const payload = data.d as Channel;
|
||||||
|
|
||||||
const cachedChannel = await cacheHandlers.get(
|
const cachedChannel = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!cachedChannel) return;
|
if (!cachedChannel) return;
|
||||||
|
|
||||||
if (
|
if (cachedChannel.type === DiscordChannelTypes.GuildVoice && payload.guildId) {
|
||||||
cachedChannel.type === DiscordChannelTypes.GuildVoice &&
|
|
||||||
payload.guildId
|
|
||||||
) {
|
|
||||||
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
|
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
|
||||||
|
|
||||||
if (guild) {
|
if (guild) {
|
||||||
@@ -47,10 +41,7 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
|||||||
) {
|
) {
|
||||||
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `Running forEach messages loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`Running forEach messages loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||||
cacheHandlers.delete("messages", message.id);
|
cacheHandlers.delete("messages", message.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,10 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
|
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as ChannelPinsUpdate;
|
const payload = data.d as ChannelPinsUpdate;
|
||||||
|
|
||||||
const channel = await cacheHandlers.get(
|
const channel = await cacheHandlers.get("channels", snowflakeToBigint(payload.channelId));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
const guild = payload.guildId
|
const guild = payload.guildId ? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId)) : undefined;
|
||||||
? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId))
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp);
|
eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Channel;
|
const payload = data.d as Channel;
|
||||||
const cachedChannel = await cacheHandlers.get(
|
const cachedChannel = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!cachedChannel) return;
|
if (!cachedChannel) return;
|
||||||
|
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||||
|
|||||||
@@ -7,18 +7,12 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Channel;
|
const payload = data.d as Channel;
|
||||||
|
|
||||||
const cachedChannel = await cacheHandlers.get(
|
const cachedChannel = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!cachedChannel) return;
|
if (!cachedChannel) return;
|
||||||
|
|
||||||
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `Running forEach messages loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`Running forEach messages loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||||
cacheHandlers.delete("messages", message.id);
|
cacheHandlers.delete("messages", message.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,28 +12,15 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
const discordenoChannels = await Promise.all(
|
const discordenoChannels = await Promise.all(
|
||||||
payload.threads.map(async (thread) => {
|
payload.threads.map(async (thread) => {
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
const discordenoChannel = await structures.createDiscordenoChannel(thread, snowflakeToBigint(payload.guildId));
|
||||||
thread,
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
|
|
||||||
await cacheHandlers.set(
|
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||||
"channels",
|
|
||||||
discordenoChannel.id,
|
|
||||||
discordenoChannel
|
|
||||||
);
|
|
||||||
|
|
||||||
return discordenoChannel;
|
return discordenoChannel;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const threads = new Collection<bigint, DiscordenoChannel>(
|
const threads = new Collection<bigint, DiscordenoChannel>(discordenoChannels.map((t) => [t.id, t]));
|
||||||
discordenoChannels.map((t) => [t.id, t])
|
|
||||||
);
|
|
||||||
|
|
||||||
eventHandlers.threadListSync?.(
|
eventHandlers.threadListSync?.(threads, payload.members, snowflakeToBigint(payload.guildId));
|
||||||
threads,
|
|
||||||
payload.members,
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
|
export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as ThreadMembersUpdate;
|
const payload = data.d as ThreadMembersUpdate;
|
||||||
const thread = await cacheHandlers.get(
|
const thread = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!thread) return;
|
if (!thread) return;
|
||||||
|
|
||||||
thread.memberCount = payload.memberCount;
|
thread.memberCount = payload.memberCount;
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as ThreadMember;
|
const payload = data.d as ThreadMember;
|
||||||
const thread = await cacheHandlers.get(
|
const thread = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!thread) return;
|
if (!thread) return;
|
||||||
|
|
||||||
thread.member = payload;
|
thread.member = payload;
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleThreadUpdate(data: DiscordGatewayPayload) {
|
export async function handleThreadUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Channel;
|
const payload = data.d as Channel;
|
||||||
const oldChannel = await cacheHandlers.get(
|
const oldChannel = await cacheHandlers.get("channels", snowflakeToBigint(payload.id));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!oldChannel) return;
|
if (!oldChannel) return;
|
||||||
|
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
const discordenoChannel = await structures.createDiscordenoChannel(payload);
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandCreate(data: DiscordGatewayPayload) {
|
export function handleApplicationCommandCreate(data: DiscordGatewayPayload) {
|
||||||
eventHandlers.applicationCommandCreate?.(
|
eventHandlers.applicationCommandCreate?.(data.d as ApplicationCommandCreateUpdateDelete);
|
||||||
data.d as ApplicationCommandCreateUpdateDelete
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
export function handleApplicationCommandDelete(data: DiscordGatewayPayload) {
|
||||||
eventHandlers.applicationCommandDelete?.(
|
eventHandlers.applicationCommandDelete?.(data.d as ApplicationCommandCreateUpdateDelete);
|
||||||
data.d as ApplicationCommandCreateUpdateDelete
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
|
||||||
|
|
||||||
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) {
|
||||||
eventHandlers.applicationCommandUpdate?.(
|
eventHandlers.applicationCommandUpdate?.(data.d as ApplicationCommandCreateUpdateDelete);
|
||||||
data.d as ApplicationCommandCreateUpdateDelete
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,11 @@ import { Collection } from "../../util/collection.ts";
|
|||||||
|
|
||||||
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildEmojisUpdate;
|
const payload = data.d as GuildEmojisUpdate;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const cachedEmojis = guild.emojis;
|
const cachedEmojis = guild.emojis;
|
||||||
guild.emojis = new Collection(
|
guild.emojis = new Collection(payload.emojis.map((emoji) => [snowflakeToBigint(emoji.id!), emoji]));
|
||||||
payload.emojis.map((emoji) => [snowflakeToBigint(emoji.id!), emoji])
|
|
||||||
);
|
|
||||||
|
|
||||||
await cacheHandlers.set("guilds", guild.id, guild);
|
await cacheHandlers.set("guilds", guild.id, guild);
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,9 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildBanAddRemove;
|
const payload = data.d as GuildBanAddRemove;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const member = await cacheHandlers.get(
|
const member = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
||||||
"members",
|
|
||||||
snowflakeToBigint(payload.user.id)
|
|
||||||
);
|
|
||||||
eventHandlers.guildBanAdd?.(guild, payload.user, member);
|
eventHandlers.guildBanAdd?.(guild, payload.user, member);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,9 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildBanAddRemove;
|
const payload = data.d as GuildBanAddRemove;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const member = await cacheHandlers.get(
|
const member = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
||||||
"members",
|
|
||||||
snowflakeToBigint(payload.user.id)
|
|
||||||
);
|
|
||||||
eventHandlers.guildBanRemove?.(guild, payload.user, member);
|
eventHandlers.guildBanRemove?.(guild, payload.user, member);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import type { Guild } from "../../types/guilds/guild.ts";
|
|||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
import { ws } from "../../ws/ws.ts";
|
import { ws } from "../../ws/ws.ts";
|
||||||
|
|
||||||
export async function handleGuildCreate(
|
export async function handleGuildCreate(data: DiscordGatewayPayload, shardId: number) {
|
||||||
data: DiscordGatewayPayload,
|
|
||||||
shardId: number
|
|
||||||
) {
|
|
||||||
const payload = data.d as Guild;
|
const payload = data.d as Guild;
|
||||||
// When shards resume they emit GUILD_CREATE again.
|
// When shards resume they emit GUILD_CREATE again.
|
||||||
if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return;
|
if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return;
|
||||||
|
|||||||
@@ -5,16 +5,10 @@ import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
|
|||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
import { ws } from "../../ws/ws.ts";
|
import { ws } from "../../ws/ws.ts";
|
||||||
|
|
||||||
export async function handleGuildDelete(
|
export async function handleGuildDelete(data: DiscordGatewayPayload, shardId: number) {
|
||||||
data: DiscordGatewayPayload,
|
|
||||||
shardId: number
|
|
||||||
) {
|
|
||||||
const payload = data.d as UnavailableGuild;
|
const payload = data.d as UnavailableGuild;
|
||||||
|
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.id));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
await cacheHandlers.delete("guilds", guild.id);
|
await cacheHandlers.delete("guilds", guild.id);
|
||||||
@@ -30,30 +24,21 @@ export async function handleGuildDelete(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `1. Running forEach messages loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`1. Running forEach messages loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
if (message.guildId === guild.id) {
|
if (message.guildId === guild.id) {
|
||||||
cacheHandlers.delete("messages", message.id);
|
cacheHandlers.delete("messages", message.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cacheHandlers.forEach("channels", (channel) => {
|
cacheHandlers.forEach("channels", (channel) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `2. Running forEach channels loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`2. Running forEach channels loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
if (channel.guildId === guild.id) {
|
if (channel.guildId === guild.id) {
|
||||||
cacheHandlers.delete("channels", channel.id);
|
cacheHandlers.delete("channels", channel.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cacheHandlers.forEach("members", (member) => {
|
cacheHandlers.forEach("members", (member) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `3. Running forEach members loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`3. Running forEach members loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
if (!member.guilds.has(guild.id)) return;
|
if (!member.guilds.has(guild.id)) return;
|
||||||
|
|
||||||
member.guilds.delete(guild.id);
|
member.guilds.delete(guild.id);
|
||||||
|
|||||||
@@ -4,15 +4,10 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts";
|
import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
|
|
||||||
export async function handleGuildIntegrationsUpdate(
|
export async function handleGuildIntegrationsUpdate(data: DiscordGatewayPayload) {
|
||||||
data: DiscordGatewayPayload
|
|
||||||
) {
|
|
||||||
const payload = data.d as GuildIntegrationsUpdate;
|
const payload = data.d as GuildIntegrationsUpdate;
|
||||||
|
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
eventHandlers.guildIntegrationsUpdate?.(guild);
|
eventHandlers.guildIntegrationsUpdate?.(guild);
|
||||||
|
|||||||
@@ -6,25 +6,12 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { Guild } from "../../types/guilds/guild.ts";
|
import type { Guild } from "../../types/guilds/guild.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
|
|
||||||
export async function handleGuildUpdate(
|
export async function handleGuildUpdate(data: DiscordGatewayPayload, shardId: number) {
|
||||||
data: DiscordGatewayPayload,
|
|
||||||
shardId: number
|
|
||||||
) {
|
|
||||||
const payload = data.d as Guild;
|
const payload = data.d as Guild;
|
||||||
const oldGuild = await cacheHandlers.get(
|
const oldGuild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.id));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!oldGuild) return;
|
if (!oldGuild) return;
|
||||||
|
|
||||||
const keysToSkip = [
|
const keysToSkip = ["id", "roles", "guildHashes", "guildId", "maxMembers", "emojis"];
|
||||||
"id",
|
|
||||||
"roles",
|
|
||||||
"guildHashes",
|
|
||||||
"guildId",
|
|
||||||
"maxMembers",
|
|
||||||
"emojis",
|
|
||||||
];
|
|
||||||
|
|
||||||
const newGuild = await structures.createDiscordenoGuild(payload, shardId);
|
const newGuild = await structures.createDiscordenoGuild(payload, shardId);
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Interaction;
|
const payload = data.d as Interaction;
|
||||||
const discordenoMember = payload.guildId
|
const discordenoMember = payload.guildId
|
||||||
? await structures.createDiscordenoMember(
|
? await structures.createDiscordenoMember(payload.member as GuildMemberWithUser, snowflakeToBigint(payload.guildId))
|
||||||
payload.member as GuildMemberWithUser,
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
)
|
|
||||||
: undefined;
|
: undefined;
|
||||||
if (discordenoMember) {
|
if (discordenoMember) {
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
const members = await Promise.all(
|
const members = await Promise.all(
|
||||||
payload.members.map(async (member) => {
|
payload.members.map(async (member) => {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(member, guildId);
|
||||||
member,
|
|
||||||
guildId
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
|
|
||||||
return discordenoMember;
|
return discordenoMember;
|
||||||
@@ -34,9 +31,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
|||||||
return resolve(new Collection(members.map((m) => [m.id, m])));
|
return resolve(new Collection(members.map((m) => [m.id, m])));
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve(
|
return resolve(await cacheHandlers.filter("members", (m) => m.guilds.has(guildId)));
|
||||||
await cacheHandlers.filter("members", (m) => m.guilds.has(guildId))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,11 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberAdd;
|
const payload = data.d as GuildMemberAdd;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
guild.memberCount++;
|
guild.memberCount++;
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(payload, guild.id);
|
||||||
payload,
|
|
||||||
guild.id
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
|
|
||||||
eventHandlers.guildMemberAdd?.(guild, discordenoMember);
|
eventHandlers.guildMemberAdd?.(guild, discordenoMember);
|
||||||
|
|||||||
@@ -6,17 +6,11 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberRemove;
|
const payload = data.d as GuildMemberRemove;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
guild.memberCount--;
|
guild.memberCount--;
|
||||||
const member = await cacheHandlers.get(
|
const member = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
||||||
"members",
|
|
||||||
snowflakeToBigint(payload.user.id)
|
|
||||||
);
|
|
||||||
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
||||||
|
|
||||||
member?.guilds.delete(guild.id);
|
member?.guilds.delete(guild.id);
|
||||||
|
|||||||
@@ -7,16 +7,10 @@ import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildMemberUpdate;
|
const payload = data.d as GuildMemberUpdate;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const cachedMember = await cacheHandlers.get(
|
const cachedMember = await cacheHandlers.get("members", snowflakeToBigint(payload.user.id));
|
||||||
"members",
|
|
||||||
snowflakeToBigint(payload.user.id)
|
|
||||||
);
|
|
||||||
const guildMember = cachedMember?.guilds.get(guild.id);
|
const guildMember = cachedMember?.guilds.get(guild.id);
|
||||||
|
|
||||||
const newMemberData = {
|
const newMemberData = {
|
||||||
@@ -27,20 +21,12 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
|||||||
mute: guildMember?.mute || false,
|
mute: guildMember?.mute || false,
|
||||||
roles: payload.roles,
|
roles: payload.roles,
|
||||||
};
|
};
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(newMemberData, guild.id);
|
||||||
newMemberData,
|
|
||||||
guild.id
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
|
|
||||||
if (guildMember) {
|
if (guildMember) {
|
||||||
if (guildMember.nick !== payload.nick) {
|
if (guildMember.nick !== payload.nick) {
|
||||||
eventHandlers.nicknameUpdate?.(
|
eventHandlers.nicknameUpdate?.(guild, discordenoMember, payload.nick!, guildMember.nick ?? undefined);
|
||||||
guild,
|
|
||||||
discordenoMember,
|
|
||||||
payload.nick!,
|
|
||||||
guildMember.nick ?? undefined
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.pending === false && guildMember.pending === true) {
|
if (payload.pending === false && guildMember.pending === true) {
|
||||||
@@ -50,26 +36,16 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
|||||||
const roleIds = guildMember.roles || [];
|
const roleIds = guildMember.roles || [];
|
||||||
|
|
||||||
roleIds.forEach((id) => {
|
roleIds.forEach((id) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `1. Running forEach loop in GUILD_MEMBER_UPDATE file.`);
|
||||||
"loop",
|
|
||||||
`1. Running forEach loop in GUILD_MEMBER_UPDATE file.`
|
|
||||||
);
|
|
||||||
if (!payload.roles.includes(bigintToSnowflake(id))) {
|
if (!payload.roles.includes(bigintToSnowflake(id))) {
|
||||||
eventHandlers.roleLost?.(guild, discordenoMember, id);
|
eventHandlers.roleLost?.(guild, discordenoMember, id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
payload.roles.forEach((id) => {
|
payload.roles.forEach((id) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `2. Running forEach loop in GUILD_MEMBER_UPDATE file.`);
|
||||||
"loop",
|
|
||||||
`2. Running forEach loop in GUILD_MEMBER_UPDATE file.`
|
|
||||||
);
|
|
||||||
if (!roleIds.includes(snowflakeToBigint(id))) {
|
if (!roleIds.includes(snowflakeToBigint(id))) {
|
||||||
eventHandlers.roleGained?.(
|
eventHandlers.roleGained?.(guild, discordenoMember, snowflakeToBigint(id));
|
||||||
guild,
|
|
||||||
discordenoMember,
|
|
||||||
snowflakeToBigint(id)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,10 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Message;
|
const payload = data.d as Message;
|
||||||
const channel = await cacheHandlers.get(
|
const channel = await cacheHandlers.get("channels", snowflakeToBigint(payload.channelId));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
if (channel) channel.lastMessageId = snowflakeToBigint(payload.id);
|
if (channel) channel.lastMessageId = snowflakeToBigint(payload.id);
|
||||||
|
|
||||||
const guild = payload.guildId
|
const guild = payload.guildId ? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId)) : undefined;
|
||||||
? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId))
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (payload.member && guild) {
|
if (payload.member && guild) {
|
||||||
// If in a guild cache the author as a member
|
// If in a guild cache the author as a member
|
||||||
@@ -37,11 +32,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
|||||||
guild.id
|
guild.id
|
||||||
);
|
);
|
||||||
|
|
||||||
return cacheHandlers.set(
|
return cacheHandlers.set("members", snowflakeToBigint(mention.id), discordenoMember);
|
||||||
"members",
|
|
||||||
snowflakeToBigint(mention.id),
|
|
||||||
discordenoMember
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageDelete(data: DiscordGatewayPayload) {
|
export async function handleMessageDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as MessageDelete;
|
const payload = data.d as MessageDelete;
|
||||||
const channel = await cacheHandlers.get(
|
const channel = await cacheHandlers.get("channels", snowflakeToBigint(payload.channelId));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
eventHandlers.messageDelete?.(
|
eventHandlers.messageDelete?.(
|
||||||
|
|||||||
@@ -6,18 +6,12 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
|
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as MessageDeleteBulk;
|
const payload = data.d as MessageDeleteBulk;
|
||||||
const channel = await cacheHandlers.get(
|
const channel = await cacheHandlers.get("channels", snowflakeToBigint(payload.channelId));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
payload.ids.map(async (id) => {
|
payload.ids.map(async (id) => {
|
||||||
eventHandlers.messageDelete?.(
|
eventHandlers.messageDelete?.({ id, channel }, await cacheHandlers.get("messages", snowflakeToBigint(id)));
|
||||||
{ id, channel },
|
|
||||||
await cacheHandlers.get("messages", snowflakeToBigint(id))
|
|
||||||
);
|
|
||||||
await cacheHandlers.delete("messages", snowflakeToBigint(id));
|
await cacheHandlers.delete("messages", snowflakeToBigint(id));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,16 +7,11 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as MessageReactionAdd;
|
const payload = data.d as MessageReactionAdd;
|
||||||
const message = await cacheHandlers.get(
|
const message = await cacheHandlers.get("messages", snowflakeToBigint(payload.messageId));
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
const reactionExisted = message.reactions?.find(
|
const reactionExisted = message.reactions?.find(
|
||||||
(reaction) =>
|
(reaction) => reaction.emoji.id === payload.emoji.id && reaction.emoji.name === payload.emoji.name
|
||||||
reaction.emoji.id === payload.emoji.id &&
|
|
||||||
reaction.emoji.name === payload.emoji.name
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (reactionExisted) reactionExisted.count++;
|
if (reactionExisted) reactionExisted.count++;
|
||||||
@@ -26,28 +21,16 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
|||||||
me: snowflakeToBigint(payload.userId) === botId,
|
me: snowflakeToBigint(payload.userId) === botId,
|
||||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||||
};
|
};
|
||||||
message.reactions = message.reactions
|
message.reactions = message.reactions ? [...message.reactions, newReaction] : [newReaction];
|
||||||
? [...message.reactions, newReaction]
|
|
||||||
: [newReaction];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await cacheHandlers.set(
|
await cacheHandlers.set("messages", snowflakeToBigint(payload.messageId), message);
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId),
|
|
||||||
message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.member && payload.guildId) {
|
if (payload.member && payload.guildId) {
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (guild) {
|
if (guild) {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(payload.member, guild.id);
|
||||||
payload.member,
|
|
||||||
guild.id
|
|
||||||
);
|
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,13 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageReactionRemove(data: DiscordGatewayPayload) {
|
export async function handleMessageReactionRemove(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as MessageReactionRemove;
|
const payload = data.d as MessageReactionRemove;
|
||||||
const message = await cacheHandlers.get(
|
const message = await cacheHandlers.get("messages", snowflakeToBigint(payload.messageId));
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
const reaction = message.reactions?.find(
|
const reaction = message.reactions?.find(
|
||||||
(reaction) =>
|
(reaction) =>
|
||||||
// MUST USE == because discord sends null and we use undefined
|
// MUST USE == because discord sends null and we use undefined
|
||||||
reaction.emoji.id == payload.emoji.id &&
|
reaction.emoji.id == payload.emoji.id && reaction.emoji.name === payload.emoji.name
|
||||||
reaction.emoji.name === payload.emoji.name
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (reaction) {
|
if (reaction) {
|
||||||
|
|||||||
@@ -4,23 +4,14 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { MessageReactionRemoveAll } from "../../types/messages/message_reaction_remove_all.ts";
|
import type { MessageReactionRemoveAll } from "../../types/messages/message_reaction_remove_all.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemoveAll(
|
export async function handleMessageReactionRemoveAll(data: DiscordGatewayPayload) {
|
||||||
data: DiscordGatewayPayload
|
|
||||||
) {
|
|
||||||
const payload = data.d as MessageReactionRemoveAll;
|
const payload = data.d as MessageReactionRemoveAll;
|
||||||
const message = await cacheHandlers.get(
|
const message = await cacheHandlers.get("messages", snowflakeToBigint(payload.messageId));
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message?.reactions) {
|
if (message?.reactions) {
|
||||||
message.reactions = undefined;
|
message.reactions = undefined;
|
||||||
|
|
||||||
await cacheHandlers.set(
|
await cacheHandlers.set("messages", snowflakeToBigint(payload.messageId), message);
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId),
|
|
||||||
message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventHandlers.reactionRemoveAll?.(payload, message);
|
eventHandlers.reactionRemoveAll?.(payload, message);
|
||||||
|
|||||||
@@ -4,24 +4,16 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
|||||||
import type { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
import type { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
|
||||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||||
|
|
||||||
export async function handleMessageReactionRemoveEmoji(
|
export async function handleMessageReactionRemoveEmoji(data: DiscordGatewayPayload) {
|
||||||
data: DiscordGatewayPayload
|
|
||||||
) {
|
|
||||||
const payload = data.d as MessageReactionRemoveEmoji;
|
const payload = data.d as MessageReactionRemoveEmoji;
|
||||||
const message = await cacheHandlers.get(
|
const message = await cacheHandlers.get("messages", snowflakeToBigint(payload.messageId));
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.messageId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message?.reactions) {
|
if (message?.reactions) {
|
||||||
message.reactions = message.reactions.filter(
|
message.reactions = message.reactions.filter(
|
||||||
(reaction) =>
|
(reaction) =>
|
||||||
!(
|
!(
|
||||||
// MUST USE == because discord sends null and we use undefined
|
// MUST USE == because discord sends null and we use undefined
|
||||||
(
|
(reaction.emoji.id == payload.emoji.id && reaction.emoji.name === payload.emoji.name)
|
||||||
reaction.emoji.id == payload.emoji.id &&
|
|
||||||
reaction.emoji.name === payload.emoji.name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,10 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as Message;
|
const payload = data.d as Message;
|
||||||
const channel = await cacheHandlers.get(
|
const channel = await cacheHandlers.get("channels", snowflakeToBigint(payload.channelId));
|
||||||
"channels",
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
const oldMessage = await cacheHandlers.get(
|
const oldMessage = await cacheHandlers.get("messages", snowflakeToBigint(payload.id));
|
||||||
"messages",
|
|
||||||
snowflakeToBigint(payload.id)
|
|
||||||
);
|
|
||||||
if (!oldMessage) return;
|
if (!oldMessage) return;
|
||||||
|
|
||||||
// Messages with embeds can trigger update but they wont have edited_timestamp
|
// Messages with embeds can trigger update but they wont have edited_timestamp
|
||||||
|
|||||||
@@ -7,15 +7,8 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as PresenceUpdate;
|
const payload = data.d as PresenceUpdate;
|
||||||
|
|
||||||
const oldPresence = await cacheHandlers.get(
|
const oldPresence = await cacheHandlers.get("presences", snowflakeToBigint(payload.user.id));
|
||||||
"presences",
|
await cacheHandlers.set("presences", snowflakeToBigint(payload.user.id), payload);
|
||||||
snowflakeToBigint(payload.user.id)
|
|
||||||
);
|
|
||||||
await cacheHandlers.set(
|
|
||||||
"presences",
|
|
||||||
snowflakeToBigint(payload.user.id),
|
|
||||||
payload
|
|
||||||
);
|
|
||||||
|
|
||||||
eventHandlers.presenceUpdate?.(payload, oldPresence);
|
eventHandlers.presenceUpdate?.(payload, oldPresence);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ export function handleReady(data: DiscordGatewayPayload, shardId: number) {
|
|||||||
// Set ready to false just to go sure
|
// Set ready to false just to go sure
|
||||||
shard.ready = false;
|
shard.ready = false;
|
||||||
// All guilds are unavailable at first
|
// All guilds are unavailable at first
|
||||||
shard.unavailableGuildIds = new Set(
|
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => snowflakeToBigint(g.id)));
|
||||||
payload.guilds.map((g) => snowflakeToBigint(g.id))
|
|
||||||
);
|
|
||||||
// Set the last available to now
|
// Set the last available to now
|
||||||
shard.lastAvailable = Date.now();
|
shard.lastAvailable = Date.now();
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleUserUpdate(data: DiscordGatewayPayload) {
|
export async function handleUserUpdate(data: DiscordGatewayPayload) {
|
||||||
const userData = data.d as User;
|
const userData = data.d as User;
|
||||||
|
|
||||||
const member = await cacheHandlers.get(
|
const member = await cacheHandlers.get("members", snowflakeToBigint(userData.id));
|
||||||
"members",
|
|
||||||
snowflakeToBigint(userData.id)
|
|
||||||
);
|
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
|
|
||||||
Object.entries(userData).forEach(([key, value]) => {
|
Object.entries(userData).forEach(([key, value]) => {
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildRoleCreate;
|
const payload = data.d as GuildRoleCreate;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const role = await structures.createDiscordenoRole({
|
const role = await structures.createDiscordenoRole({
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildRoleDelete;
|
const payload = data.d as GuildRoleDelete;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const roleId = snowflakeToBigint(payload.roleId);
|
const roleId = snowflakeToBigint(payload.roleId);
|
||||||
@@ -21,18 +18,12 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
|
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
|
||||||
cacheHandlers.forEach("members", (member) => {
|
cacheHandlers.forEach("members", (member) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `1. Running forEach members loop in GUILD_ROLE_DELETE file.`);
|
||||||
"loop",
|
|
||||||
`1. Running forEach members loop in GUILD_ROLE_DELETE file.`
|
|
||||||
);
|
|
||||||
// Not in the relevant guild so just skip.
|
// Not in the relevant guild so just skip.
|
||||||
if (!member.guilds.has(guild.id)) return;
|
if (!member.guilds.has(guild.id)) return;
|
||||||
|
|
||||||
member.guilds.forEach((g) => {
|
member.guilds.forEach((g) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.("loop", `2. Running forEach loop in CHANNEL_DELTE file.`);
|
||||||
"loop",
|
|
||||||
`2. Running forEach loop in CHANNEL_DELTE file.`
|
|
||||||
);
|
|
||||||
// Member does not have this role
|
// Member does not have this role
|
||||||
if (!g.roles.includes(roleId)) return;
|
if (!g.roles.includes(roleId)) return;
|
||||||
// Remove this role from the members cache
|
// Remove this role from the members cache
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as GuildRoleUpdate;
|
const payload = data.d as GuildRoleUpdate;
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const cachedRole = guild.roles.get(snowflakeToBigint(payload.role.id));
|
const cachedRole = guild.roles.get(snowflakeToBigint(payload.role.id));
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as VoiceServerUpdate;
|
const payload = data.d as VoiceServerUpdate;
|
||||||
|
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
eventHandlers.voiceServerUpdate?.(payload, guild);
|
eventHandlers.voiceServerUpdate?.(payload, guild);
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
|||||||
const payload = data.d as VoiceState;
|
const payload = data.d as VoiceState;
|
||||||
if (!payload.guildId) return;
|
if (!payload.guildId) return;
|
||||||
|
|
||||||
const guild = await cacheHandlers.get(
|
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||||
"guilds",
|
|
||||||
snowflakeToBigint(payload.guildId)
|
|
||||||
);
|
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const member = payload.member
|
const member = payload.member
|
||||||
@@ -30,25 +27,15 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
await cacheHandlers.set("guilds", guild.id, guild);
|
await cacheHandlers.set("guilds", guild.id, guild);
|
||||||
|
|
||||||
if (
|
if (cachedState?.channelId !== (payload.channelId ? snowflakeToBigint(payload.channelId) : null)) {
|
||||||
cachedState?.channelId !==
|
|
||||||
(payload.channelId ? snowflakeToBigint(payload.channelId) : null)
|
|
||||||
) {
|
|
||||||
// Either joined or moved channels
|
// Either joined or moved channels
|
||||||
if (payload.channelId) {
|
if (payload.channelId) {
|
||||||
if (cachedState?.channelId) {
|
if (cachedState?.channelId) {
|
||||||
// Was in a channel before
|
// Was in a channel before
|
||||||
eventHandlers.voiceChannelSwitch?.(
|
eventHandlers.voiceChannelSwitch?.(member, snowflakeToBigint(payload.channelId), cachedState.channelId);
|
||||||
member,
|
|
||||||
snowflakeToBigint(payload.channelId),
|
|
||||||
cachedState.channelId
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Was not in a channel before so user just joined
|
// Was not in a channel before so user just joined
|
||||||
eventHandlers.voiceChannelJoin?.(
|
eventHandlers.voiceChannelJoin?.(member, snowflakeToBigint(payload.channelId));
|
||||||
member,
|
|
||||||
snowflakeToBigint(payload.channelId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} // Left the channel
|
} // Left the channel
|
||||||
else if (cachedState?.channelId) {
|
else if (cachedState?.channelId) {
|
||||||
|
|||||||
@@ -5,8 +5,5 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
|||||||
|
|
||||||
export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
|
export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
|
||||||
const options = data.d as WebhookUpdate;
|
const options = data.d as WebhookUpdate;
|
||||||
eventHandlers.webhooksUpdate?.(
|
eventHandlers.webhooksUpdate?.(snowflakeToBigint(options.channelId), snowflakeToBigint(options.guildId));
|
||||||
snowflakeToBigint(options.channelId),
|
|
||||||
snowflakeToBigint(options.guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,5 @@ import { cacheHandlers } from "../../cache.ts";
|
|||||||
|
|
||||||
/** Gets an array of all the channels ids that are the children of this category. */
|
/** Gets an array of all the channels ids that are the children of this category. */
|
||||||
export async function categoryChildren(id: bigint) {
|
export async function categoryChildren(id: bigint) {
|
||||||
return await cacheHandlers.filter(
|
return await cacheHandlers.filter("channels", (channel) => channel.parentId === id);
|
||||||
"channels",
|
|
||||||
(channel) => channel.parentId === id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ export function channelOverwriteHasPermission(
|
|||||||
})[],
|
})[],
|
||||||
permissions: PermissionStrings[]
|
permissions: PermissionStrings[]
|
||||||
) {
|
) {
|
||||||
const overwrite =
|
const overwrite = overwrites.find((perm) => perm.id === id) || overwrites.find((perm) => perm.id === guildId);
|
||||||
overwrites.find((perm) => perm.id === id) ||
|
|
||||||
overwrites.find((perm) => perm.id === guildId);
|
|
||||||
|
|
||||||
if (!overwrite) return false;
|
if (!overwrite) return false;
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
|
|||||||
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||||
|
|
||||||
//Check for DM channel
|
//Check for DM channel
|
||||||
if (
|
if (channelToClone.type === DiscordChannelTypes.DM || channelToClone.type === DiscordChannelTypes.GroupDm) {
|
||||||
channelToClone.type === DiscordChannelTypes.DM ||
|
|
||||||
channelToClone.type === DiscordChannelTypes.GroupDm
|
|
||||||
) {
|
|
||||||
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,9 +19,7 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
|
|||||||
...channelToClone,
|
...channelToClone,
|
||||||
name: channelToClone.name!,
|
name: channelToClone.name!,
|
||||||
topic: channelToClone.topic || undefined,
|
topic: channelToClone.topic || undefined,
|
||||||
permissionOverwrites: channelToClone.permissionOverwrites.map((
|
permissionOverwrites: channelToClone.permissionOverwrites.map((overwrite) => ({
|
||||||
overwrite,
|
|
||||||
) => ({
|
|
||||||
id: overwrite.id.toString(),
|
id: overwrite.id.toString(),
|
||||||
type: overwrite.type,
|
type: overwrite.type,
|
||||||
allow: calculatePermissions(overwrite.allow.toString()),
|
allow: calculatePermissions(overwrite.allow.toString()),
|
||||||
@@ -33,9 +28,5 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Create the channel (also handles permissions)
|
//Create the channel (also handles permissions)
|
||||||
return await helpers.createChannel(
|
return await helpers.createChannel(channelToClone.guildId!, createChannelOptions, reason);
|
||||||
channelToClone.guildId!,
|
|
||||||
createChannelOptions,
|
|
||||||
reason,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,13 @@ import { rest } from "../../rest/rest.ts";
|
|||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import type { Channel } from "../../types/channels/channel.ts";
|
import type { Channel } from "../../types/channels/channel.ts";
|
||||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
import type {
|
import type { CreateGuildChannel, DiscordCreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||||
CreateGuildChannel,
|
|
||||||
DiscordCreateGuildChannel,
|
|
||||||
} from "../../types/guilds/create_guild_channel.ts";
|
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import { calculateBits, requireOverwritePermissions } from "../../util/permissions.ts";
|
||||||
calculateBits,
|
|
||||||
requireOverwritePermissions,
|
|
||||||
} from "../../util/permissions.ts";
|
|
||||||
import { snakelize } from "../../util/utils.ts";
|
import { snakelize } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function createChannel(
|
export async function createChannel(guildId: bigint, options?: CreateGuildChannel, reason?: string) {
|
||||||
guildId: bigint,
|
|
||||||
options?: CreateGuildChannel,
|
|
||||||
reason?: string
|
|
||||||
) {
|
|
||||||
if (options?.permissionOverwrites) {
|
if (options?.permissionOverwrites) {
|
||||||
await requireOverwritePermissions(guildId, options.permissionOverwrites);
|
await requireOverwritePermissions(guildId, options.permissionOverwrites);
|
||||||
}
|
}
|
||||||
@@ -27,20 +17,16 @@ export async function createChannel(
|
|||||||
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
||||||
|
|
||||||
const result = await rest.runMethod<Channel>(
|
const result = await rest.runMethod<Channel>("post", endpoints.GUILD_CHANNELS(guildId), {
|
||||||
"post",
|
...snakelize<DiscordCreateGuildChannel>(options ?? {}),
|
||||||
endpoints.GUILD_CHANNELS(guildId),
|
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||||
{
|
...perm,
|
||||||
...snakelize<DiscordCreateGuildChannel>(options ?? {}),
|
allow: calculateBits(perm.allow),
|
||||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
deny: calculateBits(perm.deny),
|
||||||
...perm,
|
})),
|
||||||
allow: calculateBits(perm.allow),
|
type: options?.type || DiscordChannelTypes.GuildText,
|
||||||
deny: calculateBits(perm.deny),
|
reason,
|
||||||
})),
|
});
|
||||||
type: options?.type || DiscordChannelTypes.GuildText,
|
|
||||||
reason,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
||||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||||
|
|||||||
@@ -16,23 +16,15 @@ export async function createStageInstance(channelId: bigint, topic: string) {
|
|||||||
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel, [
|
await requireBotChannelPermissions(channel, ["MANAGE_CHANNELS", "MUTE_MEMBERS", "MOVE_MEMBERS"]);
|
||||||
"MANAGE_CHANNELS",
|
|
||||||
"MUTE_MEMBERS",
|
|
||||||
"MOVE_MEMBERS",
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateLength(topic, { max: 120, min: 1 })) {
|
if (!validateLength(topic, { max: 120, min: 1 })) {
|
||||||
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<StageInstance>(
|
return await rest.runMethod<StageInstance>("post", endpoints.STAGE_INSTANCES, {
|
||||||
"post",
|
channel_id: channelId,
|
||||||
endpoints.STAGE_INSTANCES,
|
topic,
|
||||||
{
|
});
|
||||||
channel_id: channelId,
|
|
||||||
topic,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,9 @@ export async function deleteChannel(channelId: bigint, reason?: string) {
|
|||||||
// TODO(threads): check if this requires guild perms or channel is enough
|
// TODO(threads): check if this requires guild perms or channel is enough
|
||||||
await requireBotGuildPermissions(
|
await requireBotGuildPermissions(
|
||||||
guild,
|
guild,
|
||||||
[
|
[ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
|
||||||
ChannelTypes.GuildNewsThread,
|
channel.type
|
||||||
ChannelTypes.GuildPivateThread,
|
)
|
||||||
ChannelTypes.GuildPublicThread,
|
|
||||||
].includes(channel.type)
|
|
||||||
? ["MANAGE_THREADS"]
|
? ["MANAGE_THREADS"]
|
||||||
: ["MANAGE_CHANNELS"]
|
: ["MANAGE_CHANNELS"]
|
||||||
);
|
);
|
||||||
@@ -33,9 +31,5 @@ export async function deleteChannel(channelId: bigint, reason?: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.CHANNEL_BASE(channelId), { reason });
|
||||||
"delete",
|
|
||||||
endpoints.CHANNEL_BASE(channelId),
|
|
||||||
{ reason }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,5 @@ export async function deleteChannelOverwrite(
|
|||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId));
|
||||||
"delete",
|
|
||||||
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,15 +14,8 @@ export async function deleteStageInstance(channelId: bigint) {
|
|||||||
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel, [
|
await requireBotChannelPermissions(channel, ["MUTE_MEMBERS", "MANAGE_CHANNELS", "MOVE_MEMBERS"]);
|
||||||
"MUTE_MEMBERS",
|
|
||||||
"MANAGE_CHANNELS",
|
|
||||||
"MOVE_MEMBERS",
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.STAGE_INSTANCE(channelId));
|
||||||
"delete",
|
|
||||||
endpoints.STAGE_INSTANCE(channelId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,13 @@ import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
|
|||||||
import type { ModifyThread } from "../../types/channels/threads/modify_thread.ts";
|
import type { ModifyThread } from "../../types/channels/threads/modify_thread.ts";
|
||||||
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import { calculateBits, requireBotChannelPermissions, requireOverwritePermissions } from "../../util/permissions.ts";
|
||||||
calculateBits,
|
|
||||||
requireBotChannelPermissions,
|
|
||||||
requireOverwritePermissions,
|
|
||||||
} from "../../util/permissions.ts";
|
|
||||||
import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||||
|
|
||||||
//TODO: implement DM group channel edit
|
//TODO: implement DM group channel edit
|
||||||
//TODO(threads): check thread perms
|
//TODO(threads): check thread perms
|
||||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||||
export async function editChannel(
|
export async function editChannel(channelId: bigint, options: ModifyChannel | ModifyThread, reason?: string) {
|
||||||
channelId: bigint,
|
|
||||||
options: ModifyChannel | ModifyThread,
|
|
||||||
reason?: string
|
|
||||||
) {
|
|
||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
@@ -46,19 +38,11 @@ export async function editChannel(
|
|||||||
permissions.add("MANAGE_THREADS");
|
permissions.add("MANAGE_THREADS");
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel.parentId ?? 0n, [
|
await requireBotChannelPermissions(channel.parentId ?? 0n, [...permissions]);
|
||||||
...permissions,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (hasOwnProperty<ModifyChannel>(options, "permissionOverwrites") && Array.isArray(options.permissionOverwrites)) {
|
||||||
hasOwnProperty<ModifyChannel>(options, "permissionOverwrites") &&
|
await requireOverwritePermissions(channel.guildId, options.permissionOverwrites);
|
||||||
Array.isArray(options.permissionOverwrites)
|
|
||||||
) {
|
|
||||||
await requireOverwritePermissions(
|
|
||||||
channel.guildId,
|
|
||||||
options.permissionOverwrites
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +75,7 @@ export async function editChannel(
|
|||||||
const payload = {
|
const payload = {
|
||||||
...snakelize<Record<string, unknown>>(options),
|
...snakelize<Record<string, unknown>>(options),
|
||||||
// deno-lint-ignore camelcase
|
// deno-lint-ignore camelcase
|
||||||
permission_overwrites: hasOwnProperty<ModifyChannel>(
|
permission_overwrites: hasOwnProperty<ModifyChannel>(options, "permissionOverwrites")
|
||||||
options,
|
|
||||||
"permissionOverwrites"
|
|
||||||
)
|
|
||||||
? options.permissionOverwrites?.map((overwrite) => {
|
? options.permissionOverwrites?.map((overwrite) => {
|
||||||
return {
|
return {
|
||||||
...overwrite,
|
...overwrite,
|
||||||
@@ -105,14 +86,10 @@ export async function editChannel(
|
|||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await rest.runMethod<Channel>(
|
const result = await rest.runMethod<Channel>("patch", endpoints.CHANNEL_BASE(channelId), {
|
||||||
"patch",
|
...payload,
|
||||||
endpoints.CHANNEL_BASE(channelId),
|
reason,
|
||||||
{
|
});
|
||||||
...payload,
|
|
||||||
reason,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return await structures.createDiscordenoChannel(result);
|
return await structures.createDiscordenoChannel(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import type { Overwrite } from "../../types/channels/overwrite.ts";
|
import type { Overwrite } from "../../types/channels/overwrite.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import { calculateBits, requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
calculateBits,
|
|
||||||
requireBotGuildPermissions,
|
|
||||||
} from "../../util/permissions.ts";
|
|
||||||
|
|
||||||
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||||
export async function editChannelOverwrite(
|
export async function editChannelOverwrite(
|
||||||
@@ -15,13 +12,9 @@ export async function editChannelOverwrite(
|
|||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("put", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), {
|
||||||
"put",
|
allow: calculateBits(options.allow),
|
||||||
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
deny: calculateBits(options.deny),
|
||||||
{
|
type: options.type,
|
||||||
allow: calculateBits(options.allow),
|
});
|
||||||
deny: calculateBits(options.deny),
|
|
||||||
type: options.type,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,12 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
||||||
export async function followChannel(
|
export async function followChannel(sourceChannelId: bigint, targetChannelId: bigint) {
|
||||||
sourceChannelId: bigint,
|
|
||||||
targetChannelId: bigint
|
|
||||||
) {
|
|
||||||
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
|
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const data = await rest.runMethod<FollowedChannel>(
|
const data = await rest.runMethod<FollowedChannel>("post", endpoints.CHANNEL_FOLLOW(sourceChannelId), {
|
||||||
"post",
|
webhook_channel_id: targetChannelId,
|
||||||
endpoints.CHANNEL_FOLLOW(sourceChannelId),
|
});
|
||||||
{
|
|
||||||
webhook_channel_id: targetChannelId,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return data.webhookId;
|
return data.webhookId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,14 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
||||||
*/
|
*/
|
||||||
export async function getChannel(channelId: bigint, addToCache = true) {
|
export async function getChannel(channelId: bigint, addToCache = true) {
|
||||||
const result = await rest.runMethod<Channel>(
|
const result = await rest.runMethod<Channel>("get", endpoints.CHANNEL_BASE(channelId));
|
||||||
"get",
|
|
||||||
endpoints.CHANNEL_BASE(channelId)
|
|
||||||
);
|
|
||||||
|
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||||
result,
|
result,
|
||||||
result.guildId ? snowflakeToBigint(result.guildId) : undefined
|
result.guildId ? snowflakeToBigint(result.guildId) : undefined
|
||||||
);
|
);
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
await cacheHandlers.set(
|
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||||
"channels",
|
|
||||||
discordenoChannel.id,
|
|
||||||
discordenoChannel
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return discordenoChannel;
|
return discordenoChannel;
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
export async function getChannelWebhooks(channelId: bigint) {
|
export async function getChannelWebhooks(channelId: bigint) {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const result = await rest.runMethod<Webhook[]>(
|
const result = await rest.runMethod<Webhook[]>("get", endpoints.CHANNEL_WEBHOOKS(channelId));
|
||||||
"get",
|
|
||||||
endpoints.CHANNEL_WEBHOOKS(channelId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,25 +10,15 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
||||||
*/
|
*/
|
||||||
export async function getChannels(guildId: bigint, addToCache = true) {
|
export async function getChannels(guildId: bigint, addToCache = true) {
|
||||||
const result = await rest.runMethod<Channel[]>(
|
const result = await rest.runMethod<Channel[]>("get", endpoints.GUILD_CHANNELS(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_CHANNELS(guildId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
(
|
(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
result.map(async (res) => {
|
result.map(async (res) => {
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
const discordenoChannel = await structures.createDiscordenoChannel(res, guildId);
|
||||||
res,
|
|
||||||
guildId
|
|
||||||
);
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
await cacheHandlers.set(
|
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||||
"channels",
|
|
||||||
discordenoChannel.id,
|
|
||||||
discordenoChannel
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return discordenoChannel;
|
return discordenoChannel;
|
||||||
|
|||||||
@@ -5,12 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Get pinned messages in this channel. */
|
/** Get pinned messages in this channel. */
|
||||||
export async function getPins(channelId: bigint) {
|
export async function getPins(channelId: bigint) {
|
||||||
const result = await rest.runMethod<Message[]>(
|
const result = await rest.runMethod<Message[]>("get", endpoints.CHANNEL_PINS(channelId));
|
||||||
"get",
|
|
||||||
endpoints.CHANNEL_PINS(channelId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(result.map((res) => structures.createDiscordenoMessage(res)));
|
||||||
result.map((res) => structures.createDiscordenoMessage(res))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,5 @@ export async function getStageInstance(channelId: bigint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<StageInstance>(
|
return await rest.runMethod<StageInstance>("get", endpoints.STAGE_INSTANCE(channelId));
|
||||||
"get",
|
|
||||||
endpoints.STAGE_INSTANCE(channelId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,8 @@ export async function isChannelSynced(channelId: bigint) {
|
|||||||
if (!parentChannel) return false;
|
if (!parentChannel) return false;
|
||||||
|
|
||||||
return channel.permissionOverwrites?.every((overwrite) => {
|
return channel.permissionOverwrites?.every((overwrite) => {
|
||||||
const permission = parentChannel.permissionOverwrites?.find(
|
const permission = parentChannel.permissionOverwrites?.find((ow) => ow.id === overwrite.id);
|
||||||
(ow) => ow.id === overwrite.id
|
|
||||||
);
|
|
||||||
if (!permission) return false;
|
if (!permission) return false;
|
||||||
return !(
|
return !(overwrite.allow !== permission.allow || overwrite.deny !== permission.deny);
|
||||||
overwrite.allow !== permission.allow || overwrite.deny !== permission.deny
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,16 +27,11 @@ export async function startTyping(channelId: bigint) {
|
|||||||
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasSendMessagesPerm = await botHasChannelPermissions(channelId, [
|
const hasSendMessagesPerm = await botHasChannelPermissions(channelId, ["SEND_MESSAGES"]);
|
||||||
"SEND_MESSAGES",
|
|
||||||
]);
|
|
||||||
if (!hasSendMessagesPerm) {
|
if (!hasSendMessagesPerm) {
|
||||||
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("post", endpoints.CHANNEL_TYPING(channelId));
|
||||||
"post",
|
|
||||||
endpoints.CHANNEL_TYPING(channelId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,10 @@ import type { ModifyGuildChannelPositions } from "../../types/guilds/modify_guil
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||||
export async function swapChannels(
|
export async function swapChannels(guildId: bigint, channelPositions: ModifyGuildChannelPositions[]) {
|
||||||
guildId: bigint,
|
|
||||||
channelPositions: ModifyGuildChannelPositions[]
|
|
||||||
) {
|
|
||||||
if (channelPositions.length < 2) {
|
if (channelPositions.length < 2) {
|
||||||
throw "You must provide at least two channels to be swapped.";
|
throw "You must provide at least two channels to be swapped.";
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("patch", endpoints.GUILD_CHANNELS(guildId), channelPositions);
|
||||||
"patch",
|
|
||||||
endpoints.GUILD_CHANNELS(guildId),
|
|
||||||
channelPositions
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ export async function addToThread(channelId: bigint, userId?: bigint) {
|
|||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
![
|
![ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
|
||||||
ChannelTypes.GuildNewsThread,
|
channel.type
|
||||||
ChannelTypes.GuildPivateThread,
|
)
|
||||||
ChannelTypes.GuildPublicThread,
|
|
||||||
].includes(channel.type)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||||
}
|
}
|
||||||
@@ -24,8 +22,6 @@ export async function addToThread(channelId: bigint, userId?: bigint) {
|
|||||||
|
|
||||||
return await rest.runMethod(
|
return await rest.runMethod(
|
||||||
"put",
|
"put",
|
||||||
userId
|
userId ? endpoints.THREAD_USER(channelId, userId) : endpoints.THREAD_ME(channelId)
|
||||||
? endpoints.THREAD_USER(channelId, userId)
|
|
||||||
: endpoints.THREAD_ME(channelId)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ export async function getThreadMembers(channelId: bigint) {
|
|||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
![
|
![ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
|
||||||
ChannelTypes.GuildNewsThread,
|
channel.type
|
||||||
ChannelTypes.GuildPivateThread,
|
)
|
||||||
ChannelTypes.GuildPublicThread,
|
|
||||||
].includes(channel.type)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,9 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) {
|
|||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
![
|
![ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
|
||||||
ChannelTypes.GuildNewsThread,
|
channel.type
|
||||||
ChannelTypes.GuildPivateThread,
|
)
|
||||||
ChannelTypes.GuildPublicThread,
|
|
||||||
].includes(channel.type)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
||||||
}
|
}
|
||||||
@@ -22,8 +20,6 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) {
|
|||||||
|
|
||||||
return await rest.runMethod(
|
return await rest.runMethod(
|
||||||
"delete",
|
"delete",
|
||||||
userId
|
userId ? endpoints.THREAD_USER(channelId, userId) : endpoints.THREAD_ME(channelId)
|
||||||
? endpoints.THREAD_USER(channelId, userId)
|
|
||||||
: endpoints.THREAD_ME(channelId)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,11 @@ 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.
|
* 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
|
* @param messageId when provided the thread will be public
|
||||||
*/
|
*/
|
||||||
export async function startThread(
|
export async function startThread(channelId: bigint, options: StartThread & { messageId?: bigint }) {
|
||||||
channelId: bigint,
|
|
||||||
options: StartThread & { messageId?: bigint }
|
|
||||||
) {
|
|
||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
// TODO(threads): perm check
|
// TODO(threads): perm check
|
||||||
if (
|
if (![ChannelTypes.GuildText, ChannelTypes.GuildNews].includes(channel.type)) {
|
||||||
![ChannelTypes.GuildText, ChannelTypes.GuildNews].includes(channel.type)
|
|
||||||
) {
|
|
||||||
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
|
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
|
|||||||
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
throw new Error(Errors.CHANNEL_NOT_STAGE_VOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel, [
|
await requireBotChannelPermissions(channel, ["MOVE_MEMBERS", "MUTE_MEMBERS", "MANAGE_CHANNELS"]);
|
||||||
"MOVE_MEMBERS",
|
|
||||||
"MUTE_MEMBERS",
|
|
||||||
"MANAGE_CHANNELS",
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -32,11 +28,7 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
|
|||||||
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<StageInstance>(
|
return await rest.runMethod<StageInstance>("patch", endpoints.STAGE_INSTANCE(channelId), {
|
||||||
"patch",
|
topic,
|
||||||
endpoints.STAGE_INSTANCE(channelId),
|
});
|
||||||
{
|
|
||||||
topic,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ export async function updateBotVoiceState(
|
|||||||
) {
|
) {
|
||||||
return await rest.runMethod(
|
return await rest.runMethod(
|
||||||
"patch",
|
"patch",
|
||||||
endpoints.UPDATE_VOICE_STATE(
|
endpoints.UPDATE_VOICE_STATE(guildId, hasOwnProperty(options, "userId") ? options.userId : undefined),
|
||||||
guildId,
|
|
||||||
hasOwnProperty(options, "userId") ? options.userId : undefined
|
|
||||||
),
|
|
||||||
snakelize(options)
|
snakelize(options)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
||||||
export async function addDiscoverySubcategory(
|
export async function addDiscoverySubcategory(guildId: bigint, categoryId: number) {
|
||||||
guildId: bigint,
|
|
||||||
categoryId: number
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<AddGuildDiscoverySubcategory>(
|
return await rest.runMethod<AddGuildDiscoverySubcategory>(
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
import { snakelize } 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. */
|
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
|
||||||
export async function editDiscovery(
|
export async function editDiscovery(guildId: bigint, data: ModifyGuildDiscoveryMetadata) {
|
||||||
guildId: bigint,
|
|
||||||
data: ModifyGuildDiscoveryMetadata
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<DiscoveryMetadata>(
|
return await rest.runMethod<DiscoveryMetadata>("patch", endpoints.DISCOVERY_MODIFY(guildId), snakelize(data));
|
||||||
"patch",
|
|
||||||
endpoints.DISCOVERY_MODIFY(guildId),
|
|
||||||
snakelize(data)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Returns an array of discovery category objects that can be used when editing guilds */
|
/** Returns an array of discovery category objects that can be used when editing guilds */
|
||||||
export async function getDiscoveryCategories() {
|
export async function getDiscoveryCategories() {
|
||||||
const result = await rest.runMethod<DiscoveryCategory[]>(
|
const result = await rest.runMethod<DiscoveryCategory[]>("get", endpoints.DISCOVERY_CATEGORIES);
|
||||||
"get",
|
|
||||||
endpoints.DISCOVERY_CATEGORIES
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Collection<number, DiscoveryCategory>(
|
return new Collection<number, DiscoveryCategory>(result.map((category) => [category.id, category]));
|
||||||
result.map((category) => [category.id, category])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */
|
/** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */
|
||||||
export async function removeDiscoverySubcategory(
|
export async function removeDiscoverySubcategory(guildId: bigint, categoryId: number) {
|
||||||
guildId: bigint,
|
|
||||||
categoryId: number
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId));
|
||||||
"delete",
|
|
||||||
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,7 @@ import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
export async function validDiscoveryTerm(term: string) {
|
export async function validDiscoveryTerm(term: string) {
|
||||||
const result = await rest.runMethod<ValidateDiscoverySearchTerm>(
|
const result = await rest.runMethod<ValidateDiscoverySearchTerm>("get", endpoints.DISCOVERY_VALID_TERM, { term });
|
||||||
"get",
|
|
||||||
endpoints.DISCOVERY_VALID_TERM,
|
|
||||||
{ term }
|
|
||||||
);
|
|
||||||
|
|
||||||
return result.valid;
|
return result.valid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,27 +7,18 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
import { urlToBase64 } from "../../util/utils.ts";
|
import { urlToBase64 } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
||||||
export async function createEmoji(
|
export async function createEmoji(guildId: bigint, name: string, image: string, options: CreateGuildEmoji) {
|
||||||
guildId: bigint,
|
|
||||||
name: string,
|
|
||||||
image: string,
|
|
||||||
options: CreateGuildEmoji
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
if (image && !image.startsWith("data:image/")) {
|
if (image && !image.startsWith("data:image/")) {
|
||||||
image = await urlToBase64(image);
|
image = await urlToBase64(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emoji = await rest.runMethod<Emoji>(
|
const emoji = await rest.runMethod<Emoji>("post", endpoints.GUILD_EMOJIS(guildId), {
|
||||||
"post",
|
...options,
|
||||||
endpoints.GUILD_EMOJIS(guildId),
|
name,
|
||||||
{
|
image,
|
||||||
...options,
|
});
|
||||||
name,
|
|
||||||
image,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...emoji,
|
...emoji,
|
||||||
|
|||||||
@@ -3,16 +3,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
||||||
export async function deleteEmoji(
|
export async function deleteEmoji(guildId: bigint, id: bigint, reason?: string) {
|
||||||
guildId: bigint,
|
|
||||||
id: bigint,
|
|
||||||
reason?: string
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.GUILD_EMOJI(guildId, id), { reason });
|
||||||
"delete",
|
|
||||||
endpoints.GUILD_EMOJI(guildId, id),
|
|
||||||
{ reason }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||||
export async function editEmoji(
|
export async function editEmoji(guildId: bigint, id: bigint, options: ModifyGuildEmoji) {
|
||||||
guildId: bigint,
|
|
||||||
id: bigint,
|
|
||||||
options: ModifyGuildEmoji
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
return await rest.runMethod<Emoji>(
|
return await rest.runMethod<Emoji>("patch", endpoints.GUILD_EMOJI(guildId, id), {
|
||||||
"patch",
|
name: options.name,
|
||||||
endpoints.GUILD_EMOJI(guildId, id),
|
roles: options.roles,
|
||||||
{
|
});
|
||||||
name: options.name,
|
|
||||||
roles: options.roles,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
*
|
*
|
||||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
*/
|
*/
|
||||||
export async function getEmoji(
|
export async function getEmoji(guildId: bigint, emojiId: bigint, addToCache = true) {
|
||||||
guildId: bigint,
|
const result = await rest.runMethod<Emoji>("get", endpoints.GUILD_EMOJI(guildId, emojiId));
|
||||||
emojiId: bigint,
|
|
||||||
addToCache = true
|
|
||||||
) {
|
|
||||||
const result = await rest.runMethod<Emoji>(
|
|
||||||
"get",
|
|
||||||
endpoints.GUILD_EMOJI(guildId, emojiId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
*/
|
*/
|
||||||
export async function getEmojis(guildId: bigint, addToCache = true) {
|
export async function getEmojis(guildId: bigint, addToCache = true) {
|
||||||
const result = await rest.runMethod<Emoji[]>(
|
const result = await rest.runMethod<Emoji[]>("get", endpoints.GUILD_EMOJIS(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_EMOJIS(guildId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
|
|||||||
@@ -3,8 +3,5 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
|
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
|
||||||
export async function deleteGuild(guildId: bigint) {
|
export async function deleteGuild(guildId: bigint) {
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.GUILDS_BASE(guildId));
|
||||||
"delete",
|
|
||||||
endpoints.GUILDS_BASE(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,18 +24,11 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
|||||||
options.splash = await urlToBase64(options.splash);
|
options.splash = await urlToBase64(options.splash);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod<Guild>(
|
const result = await rest.runMethod<Guild>("patch", endpoints.GUILDS_BASE(guildId), options);
|
||||||
"patch",
|
|
||||||
endpoints.GUILDS_BASE(guildId),
|
|
||||||
options
|
|
||||||
);
|
|
||||||
|
|
||||||
const cached = await cacheHandlers.get("guilds", guildId);
|
const cached = await cacheHandlers.get("guilds", guildId);
|
||||||
return structures.createDiscordenoGuild(
|
return structures.createDiscordenoGuild(
|
||||||
result,
|
result,
|
||||||
cached?.shardId ||
|
cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString())
|
||||||
Number(
|
|
||||||
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { snakelize } from "../../util/utils.ts";
|
import { snakelize } from "../../util/utils.ts";
|
||||||
|
|
||||||
export async function editWelcomeScreen(
|
export async function editWelcomeScreen(guildId: bigint, options: ModifyGuildWelcomeScreen) {
|
||||||
guildId: bigint,
|
return await rest.runMethod<WelcomeScreen>("patch", endpoints.GUILD_WELCOME_SCREEN(guildId), snakelize(options));
|
||||||
options: ModifyGuildWelcomeScreen
|
|
||||||
) {
|
|
||||||
return await rest.runMethod<WelcomeScreen>(
|
|
||||||
"patch",
|
|
||||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
|
||||||
snakelize(options)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||||
export async function editWidget(
|
export async function editWidget(guildId: bigint, enabled: boolean, channelId?: string | null) {
|
||||||
guildId: bigint,
|
|
||||||
enabled: boolean,
|
|
||||||
channelId?: string | null
|
|
||||||
) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<GuildWidget>(
|
return await rest.runMethod<GuildWidget>("patch", endpoints.GUILD_WIDGET(guildId), {
|
||||||
"patch",
|
enabled,
|
||||||
endpoints.GUILD_WIDGET(guildId),
|
channel_id: channelId,
|
||||||
{
|
});
|
||||||
enabled,
|
|
||||||
channel_id: channelId,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ export async function getAuditLogs(guildId: bigint, options: GetGuildAuditLog) {
|
|||||||
endpoints.GUILD_AUDIT_LOGS(guildId),
|
endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||||
snakelize({
|
snakelize({
|
||||||
...options,
|
...options,
|
||||||
limit:
|
limit: options.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50,
|
||||||
options.limit && options.limit >= 1 && options.limit <= 100
|
|
||||||
? options.limit
|
|
||||||
: 50,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,5 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function getBan(guildId: bigint, memberId: bigint) {
|
export async function getBan(guildId: bigint, memberId: bigint) {
|
||||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
return await rest.runMethod<Ban>(
|
return await rest.runMethod<Ban>("get", endpoints.GUILD_BAN(guildId, memberId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_BAN(guildId, memberId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function getBans(guildId: bigint) {
|
export async function getBans(guildId: bigint) {
|
||||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
const results = await rest.runMethod<Ban[]>(
|
const results = await rest.runMethod<Ban[]>("get", endpoints.GUILD_BANS(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_BANS(guildId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Collection<bigint, Ban>(
|
return new Collection<bigint, Ban>(results.map((res) => [snowflakeToBigint(res.user.id), res]));
|
||||||
results.map((res) => [snowflakeToBigint(res.user.id), res])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,9 @@ export async function getGuild(
|
|||||||
addToCache: true,
|
addToCache: true,
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const result = await rest.runMethod<Guild>(
|
const result = await rest.runMethod<Guild>("get", endpoints.GUILDS_BASE(guildId), {
|
||||||
"get",
|
with_counts: options.counts,
|
||||||
endpoints.GUILDS_BASE(guildId),
|
});
|
||||||
{
|
|
||||||
with_counts: options.counts,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const guild = await structures.createDiscordenoGuild(
|
const guild = await structures.createDiscordenoGuild(
|
||||||
result,
|
result,
|
||||||
|
|||||||
@@ -4,8 +4,5 @@ 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. */
|
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
|
||||||
export async function getGuildPreview(guildId: bigint) {
|
export async function getGuildPreview(guildId: bigint) {
|
||||||
return await rest.runMethod<GuildPreview>(
|
return await rest.runMethod<GuildPreview>("get", endpoints.GUILD_PREVIEW(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_PREVIEW(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
import { snakelize } 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 */
|
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||||
export async function getPruneCount(
|
export async function getPruneCount(guildId: bigint, options?: GetGuildPruneCountQuery) {
|
||||||
guildId: bigint,
|
|
||||||
options?: GetGuildPruneCountQuery
|
|
||||||
) {
|
|
||||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||||
if (options?.days && options.days > 30) {
|
if (options?.days && options.days > 30) {
|
||||||
throw new Error(Errors.PRUNE_MAX_DAYS);
|
throw new Error(Errors.PRUNE_MAX_DAYS);
|
||||||
@@ -17,11 +14,7 @@ export async function getPruneCount(
|
|||||||
|
|
||||||
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
const result = await rest.runMethod("get", endpoints.GUILD_PRUNE(guildId), snakelize(options ?? {}));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_PRUNE(guildId),
|
|
||||||
snakelize(options ?? {})
|
|
||||||
);
|
|
||||||
|
|
||||||
return result.pruned as number;
|
return result.pruned as number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
|
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
|
||||||
export async function getVoiceRegions(guildId: bigint) {
|
export async function getVoiceRegions(guildId: bigint) {
|
||||||
const result = await rest.runMethod<VoiceRegion[]>(
|
const result = await rest.runMethod<VoiceRegion[]>("get", endpoints.GUILD_REGIONS(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_REGIONS(guildId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Collection<string, VoiceRegion>(
|
return new Collection<string, VoiceRegion>(result.map((region) => [region.id, region]));
|
||||||
result.map((region) => [region.id, region])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,5 @@ import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
export async function getWelcomeScreen(guildId: bigint) {
|
export async function getWelcomeScreen(guildId: bigint) {
|
||||||
return await rest.runMethod<WelcomeScreen>(
|
return await rest.runMethod<WelcomeScreen>("get", endpoints.GUILD_WELCOME_SCREEN(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_WELCOME_SCREEN(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,5 @@ export async function getWidget(guildId: bigint, options?: { force: boolean }) {
|
|||||||
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<GuildWidgetDetails>(
|
return await rest.runMethod<GuildWidgetDetails>("get", `${endpoints.GUILD_WIDGET(guildId)}.json`);
|
||||||
"get",
|
|
||||||
`${endpoints.GUILD_WIDGET(guildId)}.json`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,12 @@ import { Errors } from "../../types/discordeno/errors.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns the widget image URL for the guild. */
|
/** Returns the widget image URL for the guild. */
|
||||||
export async function getWidgetImageURL(
|
export async function getWidgetImageURL(guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) {
|
||||||
guildId: bigint,
|
|
||||||
options?: GetGuildWidgetImageQuery & { force?: boolean }
|
|
||||||
) {
|
|
||||||
if (!options?.force) {
|
if (!options?.force) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${
|
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`;
|
||||||
options?.style ?? "shield"
|
|
||||||
}`;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,5 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function getWidgetSettings(guildId: bigint) {
|
export async function getWidgetSettings(guildId: bigint) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<GuildWidget>(
|
return await rest.runMethod<GuildWidget>("get", endpoints.GUILD_WIDGET(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_WIDGET(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ export function guildIconURL(
|
|||||||
? formatImageURL(
|
? formatImageURL(
|
||||||
endpoints.GUILD_ICON(
|
endpoints.GUILD_ICON(
|
||||||
id,
|
id,
|
||||||
typeof options.icon === "string"
|
typeof options.icon === "string" ? options.icon : iconBigintToHash(options.icon, options.animated ?? true)
|
||||||
? options.icon
|
|
||||||
: iconBigintToHash(options.icon, options.animated ?? true)
|
|
||||||
),
|
),
|
||||||
options.size || 128,
|
options.size || 128,
|
||||||
options.format
|
options.format
|
||||||
|
|||||||
@@ -3,8 +3,5 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Leave a guild */
|
/** Leave a guild */
|
||||||
export async function leaveGuild(guildId: bigint) {
|
export async function leaveGuild(guildId: bigint) {
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.GUILD_LEAVE(guildId));
|
||||||
"delete",
|
|
||||||
endpoints.GUILD_LEAVE(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,5 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function deleteIntegration(guildId: bigint, id: bigint) {
|
export async function deleteIntegration(guildId: bigint, id: bigint) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>("delete", endpoints.GUILD_INTEGRATION(guildId, id));
|
||||||
"delete",
|
|
||||||
endpoints.GUILD_INTEGRATION(guildId, id)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,5 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function getIntegrations(guildId: bigint) {
|
export async function getIntegrations(guildId: bigint) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
return await rest.runMethod<Integration>(
|
return await rest.runMethod<Integration>("get", endpoints.GUILD_INTEGRATIONS(guildId));
|
||||||
"get",
|
|
||||||
endpoints.GUILD_INTEGRATIONS(guildId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,5 @@ export async function batchEditSlashCommandPermissions(
|
|||||||
guildId: bigint,
|
guildId: bigint,
|
||||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
||||||
) {
|
) {
|
||||||
return await rest.runMethod(
|
return await rest.runMethod("put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), snakelize(options));
|
||||||
"put",
|
|
||||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
|
||||||
snakelize(options)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,12 @@ import { snakelize, validateSlashCommands } from "../../../util/utils.ts";
|
|||||||
* Global commands are cached for **1 hour**. That means that new global commands will fan out slowly across all guilds, and will be guaranteed to be updated in an hour.
|
* Global commands are cached for **1 hour**. That means that new global commands will fan out slowly across all guilds, and will be guaranteed to be updated in an hour.
|
||||||
* Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.
|
* Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.
|
||||||
*/
|
*/
|
||||||
export async function createSlashCommand(
|
export async function createSlashCommand(options: CreateGlobalApplicationCommand, guildId?: bigint) {
|
||||||
options: CreateGlobalApplicationCommand,
|
|
||||||
guildId?: bigint
|
|
||||||
) {
|
|
||||||
validateSlashCommands([options], true);
|
validateSlashCommands([options], true);
|
||||||
|
|
||||||
return await rest.runMethod<ApplicationCommand>(
|
return await rest.runMethod<ApplicationCommand>(
|
||||||
"post",
|
"post",
|
||||||
guildId
|
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
|
||||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
|
||||||
: endpoints.COMMANDS(applicationId),
|
|
||||||
snakelize(options)
|
snakelize(options)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import { endpoints } from "../../../util/constants.ts";
|
|||||||
export async function deleteSlashCommand(id: bigint, guildId?: bigint) {
|
export async function deleteSlashCommand(id: bigint, guildId?: bigint) {
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
guildId
|
guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id) : endpoints.COMMANDS_ID(applicationId, id)
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id)
|
|
||||||
: endpoints.COMMANDS_ID(applicationId, id)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,7 @@ export async function deleteSlashResponse(token: string, messageId?: bigint) {
|
|||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
messageId
|
messageId
|
||||||
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(
|
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(applicationId, token, messageId)
|
||||||
applicationId,
|
|
||||||
token,
|
|
||||||
messageId
|
|
||||||
)
|
|
||||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user