mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Prettified Code!
This commit is contained in:
+5
-10
@@ -20,21 +20,16 @@ export async function startBot(config: BotConfig) {
|
||||
ws.identifyPayload.token = `Bot ${config.token}`;
|
||||
rest.token = `Bot ${config.token}`;
|
||||
ws.identifyPayload.intents = config.intents.reduce(
|
||||
(
|
||||
bits,
|
||||
next,
|
||||
) => (bits |= typeof next === "string"
|
||||
? DiscordGatewayIntents[next]
|
||||
: next),
|
||||
0,
|
||||
(bits, next) =>
|
||||
(bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
||||
0
|
||||
);
|
||||
|
||||
// Initial API connection to get info about bots connection
|
||||
ws.botGatewayData = await getGatewayBot();
|
||||
ws.maxShards = ws.maxShards || ws.botGatewayData.shards;
|
||||
ws.lastShardId = ws.lastShardId === 1
|
||||
? ws.botGatewayData.shards - 1
|
||||
: ws.lastShardId;
|
||||
ws.lastShardId =
|
||||
ws.lastShardId === 1 ? ws.botGatewayData.shards - 1 : ws.lastShardId;
|
||||
|
||||
// Explicitly append gateway version and encoding
|
||||
ws.botGatewayData.url += `?v=${GATEWAY_VERSION}&encoding=json`;
|
||||
|
||||
+31
-31
@@ -26,7 +26,7 @@ export const cache = {
|
||||
(
|
||||
value:
|
||||
| Collection<bigint, DiscordenoMember>
|
||||
| PromiseLike<Collection<bigint, DiscordenoMember>>,
|
||||
| PromiseLike<Collection<bigint, DiscordenoMember>>
|
||||
) => void
|
||||
>(),
|
||||
executedSlashCommands: new Set<string>(),
|
||||
@@ -34,8 +34,8 @@ export const cache = {
|
||||
return new Collection<bigint, Emoji>(
|
||||
this.guilds.reduce(
|
||||
(a, b) => [...a, ...b.emojis.map((e) => [e.id, e])],
|
||||
[] as any[],
|
||||
),
|
||||
[] as any[]
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -81,32 +81,32 @@ export type TableName =
|
||||
function set(
|
||||
table: "guilds",
|
||||
key: bigint,
|
||||
value: DiscordenoGuild,
|
||||
value: DiscordenoGuild
|
||||
): Promise<Collection<bigint, DiscordenoGuild>>;
|
||||
function set(
|
||||
table: "channels",
|
||||
key: bigint,
|
||||
value: DiscordenoChannel,
|
||||
value: DiscordenoChannel
|
||||
): Promise<Collection<bigint, DiscordenoChannel>>;
|
||||
function set(
|
||||
table: "messages",
|
||||
key: bigint,
|
||||
value: DiscordenoMessage,
|
||||
value: DiscordenoMessage
|
||||
): Promise<Collection<bigint, DiscordenoMessage>>;
|
||||
function set(
|
||||
table: "members",
|
||||
key: bigint,
|
||||
value: DiscordenoMember,
|
||||
value: DiscordenoMember
|
||||
): Promise<Collection<bigint, DiscordenoMember>>;
|
||||
function set(
|
||||
table: "presences",
|
||||
key: bigint,
|
||||
value: PresenceUpdate,
|
||||
value: PresenceUpdate
|
||||
): Promise<Collection<bigint, PresenceUpdate>>;
|
||||
function set(
|
||||
table: "unavailableGuilds",
|
||||
key: bigint,
|
||||
value: number,
|
||||
value: number
|
||||
): Promise<Collection<bigint, number>>;
|
||||
async function set(table: TableName, key: bigint, value: any) {
|
||||
return cache[table].set(key, value);
|
||||
@@ -114,27 +114,27 @@ async function set(table: TableName, key: bigint, value: any) {
|
||||
|
||||
function get(
|
||||
table: "guilds",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<DiscordenoGuild | undefined>;
|
||||
function get(
|
||||
table: "channels",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<DiscordenoChannel | undefined>;
|
||||
function get(
|
||||
table: "messages",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<DiscordenoMessage | undefined>;
|
||||
function get(
|
||||
table: "members",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<DiscordenoMember | undefined>;
|
||||
function get(
|
||||
table: "presences",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<PresenceUpdate | undefined>;
|
||||
function get(
|
||||
table: "unavailableGuilds",
|
||||
key: bigint,
|
||||
key: bigint
|
||||
): Promise<number | undefined>;
|
||||
async function get(table: TableName, key: bigint) {
|
||||
return cache[table].get(key);
|
||||
@@ -145,67 +145,67 @@ function forEach(
|
||||
callback: (
|
||||
value: DiscordenoGuild,
|
||||
key: bigint,
|
||||
map: Map<bigint, DiscordenoGuild>,
|
||||
) => unknown,
|
||||
map: Map<bigint, DiscordenoGuild>
|
||||
) => unknown
|
||||
): void;
|
||||
function forEach(
|
||||
table: "unavailableGuilds",
|
||||
callback: (value: number, key: bigint, map: Map<bigint, number>) => unknown,
|
||||
callback: (value: number, key: bigint, map: Map<bigint, number>) => unknown
|
||||
): void;
|
||||
function forEach(
|
||||
table: "channels",
|
||||
callback: (
|
||||
value: DiscordenoChannel,
|
||||
key: bigint,
|
||||
map: Map<bigint, DiscordenoChannel>,
|
||||
) => unknown,
|
||||
map: Map<bigint, DiscordenoChannel>
|
||||
) => unknown
|
||||
): void;
|
||||
function forEach(
|
||||
table: "messages",
|
||||
callback: (
|
||||
value: DiscordenoMessage,
|
||||
key: bigint,
|
||||
map: Map<bigint, DiscordenoMessage>,
|
||||
) => unknown,
|
||||
map: Map<bigint, DiscordenoMessage>
|
||||
) => unknown
|
||||
): void;
|
||||
function forEach(
|
||||
table: "members",
|
||||
callback: (
|
||||
value: DiscordenoMember,
|
||||
key: bigint,
|
||||
map: Map<bigint, DiscordenoMember>,
|
||||
) => unknown,
|
||||
map: Map<bigint, DiscordenoMember>
|
||||
) => unknown
|
||||
): void;
|
||||
function forEach(
|
||||
table: TableName,
|
||||
callback: (value: any, key: bigint, map: Map<bigint, any>) => unknown,
|
||||
callback: (value: any, key: bigint, map: Map<bigint, any>) => unknown
|
||||
) {
|
||||
return cache[table].forEach(callback);
|
||||
}
|
||||
|
||||
function filter(
|
||||
table: "guilds",
|
||||
callback: (value: DiscordenoGuild, key: bigint) => boolean,
|
||||
callback: (value: DiscordenoGuild, key: bigint) => boolean
|
||||
): Promise<Collection<bigint, DiscordenoGuild>>;
|
||||
function filter(
|
||||
table: "unavailableGuilds",
|
||||
callback: (value: number, key: bigint) => boolean,
|
||||
callback: (value: number, key: bigint) => boolean
|
||||
): Promise<Collection<bigint, number>>;
|
||||
function filter(
|
||||
table: "channels",
|
||||
callback: (value: DiscordenoChannel, key: bigint) => boolean,
|
||||
callback: (value: DiscordenoChannel, key: bigint) => boolean
|
||||
): Promise<Collection<bigint, DiscordenoChannel>>;
|
||||
function filter(
|
||||
table: "messages",
|
||||
callback: (value: DiscordenoMessage, key: bigint) => boolean,
|
||||
callback: (value: DiscordenoMessage, key: bigint) => boolean
|
||||
): Promise<Collection<bigint, DiscordenoMessage>>;
|
||||
function filter(
|
||||
table: "members",
|
||||
callback: (value: DiscordenoMember, key: bigint) => boolean,
|
||||
callback: (value: DiscordenoMember, key: bigint) => boolean
|
||||
): Promise<Collection<bigint, DiscordenoMember>>;
|
||||
async function filter(
|
||||
table: TableName,
|
||||
callback: (value: any, key: bigint) => boolean,
|
||||
callback: (value: any, key: bigint) => boolean
|
||||
) {
|
||||
return cache[table].filter(callback);
|
||||
}
|
||||
|
||||
@@ -10,27 +10,30 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
|
||||
const cachedChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
if (
|
||||
cachedChannel.type === DiscordChannelTypes.GuildVoice && payload.guildId
|
||||
cachedChannel.type === DiscordChannelTypes.GuildVoice &&
|
||||
payload.guildId
|
||||
) {
|
||||
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
|
||||
|
||||
if (guild) {
|
||||
return Promise.all(guild.voiceStates.map(async (vs, key) => {
|
||||
if (vs.channelId !== cachedChannel.id) return;
|
||||
return Promise.all(
|
||||
guild.voiceStates.map(async (vs, key) => {
|
||||
if (vs.channelId !== cachedChannel.id) return;
|
||||
|
||||
// Since this channel was deleted all voice states for this channel should be deleted
|
||||
guild.voiceStates.delete(key);
|
||||
// Since this channel was deleted all voice states for this channel should be deleted
|
||||
guild.voiceStates.delete(key);
|
||||
|
||||
const member = await cacheHandlers.get("members", vs.userId);
|
||||
if (!member) return;
|
||||
const member = await cacheHandlers.get("members", vs.userId);
|
||||
if (!member) return;
|
||||
|
||||
eventHandlers.voiceChannelLeave?.(member, vs.channelId);
|
||||
}));
|
||||
eventHandlers.voiceChannelLeave?.(member, vs.channelId);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +49,7 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const channel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
if (!channel) return;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleChannelUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
const cachedChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
||||
|
||||
const cachedChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!cachedChannel) return;
|
||||
|
||||
@@ -17,7 +17,7 @@ export async function handleThreadDelete(data: DiscordGatewayPayload) {
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
`Running forEach messages loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
if (message.channelId === snowflakeToBigint(payload.id)) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
|
||||
@@ -14,26 +14,26 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) {
|
||||
payload.threads.map(async (thread) => {
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||
thread,
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
|
||||
await cacheHandlers.set(
|
||||
"channels",
|
||||
discordenoChannel.id,
|
||||
discordenoChannel,
|
||||
discordenoChannel
|
||||
);
|
||||
|
||||
return discordenoChannel;
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const threads = new Collection<bigint, DiscordenoChannel>(
|
||||
discordenoChannels.map((t) => [t.id, t]),
|
||||
discordenoChannels.map((t) => [t.id, t])
|
||||
);
|
||||
|
||||
eventHandlers.threadListSync?.(
|
||||
threads,
|
||||
payload.members,
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as ThreadMembersUpdate;
|
||||
const thread = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!thread) return;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as ThreadMember;
|
||||
const thread = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!thread) return;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleThreadUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Channel;
|
||||
const oldChannel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!oldChannel) return;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
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?.(
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
data.d as ApplicationCommandCreateUpdateDelete
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
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) {
|
||||
eventHandlers.applicationCommandDelete?.(
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
data.d as ApplicationCommandCreateUpdateDelete
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
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) {
|
||||
eventHandlers.applicationCommandUpdate?.(
|
||||
data.d as ApplicationCommandCreateUpdateDelete,
|
||||
data.d as ApplicationCommandCreateUpdateDelete
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,20 +9,16 @@ export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildEmojisUpdate;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedEmojis = guild.emojis;
|
||||
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);
|
||||
|
||||
eventHandlers.guildEmojisUpdate?.(
|
||||
guild,
|
||||
guild.emojis,
|
||||
cachedEmojis,
|
||||
);
|
||||
eventHandlers.guildEmojisUpdate?.(guild, guild.emojis, cachedEmojis);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const member = await cacheHandlers.get(
|
||||
"members",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
snowflakeToBigint(payload.user.id)
|
||||
);
|
||||
eventHandlers.guildBanAdd?.(guild, payload.user, member);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildBanAddRemove;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const member = await cacheHandlers.get(
|
||||
"members",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
snowflakeToBigint(payload.user.id)
|
||||
);
|
||||
eventHandlers.guildBanRemove?.(guild, payload.user, member);
|
||||
}
|
||||
|
||||
@@ -8,16 +8,13 @@ import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export async function handleGuildCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
shardId: number
|
||||
) {
|
||||
const payload = data.d as Guild;
|
||||
// When shards resume they emit GUILD_CREATE again.
|
||||
if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return;
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(
|
||||
payload,
|
||||
shardId,
|
||||
);
|
||||
const guild = await structures.createDiscordenoGuild(payload, shardId);
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
|
||||
const shard = ws.shards.get(shardId);
|
||||
|
||||
@@ -7,13 +7,13 @@ import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export async function handleGuildDelete(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
shardId: number
|
||||
) {
|
||||
const payload = data.d as UnavailableGuild;
|
||||
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function handleGuildDelete(
|
||||
cacheHandlers.forEach("messages", (message) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`1. Running forEach messages loop in CHANNEL_DELTE file.`,
|
||||
`1. Running forEach messages loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
if (message.guildId === guild.id) {
|
||||
cacheHandlers.delete("messages", message.id);
|
||||
@@ -42,7 +42,7 @@ export async function handleGuildDelete(
|
||||
cacheHandlers.forEach("channels", (channel) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`2. Running forEach channels loop in CHANNEL_DELTE file.`,
|
||||
`2. Running forEach channels loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
if (channel.guildId === guild.id) {
|
||||
cacheHandlers.delete("channels", channel.id);
|
||||
@@ -52,7 +52,7 @@ export async function handleGuildDelete(
|
||||
cacheHandlers.forEach("members", (member) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`3. Running forEach members loop in CHANNEL_DELTE file.`,
|
||||
`3. Running forEach members loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
if (!member.guilds.has(guild.id)) return;
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_int
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildIntegrationsUpdate(
|
||||
data: DiscordGatewayPayload,
|
||||
data: DiscordGatewayPayload
|
||||
) {
|
||||
const payload = data.d as GuildIntegrationsUpdate;
|
||||
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleGuildUpdate(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
shardId: number
|
||||
) {
|
||||
const payload = data.d as Guild;
|
||||
const oldGuild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!oldGuild) return;
|
||||
|
||||
@@ -40,7 +40,8 @@ export async function handleGuildUpdate(
|
||||
if (!cachedValue && !value) return;
|
||||
|
||||
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
||||
const different = cachedValue.length !== value.length ||
|
||||
const different =
|
||||
cachedValue.length !== value.length ||
|
||||
cachedValue.find((val) => !value.includes(val)) ||
|
||||
value.find((val) => !cachedValue.includes(val));
|
||||
if (!different) return;
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integrations/integration_create_update.ts";
|
||||
import type { IntegrationCreateUpdate } from "../../types/integrations/integration_create_update.ts";
|
||||
|
||||
export function handleIntegrationCreate(
|
||||
data: DiscordGatewayPayload,
|
||||
) {
|
||||
eventHandlers.integrationCreate?.(
|
||||
data.d as IntegrationCreateUpdate,
|
||||
);
|
||||
export function handleIntegrationCreate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationCreate?.(data.d as IntegrationCreateUpdate);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
||||
import type { IntegrationDelete } from "../../types/integrations/integration_delete.ts";
|
||||
|
||||
export function handleIntegrationDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationDelete?.(
|
||||
data.d as IntegrationDelete,
|
||||
);
|
||||
eventHandlers.integrationDelete?.(data.d as IntegrationDelete);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
IntegrationCreateUpdate,
|
||||
} from "../../types/integrations/integration_create_update.ts";
|
||||
import type { IntegrationCreateUpdate } from "../../types/integrations/integration_create_update.ts";
|
||||
|
||||
export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.integrationUpdate?.(
|
||||
data.d as IntegrationCreateUpdate,
|
||||
);
|
||||
eventHandlers.integrationUpdate?.(data.d as IntegrationCreateUpdate);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Interaction;
|
||||
const discordenoMember = payload.guildId
|
||||
? await structures.createDiscordenoMember(
|
||||
payload.member as GuildMemberWithUser,
|
||||
snowflakeToBigint(payload.guildId),
|
||||
)
|
||||
payload.member as GuildMemberWithUser,
|
||||
snowflakeToBigint(payload.guildId)
|
||||
)
|
||||
: undefined;
|
||||
if (discordenoMember) {
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
||||
import type { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||
|
||||
export function handleInviteCreate(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteCreate?.(
|
||||
data.d as InviteCreate,
|
||||
);
|
||||
eventHandlers.inviteCreate?.(data.d as InviteCreate);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
||||
import type { InviteDelete } from "../../types/invites/invite_delete.ts";
|
||||
|
||||
export function handleInviteDelete(data: DiscordGatewayPayload) {
|
||||
eventHandlers.inviteDelete?.(
|
||||
data.d as InviteDelete,
|
||||
);
|
||||
eventHandlers.inviteDelete?.(data.d as InviteDelete);
|
||||
}
|
||||
|
||||
@@ -14,18 +14,16 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
||||
payload.members.map(async (member) => {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
member,
|
||||
guildId,
|
||||
guildId
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
return discordenoMember;
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
|
||||
if (
|
||||
payload.nonce
|
||||
) {
|
||||
if (payload.nonce) {
|
||||
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
|
||||
if (!resolve) return;
|
||||
|
||||
@@ -37,10 +35,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
|
||||
}
|
||||
|
||||
return resolve(
|
||||
await cacheHandlers.filter(
|
||||
"members",
|
||||
(m) => m.guilds.has(guildId),
|
||||
),
|
||||
await cacheHandlers.filter("members", (m) => m.guilds.has(guildId))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildMemberAdd;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
guild.memberCount++;
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload,
|
||||
guild.id,
|
||||
guild.id
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildMemberRemove;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
guild.memberCount--;
|
||||
const member = await cacheHandlers.get(
|
||||
"members",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
snowflakeToBigint(payload.user.id)
|
||||
);
|
||||
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
|
||||
|
||||
|
||||
@@ -9,28 +9,27 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildMemberUpdate;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const cachedMember = await cacheHandlers.get(
|
||||
"members",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
snowflakeToBigint(payload.user.id)
|
||||
);
|
||||
const guildMember = cachedMember?.guilds.get(guild.id);
|
||||
|
||||
const newMemberData = {
|
||||
...payload,
|
||||
premiumSince: payload.premiumSince || undefined,
|
||||
joinedAt: new Date(guildMember?.joinedAt || Date.now())
|
||||
.toISOString(),
|
||||
joinedAt: new Date(guildMember?.joinedAt || Date.now()).toISOString(),
|
||||
deaf: guildMember?.deaf || false,
|
||||
mute: guildMember?.mute || false,
|
||||
roles: payload.roles,
|
||||
};
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
newMemberData,
|
||||
guild.id,
|
||||
guild.id
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
@@ -40,7 +39,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
guild,
|
||||
discordenoMember,
|
||||
payload.nick!,
|
||||
guildMember.nick ?? undefined,
|
||||
guildMember.nick ?? undefined
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
roleIds.forEach((id) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`1. Running forEach loop in GUILD_MEMBER_UPDATE file.`,
|
||||
`1. Running forEach loop in GUILD_MEMBER_UPDATE file.`
|
||||
);
|
||||
if (!payload.roles.includes(bigintToSnowflake(id))) {
|
||||
eventHandlers.roleLost?.(guild, discordenoMember, id);
|
||||
@@ -63,13 +62,13 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
||||
payload.roles.forEach((id) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`2. Running forEach loop in GUILD_MEMBER_UPDATE file.`,
|
||||
`2. Running forEach loop in GUILD_MEMBER_UPDATE file.`
|
||||
);
|
||||
if (!roleIds.includes(snowflakeToBigint(id))) {
|
||||
eventHandlers.roleGained?.(
|
||||
guild,
|
||||
discordenoMember,
|
||||
snowflakeToBigint(id),
|
||||
snowflakeToBigint(id)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Message;
|
||||
const channel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
if (channel) channel.lastMessageId = snowflakeToBigint(payload.id);
|
||||
|
||||
@@ -22,32 +22,32 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
// If in a guild cache the author as a member
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...payload.member, user: payload.author } as GuildMemberWithUser,
|
||||
guild.id,
|
||||
guild.id
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
}
|
||||
|
||||
if (payload.mentions && guild) {
|
||||
await Promise.all(payload.mentions.map(async (mention) => {
|
||||
// Cache the member if its a valid member
|
||||
if (mention.member) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...mention.member, user: mention } as GuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
await Promise.all(
|
||||
payload.mentions.map(async (mention) => {
|
||||
// Cache the member if its a valid member
|
||||
if (mention.member) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...mention.member, user: mention } as GuildMemberWithUser,
|
||||
guild.id
|
||||
);
|
||||
|
||||
return cacheHandlers.set(
|
||||
"members",
|
||||
snowflakeToBigint(mention.id),
|
||||
discordenoMember,
|
||||
);
|
||||
}
|
||||
}));
|
||||
return cacheHandlers.set(
|
||||
"members",
|
||||
snowflakeToBigint(mention.id),
|
||||
discordenoMember
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const message = await structures.createDiscordenoMessage(
|
||||
data.d as Message,
|
||||
);
|
||||
const message = await structures.createDiscordenoMessage(data.d as Message);
|
||||
// Cache the message
|
||||
await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message);
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ export async function handleMessageDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as MessageDelete;
|
||||
const channel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
if (!channel) return;
|
||||
|
||||
eventHandlers.messageDelete?.(
|
||||
{ id: payload.id, channel },
|
||||
await cacheHandlers.get("messages", snowflakeToBigint(payload.id)),
|
||||
await cacheHandlers.get("messages", snowflakeToBigint(payload.id))
|
||||
);
|
||||
|
||||
await cacheHandlers.delete("messages", snowflakeToBigint(payload.id));
|
||||
|
||||
@@ -8,15 +8,17 @@ export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as MessageDeleteBulk;
|
||||
const channel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
if (!channel) return;
|
||||
|
||||
return Promise.all(payload.ids.map(async (id) => {
|
||||
eventHandlers.messageDelete?.(
|
||||
{ id, channel },
|
||||
await cacheHandlers.get("messages", snowflakeToBigint(id)),
|
||||
);
|
||||
await cacheHandlers.delete("messages", snowflakeToBigint(id));
|
||||
}));
|
||||
return Promise.all(
|
||||
payload.ids.map(async (id) => {
|
||||
eventHandlers.messageDelete?.(
|
||||
{ id, channel },
|
||||
await cacheHandlers.get("messages", snowflakeToBigint(id))
|
||||
);
|
||||
await cacheHandlers.delete("messages", snowflakeToBigint(id));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,21 @@ import { botId, eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
MessageReactionAdd,
|
||||
} from "../../types/messages/message_reaction_add.ts";
|
||||
import type { MessageReactionAdd } from "../../types/messages/message_reaction_add.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as MessageReactionAdd;
|
||||
const message = await cacheHandlers.get(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
snowflakeToBigint(payload.messageId)
|
||||
);
|
||||
|
||||
if (message) {
|
||||
const reactionExisted = message.reactions?.find(
|
||||
(reaction) =>
|
||||
reaction.emoji.id === payload.emoji.id &&
|
||||
reaction.emoji.name === payload.emoji.name,
|
||||
reaction.emoji.name === payload.emoji.name
|
||||
);
|
||||
|
||||
if (reactionExisted) reactionExisted.count++;
|
||||
@@ -36,26 +34,23 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
||||
await cacheHandlers.set(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
message,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
if (payload.member && payload.guildId) {
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (guild) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload.member,
|
||||
guild.id,
|
||||
guild.id
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
}
|
||||
}
|
||||
|
||||
eventHandlers.reactionAdd?.(
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
eventHandlers.reactionAdd?.(payload, message);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type {
|
||||
MessageReactionRemove,
|
||||
} from "../../types/messages/message_reaction_remove.ts";
|
||||
import type { MessageReactionRemove } from "../../types/messages/message_reaction_remove.ts";
|
||||
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 message = await cacheHandlers.get(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
snowflakeToBigint(payload.messageId)
|
||||
);
|
||||
|
||||
if (message) {
|
||||
const reaction = message.reactions?.find((reaction) =>
|
||||
// MUST USE == because discord sends null and we use undefined
|
||||
reaction.emoji.id == payload.emoji.id &&
|
||||
reaction.emoji.name === payload.emoji.name
|
||||
const reaction = message.reactions?.find(
|
||||
(reaction) =>
|
||||
// MUST USE == because discord sends null and we use undefined
|
||||
reaction.emoji.id == payload.emoji.id &&
|
||||
reaction.emoji.name === payload.emoji.name
|
||||
);
|
||||
|
||||
if (reaction) {
|
||||
@@ -33,8 +30,5 @@ export async function handleMessageReactionRemove(
|
||||
}
|
||||
}
|
||||
|
||||
eventHandlers.reactionRemove?.(
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
eventHandlers.reactionRemove?.(payload, message);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
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";
|
||||
|
||||
export async function handleMessageReactionRemoveAll(
|
||||
data: DiscordGatewayPayload,
|
||||
data: DiscordGatewayPayload
|
||||
) {
|
||||
const payload = data.d as MessageReactionRemoveAll;
|
||||
const message = await cacheHandlers.get(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
snowflakeToBigint(payload.messageId)
|
||||
);
|
||||
|
||||
if (message?.reactions) {
|
||||
@@ -21,12 +19,9 @@ export async function handleMessageReactionRemoveAll(
|
||||
await cacheHandlers.set(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
message,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
eventHandlers.reactionRemoveAll?.(
|
||||
payload,
|
||||
message,
|
||||
);
|
||||
eventHandlers.reactionRemoveAll?.(payload, message);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import type { MessageReactionRemoveEmoji } from "../../types/messages/message_re
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji(
|
||||
data: DiscordGatewayPayload,
|
||||
data: DiscordGatewayPayload
|
||||
) {
|
||||
const payload = data.d as MessageReactionRemoveEmoji;
|
||||
const message = await cacheHandlers.get(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.messageId),
|
||||
snowflakeToBigint(payload.messageId)
|
||||
);
|
||||
|
||||
if (message?.reactions) {
|
||||
@@ -18,9 +18,11 @@ export async function handleMessageReactionRemoveEmoji(
|
||||
(reaction) =>
|
||||
!(
|
||||
// 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
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (!message.reactions.length) message.reactions = undefined;
|
||||
@@ -32,6 +34,6 @@ export async function handleMessageReactionRemoveEmoji(
|
||||
payload.emoji,
|
||||
snowflakeToBigint(payload.messageId),
|
||||
snowflakeToBigint(payload.channelId),
|
||||
payload.guildId ? snowflakeToBigint(payload.guildId) : undefined,
|
||||
payload.guildId ? snowflakeToBigint(payload.guildId) : undefined
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,21 +9,18 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Message;
|
||||
const channel = await cacheHandlers.get(
|
||||
"channels",
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
if (!channel) return;
|
||||
|
||||
const oldMessage = await cacheHandlers.get(
|
||||
"messages",
|
||||
snowflakeToBigint(payload.id),
|
||||
snowflakeToBigint(payload.id)
|
||||
);
|
||||
if (!oldMessage) return;
|
||||
|
||||
// Messages with embeds can trigger update but they wont have edited_timestamp
|
||||
if (
|
||||
!payload.editedTimestamp ||
|
||||
(oldMessage.content === payload.content)
|
||||
) {
|
||||
if (!payload.editedTimestamp || oldMessage.content === payload.content) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const oldPresence = await cacheHandlers.get(
|
||||
"presences",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
snowflakeToBigint(payload.user.id)
|
||||
);
|
||||
await cacheHandlers.set(
|
||||
"presences",
|
||||
snowflakeToBigint(payload.user.id),
|
||||
payload,
|
||||
payload
|
||||
);
|
||||
|
||||
eventHandlers.presenceUpdate?.(payload, oldPresence);
|
||||
|
||||
@@ -5,10 +5,7 @@ import type { Ready } from "../../types/gateway/ready.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { DiscordenoShard, ws } from "../../ws/ws.ts";
|
||||
|
||||
export function handleReady(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
) {
|
||||
export function handleReady(data: DiscordGatewayPayload, shardId: number) {
|
||||
// Triggered on each shard
|
||||
eventHandlers.shardReady?.(shardId);
|
||||
|
||||
@@ -26,17 +23,14 @@ export function handleReady(
|
||||
shard.ready = false;
|
||||
// All guilds are unavailable at first
|
||||
shard.unavailableGuildIds = new Set(
|
||||
payload.guilds.map((g) => snowflakeToBigint(g.id)),
|
||||
payload.guilds.map((g) => snowflakeToBigint(g.id))
|
||||
);
|
||||
// Set the last available to now
|
||||
shard.lastAvailable = Date.now();
|
||||
|
||||
// Start ready check in 2 seconds
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`1. Running setTimeout in READY file.`,
|
||||
);
|
||||
eventHandlers.debug?.("loop", `1. Running setTimeout in READY file.`);
|
||||
checkReady(payload, shard);
|
||||
}, 2000);
|
||||
}
|
||||
@@ -55,10 +49,7 @@ function checkReady(payload: Ready, shard: DiscordenoShard) {
|
||||
|
||||
// Not all guilds were loaded but 5 seconds haven't passed so check again
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`2. Running setTimeout in READY file.`,
|
||||
);
|
||||
eventHandlers.debug?.("loop", `2. Running setTimeout in READY file.`);
|
||||
checkReady(payload, shard);
|
||||
}, 2000);
|
||||
}
|
||||
@@ -72,10 +63,7 @@ function loaded(shard: DiscordenoShard) {
|
||||
// Still some shards are loading so wait another 2 seconds for them
|
||||
if (ws.shards.some((shard) => !shard.ready)) {
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`3. Running setTimeout in READY file.`,
|
||||
);
|
||||
eventHandlers.debug?.("loop", `3. Running setTimeout in READY file.`);
|
||||
loaded(shard);
|
||||
}, 2000);
|
||||
|
||||
|
||||
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
|
||||
import type { TypingStart } from "../../types/misc/typing_start.ts";
|
||||
|
||||
export function handleTypingStart(data: DiscordGatewayPayload) {
|
||||
eventHandlers.typingStart?.(
|
||||
data.d as TypingStart,
|
||||
);
|
||||
eventHandlers.typingStart?.(data.d as TypingStart);
|
||||
}
|
||||
|
||||
@@ -9,17 +9,14 @@ export async function handleUserUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const member = await cacheHandlers.get(
|
||||
"members",
|
||||
snowflakeToBigint(userData.id),
|
||||
snowflakeToBigint(userData.id)
|
||||
);
|
||||
if (!member) return;
|
||||
|
||||
Object.entries(userData).forEach(([key, value]) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach loop in USER_UPDATE file.`,
|
||||
);
|
||||
eventHandlers.debug?.("loop", `Running forEach loop in USER_UPDATE file.`);
|
||||
// @ts-ignore index signatures
|
||||
if (member[key] !== value) return member[key] = value;
|
||||
if (member[key] !== value) return (member[key] = value);
|
||||
});
|
||||
|
||||
await cacheHandlers.set("members", snowflakeToBigint(userData.id), member);
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildRoleCreate;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildRoleDelete;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
cacheHandlers.forEach("members", (member) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`1. Running forEach members loop in GUILD_ROLE_DELETE file.`,
|
||||
`1. Running forEach members loop in GUILD_ROLE_DELETE file.`
|
||||
);
|
||||
// Not in the relevant guild so just skip.
|
||||
if (!member.guilds.has(guild.id)) return;
|
||||
@@ -31,7 +31,7 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
member.guilds.forEach((g) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`2. Running forEach loop in CHANNEL_DELTE file.`,
|
||||
`2. Running forEach loop in CHANNEL_DELTE file.`
|
||||
);
|
||||
// Member does not have this role
|
||||
if (!g.roles.includes(roleId)) return;
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildRoleUpdate;
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
|
||||
@@ -11,15 +11,12 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
const guild = await cacheHandlers.get(
|
||||
"guilds",
|
||||
snowflakeToBigint(payload.guildId),
|
||||
snowflakeToBigint(payload.guildId)
|
||||
);
|
||||
if (!guild) return;
|
||||
|
||||
const member = payload.member
|
||||
? await structures.createDiscordenoMember(
|
||||
payload.member,
|
||||
guild.id,
|
||||
)
|
||||
? await structures.createDiscordenoMember(payload.member, guild.id)
|
||||
: await cacheHandlers.get("members", snowflakeToBigint(payload.userId));
|
||||
if (!member) return;
|
||||
|
||||
@@ -28,27 +25,29 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
||||
|
||||
guild.voiceStates.set(
|
||||
snowflakeToBigint(payload.userId),
|
||||
await structures.createDiscordenoVoiceState(guild.id, payload),
|
||||
await structures.createDiscordenoVoiceState(guild.id, payload)
|
||||
);
|
||||
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
|
||||
if (
|
||||
cachedState?.channelId !==
|
||||
(payload.channelId ? snowflakeToBigint(payload.channelId) : null)
|
||||
(payload.channelId ? snowflakeToBigint(payload.channelId) : null)
|
||||
) {
|
||||
// Either joined or moved channels
|
||||
if (payload.channelId) {
|
||||
if (cachedState?.channelId) { // Was in a channel before
|
||||
if (cachedState?.channelId) {
|
||||
// Was in a channel before
|
||||
eventHandlers.voiceChannelSwitch?.(
|
||||
member,
|
||||
snowflakeToBigint(payload.channelId),
|
||||
cachedState.channelId,
|
||||
cachedState.channelId
|
||||
);
|
||||
} else { // Was not in a channel before so user just joined
|
||||
} else {
|
||||
// Was not in a channel before so user just joined
|
||||
eventHandlers.voiceChannelJoin?.(
|
||||
member,
|
||||
snowflakeToBigint(payload.channelId),
|
||||
snowflakeToBigint(payload.channelId)
|
||||
);
|
||||
}
|
||||
} // Left the channel
|
||||
|
||||
@@ -7,6 +7,6 @@ export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
|
||||
const options = data.d as WebhookUpdate;
|
||||
eventHandlers.webhooksUpdate?.(
|
||||
snowflakeToBigint(options.channelId),
|
||||
snowflakeToBigint(options.guildId),
|
||||
snowflakeToBigint(options.guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
export async function categoryChildren(id: bigint) {
|
||||
return await cacheHandlers.filter(
|
||||
"channels",
|
||||
(channel) => channel.parentId === id,
|
||||
(channel) => channel.parentId === id
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ export function channelOverwriteHasPermission(
|
||||
allow: bigint;
|
||||
deny: bigint;
|
||||
})[],
|
||||
permissions: PermissionStrings[],
|
||||
permissions: PermissionStrings[]
|
||||
) {
|
||||
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
||||
const overwrite =
|
||||
overwrites.find((perm) => perm.id === id) ||
|
||||
overwrites.find((perm) => perm.id === guildId);
|
||||
|
||||
if (!overwrite) return false;
|
||||
@@ -21,14 +22,10 @@ export function channelOverwriteHasPermission(
|
||||
return permissions.every((perm) => {
|
||||
const allowBits = overwrite.allow;
|
||||
const denyBits = overwrite.deny;
|
||||
if (
|
||||
BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])
|
||||
) {
|
||||
if (BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])
|
||||
) {
|
||||
if (BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,20 +26,20 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
|
||||
parentId: channelToClone.parentId
|
||||
? bigintToSnowflake(channelToClone.parentId)
|
||||
: undefined,
|
||||
permissionOverwrites: channelToClone.permissionOverwrites.map((
|
||||
overwrite,
|
||||
) => ({
|
||||
id: overwrite.id.toString(),
|
||||
type: overwrite.type,
|
||||
allow: calculatePermissions(overwrite.allow.toString()),
|
||||
deny: calculatePermissions(overwrite.deny.toString()),
|
||||
})),
|
||||
permissionOverwrites: channelToClone.permissionOverwrites.map(
|
||||
(overwrite) => ({
|
||||
id: overwrite.id.toString(),
|
||||
type: overwrite.type,
|
||||
allow: calculatePermissions(overwrite.allow.toString()),
|
||||
deny: calculatePermissions(overwrite.deny.toString()),
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
//Create the channel (also handles permissions)
|
||||
return await helpers.createChannel(
|
||||
channelToClone.guildId!,
|
||||
createChannelOptions,
|
||||
reason,
|
||||
reason
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@ import { snakelize } from "../../util/utils.ts";
|
||||
export async function createChannel(
|
||||
guildId: bigint,
|
||||
options?: CreateGuildChannel,
|
||||
reason?: string,
|
||||
reason?: string
|
||||
) {
|
||||
if (options?.permissionOverwrites) {
|
||||
await requireOverwritePermissions(
|
||||
guildId,
|
||||
options.permissionOverwrites,
|
||||
);
|
||||
await requireOverwritePermissions(guildId, options.permissionOverwrites);
|
||||
}
|
||||
|
||||
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
@@ -42,7 +39,7 @@ export async function createChannel(
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GuildText,
|
||||
reason,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
||||
|
||||
@@ -23,9 +23,7 @@ export async function createStageInstance(channelId: bigint, topic: string) {
|
||||
]);
|
||||
}
|
||||
|
||||
if (
|
||||
!validateLength(topic, { max: 120, min: 1 })
|
||||
) {
|
||||
if (!validateLength(topic, { max: 120, min: 1 })) {
|
||||
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
||||
}
|
||||
|
||||
@@ -33,8 +31,8 @@ export async function createStageInstance(channelId: bigint, topic: string) {
|
||||
"post",
|
||||
endpoints.STAGE_INSTANCES,
|
||||
{
|
||||
"channel_id": channelId,
|
||||
channel_id: channelId,
|
||||
topic,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function deleteChannel(
|
||||
channelId: bigint,
|
||||
reason?: string,
|
||||
) {
|
||||
export async function deleteChannel(channelId: bigint, reason?: string) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
if (channel?.guildId) {
|
||||
@@ -20,12 +17,12 @@ export async function deleteChannel(
|
||||
await requireBotGuildPermissions(
|
||||
guild,
|
||||
[
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPivateThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
].includes(channel.type)
|
||||
? ["MANAGE_THREADS"]
|
||||
: ["MANAGE_CHANNELS"],
|
||||
: ["MANAGE_CHANNELS"]
|
||||
);
|
||||
if (guild.rulesChannelId === channelId) {
|
||||
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
||||
@@ -39,6 +36,6 @@ export async function deleteChannel(
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.CHANNEL_BASE(channelId),
|
||||
{ reason },
|
||||
{ reason }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function deleteChannelOverwrite(
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
overwriteId: bigint
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ export async function deleteStageInstance(channelId: bigint) {
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.STAGE_INSTANCE(channelId),
|
||||
endpoints.STAGE_INSTANCE(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||
export async function editChannel(
|
||||
channelId: bigint,
|
||||
options: ModifyChannel | ModifyThread,
|
||||
reason?: string,
|
||||
reason?: string
|
||||
) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function editChannel(
|
||||
) {
|
||||
await requireOverwritePermissions(
|
||||
channel.guildId,
|
||||
options.permissionOverwrites,
|
||||
options.permissionOverwrites
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -92,16 +92,16 @@ export async function editChannel(
|
||||
...snakelize<Record<string, unknown>>(options),
|
||||
// deno-lint-ignore camelcase
|
||||
permission_overwrites: hasOwnProperty<ModifyChannel>(
|
||||
options,
|
||||
"permissionOverwrites",
|
||||
)
|
||||
options,
|
||||
"permissionOverwrites"
|
||||
)
|
||||
? options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
})
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
};
|
||||
|
||||
@@ -111,7 +111,7 @@ export async function editChannel(
|
||||
{
|
||||
...payload,
|
||||
reason,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return await structures.createDiscordenoChannel(result);
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function editChannelOverwrite(
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
options: Omit<Overwrite, "id">,
|
||||
options: Omit<Overwrite, "id">
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
@@ -22,6 +22,6 @@ export async function editChannelOverwrite(
|
||||
allow: calculateBits(options.allow),
|
||||
deny: calculateBits(options.deny),
|
||||
type: options.type,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ 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. */
|
||||
export async function followChannel(
|
||||
sourceChannelId: bigint,
|
||||
targetChannelId: bigint,
|
||||
targetChannelId: bigint
|
||||
) {
|
||||
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
@@ -15,7 +15,7 @@ export async function followChannel(
|
||||
endpoints.CHANNEL_FOLLOW(sourceChannelId),
|
||||
{
|
||||
webhook_channel_id: targetChannelId,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return data.webhookId;
|
||||
|
||||
@@ -12,18 +12,18 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getChannel(channelId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Channel>(
|
||||
"get",
|
||||
endpoints.CHANNEL_BASE(channelId),
|
||||
endpoints.CHANNEL_BASE(channelId)
|
||||
);
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||
result,
|
||||
result.guildId ? snowflakeToBigint(result.guildId) : undefined,
|
||||
result.guildId ? snowflakeToBigint(result.guildId) : undefined
|
||||
);
|
||||
if (addToCache) {
|
||||
await cacheHandlers.set(
|
||||
"channels",
|
||||
discordenoChannel.id,
|
||||
discordenoChannel,
|
||||
discordenoChannel
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,8 @@ export async function getChannelWebhooks(channelId: bigint) {
|
||||
|
||||
const result = await rest.runMethod<Webhook[]>(
|
||||
"get",
|
||||
endpoints.CHANNEL_WEBHOOKS(channelId),
|
||||
endpoints.CHANNEL_WEBHOOKS(channelId)
|
||||
);
|
||||
|
||||
return new Collection(
|
||||
result.map((webhook) => [webhook.id, webhook]),
|
||||
);
|
||||
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getChannels(guildId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Channel[]>(
|
||||
"get",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
endpoints.GUILD_CHANNELS(guildId)
|
||||
);
|
||||
|
||||
return new Collection(
|
||||
@@ -21,19 +21,19 @@ export async function getChannels(guildId: bigint, addToCache = true) {
|
||||
result.map(async (res) => {
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||
res,
|
||||
guildId,
|
||||
guildId
|
||||
);
|
||||
if (addToCache) {
|
||||
await cacheHandlers.set(
|
||||
"channels",
|
||||
discordenoChannel.id,
|
||||
discordenoChannel,
|
||||
discordenoChannel
|
||||
);
|
||||
}
|
||||
|
||||
return discordenoChannel;
|
||||
}),
|
||||
})
|
||||
)
|
||||
).map((c) => [c.id, c]),
|
||||
).map((c) => [c.id, c])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getPins(channelId: bigint) {
|
||||
const result = await rest.runMethod<Message[]>(
|
||||
"get",
|
||||
endpoints.CHANNEL_PINS(channelId),
|
||||
endpoints.CHANNEL_PINS(channelId)
|
||||
);
|
||||
|
||||
return Promise.all(
|
||||
result.map((res) => structures.createDiscordenoMessage(res)),
|
||||
result.map((res) => structures.createDiscordenoMessage(res))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ export async function getStageInstance(channelId: bigint) {
|
||||
|
||||
return await rest.runMethod<StageInstance>(
|
||||
"get",
|
||||
endpoints.STAGE_INSTANCE(channelId),
|
||||
endpoints.STAGE_INSTANCE(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function isChannelSynced(channelId: bigint) {
|
||||
|
||||
return channel.permissionOverwrites?.every((overwrite) => {
|
||||
const permission = parentChannel.permissionOverwrites?.find(
|
||||
(ow) => ow.id === overwrite.id,
|
||||
(ow) => ow.id === overwrite.id
|
||||
);
|
||||
if (!permission) return false;
|
||||
return !(
|
||||
|
||||
@@ -27,19 +27,16 @@ export async function startTyping(channelId: bigint) {
|
||||
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
||||
}
|
||||
|
||||
const hasSendMessagesPerm = await botHasChannelPermissions(
|
||||
channelId,
|
||||
["SEND_MESSAGES"],
|
||||
);
|
||||
if (
|
||||
!hasSendMessagesPerm
|
||||
) {
|
||||
const hasSendMessagesPerm = await botHasChannelPermissions(channelId, [
|
||||
"SEND_MESSAGES",
|
||||
]);
|
||||
if (!hasSendMessagesPerm) {
|
||||
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
"post",
|
||||
endpoints.CHANNEL_TYPING(channelId),
|
||||
endpoints.CHANNEL_TYPING(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||
export async function swapChannels(
|
||||
guildId: bigint,
|
||||
channelPositions: ModifyGuildChannelPositions[],
|
||||
channelPositions: ModifyGuildChannelPositions[]
|
||||
) {
|
||||
if (channelPositions.length < 2) {
|
||||
throw "You must provide at least two channels to be swapped.";
|
||||
@@ -14,6 +14,6 @@ export async function swapChannels(
|
||||
return await rest.runMethod<undefined>(
|
||||
"patch",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
channelPositions,
|
||||
channelPositions
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ export async function addToThread(channelId: bigint, userId?: bigint) {
|
||||
"put",
|
||||
userId
|
||||
? endpoints.THREAD_USER(channelId, userId)
|
||||
: endpoints.THREAD_ME(channelId),
|
||||
: endpoints.THREAD_ME(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,5 @@ import { endpoints } from "../../../util/constants.ts";
|
||||
export async function getActiveThreads(channelId: bigint) {
|
||||
// TODO(threads): perm check
|
||||
// TODO(threads): test if it works
|
||||
return await rest.runMethod(
|
||||
"get",
|
||||
endpoints.THREAD_ACTIVE(channelId),
|
||||
);
|
||||
return await rest.runMethod("get", endpoints.THREAD_ACTIVE(channelId));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function getArchivedThreads(
|
||||
channelId: bigint,
|
||||
options?: ListPublicArchivedThreads & {
|
||||
type?: "public" | "private" | "privateJoinedThreads";
|
||||
},
|
||||
}
|
||||
) {
|
||||
// TODO(threads): perm check
|
||||
// TODO(threads): check if this works
|
||||
@@ -19,6 +19,6 @@ export async function getArchivedThreads(
|
||||
: options?.type === "private"
|
||||
? endpoints.THREAD_ARCHIVED_PRIVATE(channelId)
|
||||
: endpoints.THREAD_ARCHIVED_PUBLIC(channelId),
|
||||
snakelize(options ?? {}),
|
||||
snakelize(options ?? {})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) {
|
||||
"delete",
|
||||
userId
|
||||
? endpoints.THREAD_USER(channelId, userId)
|
||||
: endpoints.THREAD_ME(channelId),
|
||||
: endpoints.THREAD_ME(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { snakelize } from "../../../util/utils.ts";
|
||||
*/
|
||||
export async function startThread(
|
||||
channelId: bigint,
|
||||
options: StartThread & { messageId?: bigint },
|
||||
options: StartThread & { messageId?: bigint }
|
||||
) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (channel) {
|
||||
@@ -33,6 +33,6 @@ export async function startThread(
|
||||
options?.messageId
|
||||
? endpoints.THREAD_START_PUBLIC(channelId, options.messageId)
|
||||
: endpoints.THREAD_START_PRIVATE(channelId),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
|
||||
endpoints.STAGE_INSTANCE(channelId),
|
||||
{
|
||||
topic,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts";
|
||||
import type {
|
||||
UpdateSelfVoiceState,
|
||||
} from "../../types/guilds/update_self_voice_state.ts";
|
||||
import type { UpdateSelfVoiceState } from "../../types/guilds/update_self_voice_state.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||
|
||||
@@ -19,14 +17,14 @@ import { hasOwnProperty, snakelize } from "../../util/utils.ts";
|
||||
*/
|
||||
export async function updateBotVoiceState(
|
||||
guildId: bigint,
|
||||
options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState,
|
||||
options: UpdateSelfVoiceState | ({ userId: bigint } & UpdateOthersVoiceState)
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.UPDATE_VOICE_STATE(
|
||||
guildId,
|
||||
hasOwnProperty(options, "userId") ? options.userId : undefined,
|
||||
hasOwnProperty(options, "userId") ? options.userId : undefined
|
||||
),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type {
|
||||
AddGuildDiscoverySubcategory,
|
||||
} from "../../types/discovery/add_guild_discovery_subcategory.ts";
|
||||
import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function addDiscoverySubcategory(
|
||||
guildId: bigint,
|
||||
categoryId: number,
|
||||
categoryId: number
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<AddGuildDiscoverySubcategory>(
|
||||
"post",
|
||||
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId),
|
||||
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import { snakelize } from "../../util/utils.ts";
|
||||
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
|
||||
export async function editDiscovery(
|
||||
guildId: bigint,
|
||||
data: ModifyGuildDiscoveryMetadata,
|
||||
data: ModifyGuildDiscoveryMetadata
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<DiscoveryMetadata>(
|
||||
"patch",
|
||||
endpoints.DISCOVERY_MODIFY(guildId),
|
||||
snakelize(data),
|
||||
snakelize(data)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getDiscoveryCategories() {
|
||||
const result = await rest.runMethod<DiscoveryCategory[]>(
|
||||
"get",
|
||||
endpoints.DISCOVERY_CATEGORIES,
|
||||
endpoints.DISCOVERY_CATEGORIES
|
||||
);
|
||||
|
||||
return new Collection<number, DiscoveryCategory>(
|
||||
result.map(
|
||||
(category) => [category.id, category],
|
||||
),
|
||||
result.map((category) => [category.id, category])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ 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. */
|
||||
export async function removeDiscoverySubcategory(
|
||||
guildId: bigint,
|
||||
categoryId: number,
|
||||
categoryId: number
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId),
|
||||
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function validDiscoveryTerm(term: string) {
|
||||
const result = await rest.runMethod<ValidateDiscoverySearchTerm>(
|
||||
"get",
|
||||
endpoints.DISCOVERY_VALID_TERM,
|
||||
{ term },
|
||||
{ term }
|
||||
);
|
||||
|
||||
return result.valid;
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function createEmoji(
|
||||
guildId: bigint,
|
||||
name: string,
|
||||
image: string,
|
||||
options: CreateGuildEmoji,
|
||||
options: CreateGuildEmoji
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function createEmoji(
|
||||
...options,
|
||||
name,
|
||||
image,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -6,13 +6,13 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function deleteEmoji(
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
reason?: string,
|
||||
reason?: string
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILD_EMOJI(guildId, id),
|
||||
{ reason },
|
||||
{ reason }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function editEmoji(
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options: ModifyGuildEmoji,
|
||||
options: ModifyGuildEmoji
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||
|
||||
@@ -18,6 +18,6 @@ export async function editEmoji(
|
||||
{
|
||||
name: options.name,
|
||||
roles: options.roles,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,22 +12,18 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getEmoji(
|
||||
guildId: bigint,
|
||||
emojiId: bigint,
|
||||
addToCache = true,
|
||||
addToCache = true
|
||||
) {
|
||||
const result = await rest.runMethod<Emoji>(
|
||||
"get",
|
||||
endpoints.GUILD_EMOJI(guildId, emojiId),
|
||||
endpoints.GUILD_EMOJI(guildId, emojiId)
|
||||
);
|
||||
|
||||
if (addToCache) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
guild.emojis.set(emojiId, result);
|
||||
await cacheHandlers.set(
|
||||
"guilds",
|
||||
guildId,
|
||||
guild,
|
||||
);
|
||||
await cacheHandlers.set("guilds", guildId, guild);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -15,7 +15,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getEmojis(guildId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Emoji[]>(
|
||||
"get",
|
||||
endpoints.GUILD_EMOJIS(guildId),
|
||||
endpoints.GUILD_EMOJIS(guildId)
|
||||
);
|
||||
|
||||
if (addToCache) {
|
||||
@@ -23,10 +23,7 @@ export async function getEmojis(guildId: bigint, addToCache = true) {
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
result.forEach((emoji) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach loop in get_emojis file.`,
|
||||
);
|
||||
eventHandlers.debug?.("loop", `Running forEach loop in get_emojis file.`);
|
||||
guild.emojis.set(snowflakeToBigint(emoji.id!), emoji);
|
||||
});
|
||||
|
||||
|
||||
@@ -9,11 +9,7 @@ import { getMember } from "../members/get_member.ts";
|
||||
|
||||
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
|
||||
export async function createGuild(options: CreateGuild) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"post",
|
||||
endpoints.GUILDS,
|
||||
options,
|
||||
);
|
||||
const result = await rest.runMethod<Guild>("post", endpoints.GUILDS, options);
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(result, 0);
|
||||
// MANUALLY CACHE THE GUILD
|
||||
|
||||
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function deleteGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
endpoints.GUILDS_BASE(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"patch",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
options,
|
||||
options
|
||||
);
|
||||
|
||||
const cached = await cacheHandlers.get("guilds", guildId);
|
||||
@@ -35,8 +35,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
||||
result,
|
||||
cached?.shardId ||
|
||||
Number(
|
||||
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards))
|
||||
.toString(),
|
||||
),
|
||||
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
export async function editWelcomeScreen(
|
||||
guildId: bigint,
|
||||
options: ModifyGuildWelcomeScreen,
|
||||
options: ModifyGuildWelcomeScreen
|
||||
) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"patch",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function editWidget(
|
||||
guildId: bigint,
|
||||
enabled: boolean,
|
||||
channelId?: string | null,
|
||||
channelId?: string | null
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
@@ -17,6 +17,6 @@ export async function editWidget(
|
||||
{
|
||||
enabled,
|
||||
channel_id: channelId,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(
|
||||
guildId: bigint,
|
||||
options: GetGuildAuditLog,
|
||||
) {
|
||||
export async function getAuditLogs(guildId: bigint, options: GetGuildAuditLog) {
|
||||
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
return await rest.runMethod<AuditLog>(
|
||||
@@ -17,9 +14,10 @@ export async function getAuditLogs(
|
||||
endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
snakelize({
|
||||
...options,
|
||||
limit: options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
: 50,
|
||||
}),
|
||||
limit:
|
||||
options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
: 50,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ export async function getBan(guildId: bigint, memberId: bigint) {
|
||||
|
||||
return await rest.runMethod<Ban>(
|
||||
"get",
|
||||
endpoints.GUILD_BAN(guildId, memberId),
|
||||
endpoints.GUILD_BAN(guildId, memberId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ export async function getBans(guildId: bigint) {
|
||||
|
||||
const results = await rest.runMethod<Ban[]>(
|
||||
"get",
|
||||
endpoints.GUILD_BANS(guildId),
|
||||
endpoints.GUILD_BANS(guildId)
|
||||
);
|
||||
|
||||
return new Collection<bigint, Ban>(
|
||||
results.map((res) => [snowflakeToBigint(res.user.id), res]),
|
||||
results.map((res) => [snowflakeToBigint(res.user.id), res])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,19 +17,19 @@ export async function getGuild(
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
},
|
||||
}
|
||||
) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"get",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
{
|
||||
with_counts: options.counts,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
|
||||
@@ -6,6 +6,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getGuildPreview(guildId: bigint) {
|
||||
return await rest.runMethod<GuildPreview>(
|
||||
"get",
|
||||
endpoints.GUILD_PREVIEW(guildId),
|
||||
endpoints.GUILD_PREVIEW(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { snakelize } from "../../util/utils.ts";
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
export async function getPruneCount(
|
||||
guildId: bigint,
|
||||
options?: GetGuildPruneCountQuery,
|
||||
options?: GetGuildPruneCountQuery
|
||||
) {
|
||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||
if (options?.days && options.days > 30) {
|
||||
@@ -20,7 +20,7 @@ export async function getPruneCount(
|
||||
const result = await rest.runMethod(
|
||||
"get",
|
||||
endpoints.GUILD_PRUNE(guildId),
|
||||
snakelize(options ?? {}),
|
||||
snakelize(options ?? {})
|
||||
);
|
||||
|
||||
return result.pruned as number;
|
||||
|
||||
@@ -5,11 +5,9 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function getVanityURL(guildId: bigint) {
|
||||
return await rest.runMethod<
|
||||
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
|
||||
code: null;
|
||||
}
|
||||
>(
|
||||
"get",
|
||||
endpoints.GUILD_VANITY_URL(guildId),
|
||||
);
|
||||
| (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
|
||||
| {
|
||||
code: null;
|
||||
}
|
||||
>("get", endpoints.GUILD_VANITY_URL(guildId));
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getVoiceRegions(guildId: bigint) {
|
||||
const result = await rest.runMethod<VoiceRegion[]>(
|
||||
"get",
|
||||
endpoints.GUILD_REGIONS(guildId),
|
||||
endpoints.GUILD_REGIONS(guildId)
|
||||
);
|
||||
|
||||
return new Collection<string, VoiceRegion>(
|
||||
result.map((region) => [region.id, region]),
|
||||
result.map((region) => [region.id, region])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getWelcomeScreen(guildId: bigint) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"get",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@ export async function getWidget(guildId: bigint, options?: { force: boolean }) {
|
||||
|
||||
return await rest.runMethod<GuildWidgetDetails>(
|
||||
"get",
|
||||
`${endpoints.GUILD_WIDGET(guildId)}.json`,
|
||||
`${endpoints.GUILD_WIDGET(guildId)}.json`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** Returns the widget image URL for the guild. */
|
||||
export async function getWidgetImageURL(
|
||||
guildId: bigint,
|
||||
options?: GetGuildWidgetImageQuery & { force?: boolean },
|
||||
options?: GetGuildWidgetImageQuery & { force?: boolean }
|
||||
) {
|
||||
if (!options?.force) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
@@ -14,6 +14,7 @@ export async function getWidgetImageURL(
|
||||
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
}
|
||||
|
||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ??
|
||||
"shield"}`;
|
||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${
|
||||
options?.style ?? "shield"
|
||||
}`;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user