Prettified Code!

This commit is contained in:
itohatweb
2021-05-21 15:51:33 +00:00
committed by GitHub Action
parent fe4ab8517b
commit 3549cdeb63
279 changed files with 1617 additions and 1768 deletions
+5 -10
View File
@@ -20,21 +20,16 @@ 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, (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
next, 0
) => (bits |= typeof next === "string"
? DiscordGatewayIntents[next]
: next),
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 === 1 ws.lastShardId =
? ws.botGatewayData.shards - 1 ws.lastShardId === 1 ? ws.botGatewayData.shards - 1 : ws.lastShardId;
: 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`;
+31 -31
View File
@@ -26,7 +26,7 @@ export const cache = {
( (
value: value:
| Collection<bigint, DiscordenoMember> | Collection<bigint, DiscordenoMember>
| PromiseLike<Collection<bigint, DiscordenoMember>>, | PromiseLike<Collection<bigint, DiscordenoMember>>
) => void ) => void
>(), >(),
executedSlashCommands: new Set<string>(), executedSlashCommands: new Set<string>(),
@@ -34,8 +34,8 @@ export const cache = {
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])], (a, b) => [...a, ...b.emojis.map((e) => [e.id, e])],
[] as any[], [] as any[]
), )
); );
}, },
}; };
@@ -81,32 +81,32 @@ export type TableName =
function set( function set(
table: "guilds", table: "guilds",
key: bigint, key: bigint,
value: DiscordenoGuild, value: DiscordenoGuild
): Promise<Collection<bigint, DiscordenoGuild>>; ): Promise<Collection<bigint, DiscordenoGuild>>;
function set( function set(
table: "channels", table: "channels",
key: bigint, key: bigint,
value: DiscordenoChannel, value: DiscordenoChannel
): Promise<Collection<bigint, DiscordenoChannel>>; ): Promise<Collection<bigint, DiscordenoChannel>>;
function set( function set(
table: "messages", table: "messages",
key: bigint, key: bigint,
value: DiscordenoMessage, value: DiscordenoMessage
): Promise<Collection<bigint, DiscordenoMessage>>; ): Promise<Collection<bigint, DiscordenoMessage>>;
function set( function set(
table: "members", table: "members",
key: bigint, key: bigint,
value: DiscordenoMember, value: DiscordenoMember
): Promise<Collection<bigint, DiscordenoMember>>; ): Promise<Collection<bigint, DiscordenoMember>>;
function set( function set(
table: "presences", table: "presences",
key: bigint, key: bigint,
value: PresenceUpdate, value: PresenceUpdate
): Promise<Collection<bigint, PresenceUpdate>>; ): Promise<Collection<bigint, PresenceUpdate>>;
function set( function set(
table: "unavailableGuilds", table: "unavailableGuilds",
key: bigint, key: bigint,
value: number, value: number
): Promise<Collection<bigint, 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);
@@ -114,27 +114,27 @@ async function set(table: TableName, key: bigint, value: any) {
function get( function get(
table: "guilds", table: "guilds",
key: bigint, key: bigint
): Promise<DiscordenoGuild | undefined>; ): Promise<DiscordenoGuild | undefined>;
function get( function get(
table: "channels", table: "channels",
key: bigint, key: bigint
): Promise<DiscordenoChannel | undefined>; ): Promise<DiscordenoChannel | undefined>;
function get( function get(
table: "messages", table: "messages",
key: bigint, key: bigint
): Promise<DiscordenoMessage | undefined>; ): Promise<DiscordenoMessage | undefined>;
function get( function get(
table: "members", table: "members",
key: bigint, key: bigint
): Promise<DiscordenoMember | undefined>; ): Promise<DiscordenoMember | undefined>;
function get( function get(
table: "presences", table: "presences",
key: bigint, key: bigint
): Promise<PresenceUpdate | undefined>; ): Promise<PresenceUpdate | undefined>;
function get( function get(
table: "unavailableGuilds", table: "unavailableGuilds",
key: bigint, key: bigint
): Promise<number | undefined>; ): 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);
@@ -145,67 +145,67 @@ function forEach(
callback: ( callback: (
value: DiscordenoGuild, value: DiscordenoGuild,
key: bigint, key: bigint,
map: Map<bigint, DiscordenoGuild>, map: Map<bigint, DiscordenoGuild>
) => unknown, ) => unknown
): void; ): void;
function forEach( function forEach(
table: "unavailableGuilds", table: "unavailableGuilds",
callback: (value: number, key: bigint, map: Map<bigint, number>) => unknown, callback: (value: number, key: bigint, map: Map<bigint, number>) => unknown
): void; ): void;
function forEach( function forEach(
table: "channels", table: "channels",
callback: ( callback: (
value: DiscordenoChannel, value: DiscordenoChannel,
key: bigint, key: bigint,
map: Map<bigint, DiscordenoChannel>, map: Map<bigint, DiscordenoChannel>
) => unknown, ) => unknown
): void; ): void;
function forEach( function forEach(
table: "messages", table: "messages",
callback: ( callback: (
value: DiscordenoMessage, value: DiscordenoMessage,
key: bigint, key: bigint,
map: Map<bigint, DiscordenoMessage>, map: Map<bigint, DiscordenoMessage>
) => unknown, ) => unknown
): void; ): void;
function forEach( function forEach(
table: "members", table: "members",
callback: ( callback: (
value: DiscordenoMember, value: DiscordenoMember,
key: bigint, key: bigint,
map: Map<bigint, DiscordenoMember>, map: Map<bigint, DiscordenoMember>
) => unknown, ) => unknown
): void; ): void;
function forEach( function forEach(
table: TableName, 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); return cache[table].forEach(callback);
} }
function filter( function filter(
table: "guilds", table: "guilds",
callback: (value: DiscordenoGuild, key: bigint) => boolean, callback: (value: DiscordenoGuild, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoGuild>>; ): Promise<Collection<bigint, DiscordenoGuild>>;
function filter( function filter(
table: "unavailableGuilds", table: "unavailableGuilds",
callback: (value: number, key: bigint) => boolean, callback: (value: number, key: bigint) => boolean
): Promise<Collection<bigint, number>>; ): Promise<Collection<bigint, number>>;
function filter( function filter(
table: "channels", table: "channels",
callback: (value: DiscordenoChannel, key: bigint) => boolean, callback: (value: DiscordenoChannel, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoChannel>>; ): Promise<Collection<bigint, DiscordenoChannel>>;
function filter( function filter(
table: "messages", table: "messages",
callback: (value: DiscordenoMessage, key: bigint) => boolean, callback: (value: DiscordenoMessage, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoMessage>>; ): Promise<Collection<bigint, DiscordenoMessage>>;
function filter( 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, table: TableName,
callback: (value: any, key: bigint) => boolean, callback: (value: any, key: bigint) => boolean
) { ) {
return cache[table].filter(callback); return cache[table].filter(callback);
} }
+8 -5
View File
@@ -10,17 +10,19 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
const cachedChannel = await cacheHandlers.get( const cachedChannel = await cacheHandlers.get(
"channels", "channels",
snowflakeToBigint(payload.id), 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) {
return Promise.all(guild.voiceStates.map(async (vs, key) => { return Promise.all(
guild.voiceStates.map(async (vs, key) => {
if (vs.channelId !== cachedChannel.id) return; if (vs.channelId !== cachedChannel.id) return;
// Since this channel was deleted all voice states for this channel should be deleted // Since this channel was deleted all voice states for this channel should be deleted
@@ -30,7 +32,8 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
if (!member) return; 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) => { cacheHandlers.forEach("messages", (message) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`Running forEach messages loop in CHANNEL_DELTE file.`, `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);
+1 -1
View File
@@ -9,7 +9,7 @@ export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
const channel = await cacheHandlers.get( const channel = await cacheHandlers.get(
"channels", "channels",
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
if (!channel) return; if (!channel) return;
+1 -1
View File
@@ -9,7 +9,7 @@ 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", "channels",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!cachedChannel) return; if (!cachedChannel) return;
+2 -2
View File
@@ -9,7 +9,7 @@ export async function handleThreadDelete(data: DiscordGatewayPayload) {
const cachedChannel = await cacheHandlers.get( const cachedChannel = await cacheHandlers.get(
"channels", "channels",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!cachedChannel) return; if (!cachedChannel) return;
@@ -17,7 +17,7 @@ export async function handleThreadDelete(data: DiscordGatewayPayload) {
cacheHandlers.forEach("messages", (message) => { cacheHandlers.forEach("messages", (message) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`Running forEach messages loop in CHANNEL_DELTE file.`, `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);
+5 -5
View File
@@ -14,26 +14,26 @@ export async function handleThreadListSync(data: DiscordGatewayPayload) {
payload.threads.map(async (thread) => { payload.threads.map(async (thread) => {
const discordenoChannel = await structures.createDiscordenoChannel( const discordenoChannel = await structures.createDiscordenoChannel(
thread, thread,
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
await cacheHandlers.set( await cacheHandlers.set(
"channels", "channels",
discordenoChannel.id, discordenoChannel.id,
discordenoChannel, 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, threads,
payload.members, 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 payload = data.d as ThreadMembersUpdate;
const thread = await cacheHandlers.get( const thread = await cacheHandlers.get(
"channels", "channels",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!thread) return; if (!thread) return;
@@ -8,7 +8,7 @@ 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", "channels",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!thread) return; if (!thread) return;
+1 -1
View File
@@ -9,7 +9,7 @@ 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", "channels",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!oldChannel) return; if (!oldChannel) return;
@@ -1,13 +1,9 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
ApplicationCommandCreateUpdateDelete,
} from "../../types/interactions/commands/application_command_create_update_delete.ts";
export function handleApplicationCommandCreate( export function handleApplicationCommandCreate(data: DiscordGatewayPayload) {
data: DiscordGatewayPayload,
) {
eventHandlers.applicationCommandCreate?.( eventHandlers.applicationCommandCreate?.(
data.d as ApplicationCommandCreateUpdateDelete, data.d as ApplicationCommandCreateUpdateDelete
); );
} }
@@ -1,11 +1,9 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
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
); );
} }
@@ -1,11 +1,9 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { ApplicationCommandCreateUpdateDelete } from "../../types/interactions/commands/application_command_create_update_delete.ts";
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
); );
} }
+3 -7
View File
@@ -9,20 +9,16 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), 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);
eventHandlers.guildEmojisUpdate?.( eventHandlers.guildEmojisUpdate?.(guild, guild.emojis, cachedEmojis);
guild,
guild.emojis,
cachedEmojis,
);
} }
+2 -2
View File
@@ -8,13 +8,13 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
const member = await cacheHandlers.get( const member = await cacheHandlers.get(
"members", "members",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id)
); );
eventHandlers.guildBanAdd?.(guild, payload.user, member); eventHandlers.guildBanAdd?.(guild, payload.user, member);
} }
+2 -2
View File
@@ -8,13 +8,13 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
const member = await cacheHandlers.get( const member = await cacheHandlers.get(
"members", "members",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id)
); );
eventHandlers.guildBanRemove?.(guild, payload.user, member); eventHandlers.guildBanRemove?.(guild, payload.user, member);
} }
+2 -5
View File
@@ -8,16 +8,13 @@ import { ws } from "../../ws/ws.ts";
export async function handleGuildCreate( export async function handleGuildCreate(
data: DiscordGatewayPayload, data: DiscordGatewayPayload,
shardId: number, 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;
const guild = await structures.createDiscordenoGuild( const guild = await structures.createDiscordenoGuild(payload, shardId);
payload,
shardId,
);
await cacheHandlers.set("guilds", guild.id, guild); await cacheHandlers.set("guilds", guild.id, guild);
const shard = ws.shards.get(shardId); const shard = ws.shards.get(shardId);
+5 -5
View File
@@ -7,13 +7,13 @@ import { ws } from "../../ws/ws.ts";
export async function handleGuildDelete( export async function handleGuildDelete(
data: DiscordGatewayPayload, data: DiscordGatewayPayload,
shardId: number, 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", "guilds",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!guild) return; if (!guild) return;
@@ -32,7 +32,7 @@ export async function handleGuildDelete(
cacheHandlers.forEach("messages", (message) => { cacheHandlers.forEach("messages", (message) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`1. Running forEach messages loop in CHANNEL_DELTE file.`, `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);
@@ -42,7 +42,7 @@ export async function handleGuildDelete(
cacheHandlers.forEach("channels", (channel) => { cacheHandlers.forEach("channels", (channel) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`2. Running forEach channels loop in CHANNEL_DELTE file.`, `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);
@@ -52,7 +52,7 @@ export async function handleGuildDelete(
cacheHandlers.forEach("members", (member) => { cacheHandlers.forEach("members", (member) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "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; 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"; 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
+4 -3
View File
@@ -8,12 +8,12 @@ import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildUpdate( export async function handleGuildUpdate(
data: DiscordGatewayPayload, data: DiscordGatewayPayload,
shardId: number, 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", "guilds",
snowflakeToBigint(payload.id), snowflakeToBigint(payload.id)
); );
if (!oldGuild) return; if (!oldGuild) return;
@@ -40,7 +40,8 @@ export async function handleGuildUpdate(
if (!cachedValue && !value) return; if (!cachedValue && !value) return;
if (Array.isArray(cachedValue) && Array.isArray(value)) { if (Array.isArray(cachedValue) && Array.isArray(value)) {
const different = cachedValue.length !== value.length || const different =
cachedValue.length !== value.length ||
cachedValue.find((val) => !value.includes(val)) || cachedValue.find((val) => !value.includes(val)) ||
value.find((val) => !cachedValue.includes(val)); value.find((val) => !cachedValue.includes(val));
if (!different) return; if (!different) return;
@@ -1,13 +1,7 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { IntegrationCreateUpdate } from "../../types/integrations/integration_create_update.ts";
IntegrationCreateUpdate,
} from "../../types/integrations/integration_create_update.ts";
export function handleIntegrationCreate( export function handleIntegrationCreate(data: DiscordGatewayPayload) {
data: DiscordGatewayPayload, eventHandlers.integrationCreate?.(data.d as IntegrationCreateUpdate);
) {
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"; import type { IntegrationDelete } from "../../types/integrations/integration_delete.ts";
export function handleIntegrationDelete(data: DiscordGatewayPayload) { export function handleIntegrationDelete(data: DiscordGatewayPayload) {
eventHandlers.integrationDelete?.( eventHandlers.integrationDelete?.(data.d as IntegrationDelete);
data.d as IntegrationDelete,
);
} }
@@ -1,11 +1,7 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { IntegrationCreateUpdate } from "../../types/integrations/integration_create_update.ts";
IntegrationCreateUpdate,
} from "../../types/integrations/integration_create_update.ts";
export function handleIntegrationUpdate(data: DiscordGatewayPayload) { export function handleIntegrationUpdate(data: DiscordGatewayPayload) {
eventHandlers.integrationUpdate?.( eventHandlers.integrationUpdate?.(data.d as IntegrationCreateUpdate);
data.d as IntegrationCreateUpdate,
);
} }
@@ -11,7 +11,7 @@ export async function handleInteractionCreate(data: DiscordGatewayPayload) {
const discordenoMember = payload.guildId const discordenoMember = payload.guildId
? await structures.createDiscordenoMember( ? await structures.createDiscordenoMember(
payload.member as GuildMemberWithUser, payload.member as GuildMemberWithUser,
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
) )
: undefined; : undefined;
if (discordenoMember) { if (discordenoMember) {
+1 -3
View File
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
import type { InviteCreate } from "../../types/invites/invite_create.ts"; import type { InviteCreate } from "../../types/invites/invite_create.ts";
export function handleInviteCreate(data: DiscordGatewayPayload) { export function handleInviteCreate(data: DiscordGatewayPayload) {
eventHandlers.inviteCreate?.( eventHandlers.inviteCreate?.(data.d as InviteCreate);
data.d as InviteCreate,
);
} }
+1 -3
View File
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
import type { InviteDelete } from "../../types/invites/invite_delete.ts"; import type { InviteDelete } from "../../types/invites/invite_delete.ts";
export function handleInviteDelete(data: DiscordGatewayPayload) { export function handleInviteDelete(data: DiscordGatewayPayload) {
eventHandlers.inviteDelete?.( eventHandlers.inviteDelete?.(data.d as InviteDelete);
data.d as InviteDelete,
);
} }
+4 -9
View File
@@ -14,18 +14,16 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
payload.members.map(async (member) => { payload.members.map(async (member) => {
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
member, member,
guildId, guildId
); );
await cacheHandlers.set("members", discordenoMember.id, discordenoMember); await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
return discordenoMember; return discordenoMember;
}), })
); );
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming // Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
if ( if (payload.nonce) {
payload.nonce
) {
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce); const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
if (!resolve) return; if (!resolve) return;
@@ -37,10 +35,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
} }
return resolve( return resolve(
await cacheHandlers.filter( await cacheHandlers.filter("members", (m) => m.guilds.has(guildId))
"members",
(m) => m.guilds.has(guildId),
),
); );
} }
} }
+2 -2
View File
@@ -9,14 +9,14 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
guild.memberCount++; guild.memberCount++;
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
payload, payload,
guild.id, guild.id
); );
await cacheHandlers.set("members", discordenoMember.id, discordenoMember); await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
+2 -2
View File
@@ -8,14 +8,14 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
guild.memberCount--; guild.memberCount--;
const member = await cacheHandlers.get( const member = await cacheHandlers.get(
"members", "members",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id)
); );
eventHandlers.guildMemberRemove?.(guild, payload.user, member); eventHandlers.guildMemberRemove?.(guild, payload.user, member);
+8 -9
View File
@@ -9,28 +9,27 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
const cachedMember = await cacheHandlers.get( const cachedMember = await cacheHandlers.get(
"members", "members",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id)
); );
const guildMember = cachedMember?.guilds.get(guild.id); const guildMember = cachedMember?.guilds.get(guild.id);
const newMemberData = { const newMemberData = {
...payload, ...payload,
premiumSince: payload.premiumSince || undefined, premiumSince: payload.premiumSince || undefined,
joinedAt: new Date(guildMember?.joinedAt || Date.now()) joinedAt: new Date(guildMember?.joinedAt || Date.now()).toISOString(),
.toISOString(),
deaf: guildMember?.deaf || false, deaf: guildMember?.deaf || false,
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, newMemberData,
guild.id, guild.id
); );
await cacheHandlers.set("members", discordenoMember.id, discordenoMember); await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
@@ -40,7 +39,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
guild, guild,
discordenoMember, discordenoMember,
payload.nick!, payload.nick!,
guildMember.nick ?? undefined, guildMember.nick ?? undefined
); );
} }
@@ -53,7 +52,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
roleIds.forEach((id) => { roleIds.forEach((id) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "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))) { if (!payload.roles.includes(bigintToSnowflake(id))) {
eventHandlers.roleLost?.(guild, discordenoMember, id); eventHandlers.roleLost?.(guild, discordenoMember, id);
@@ -63,13 +62,13 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
payload.roles.forEach((id) => { payload.roles.forEach((id) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`2. Running forEach loop in GUILD_MEMBER_UPDATE file.`, `2. Running forEach loop in GUILD_MEMBER_UPDATE file.`
); );
if (!roleIds.includes(snowflakeToBigint(id))) { if (!roleIds.includes(snowflakeToBigint(id))) {
eventHandlers.roleGained?.( eventHandlers.roleGained?.(
guild, guild,
discordenoMember, discordenoMember,
snowflakeToBigint(id), snowflakeToBigint(id)
); );
} }
}); });
+9 -9
View File
@@ -10,7 +10,7 @@ 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", "channels",
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
if (channel) channel.lastMessageId = snowflakeToBigint(payload.id); 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 // If in a guild cache the author as a member
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
{ ...payload.member, user: payload.author } as GuildMemberWithUser, { ...payload.member, user: payload.author } as GuildMemberWithUser,
guild.id, guild.id
); );
await cacheHandlers.set("members", discordenoMember.id, discordenoMember); await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
} }
if (payload.mentions && guild) { if (payload.mentions && guild) {
await Promise.all(payload.mentions.map(async (mention) => { await Promise.all(
payload.mentions.map(async (mention) => {
// Cache the member if its a valid member // Cache the member if its a valid member
if (mention.member) { if (mention.member) {
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
{ ...mention.member, user: mention } as GuildMemberWithUser, { ...mention.member, user: mention } as GuildMemberWithUser,
guild.id, guild.id
); );
return cacheHandlers.set( return cacheHandlers.set(
"members", "members",
snowflakeToBigint(mention.id), snowflakeToBigint(mention.id),
discordenoMember, discordenoMember
); );
} }
})); })
);
} }
const message = await structures.createDiscordenoMessage( const message = await structures.createDiscordenoMessage(data.d as Message);
data.d as Message,
);
// Cache the message // Cache the message
await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message); await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message);
+2 -2
View File
@@ -8,13 +8,13 @@ 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", "channels",
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
if (!channel) return; if (!channel) return;
eventHandlers.messageDelete?.( eventHandlers.messageDelete?.(
{ id: payload.id, channel }, { 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)); await cacheHandlers.delete("messages", snowflakeToBigint(payload.id));
+6 -4
View File
@@ -8,15 +8,17 @@ 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", "channels",
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
if (!channel) return; if (!channel) return;
return Promise.all(payload.ids.map(async (id) => { return Promise.all(
payload.ids.map(async (id) => {
eventHandlers.messageDelete?.( eventHandlers.messageDelete?.(
{ id, channel }, { id, channel },
await cacheHandlers.get("messages", snowflakeToBigint(id)), await cacheHandlers.get("messages", snowflakeToBigint(id))
); );
await cacheHandlers.delete("messages", snowflakeToBigint(id)); await cacheHandlers.delete("messages", snowflakeToBigint(id));
})); })
);
} }
+7 -12
View File
@@ -2,23 +2,21 @@ import { botId, eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { MessageReactionAdd } from "../../types/messages/message_reaction_add.ts";
MessageReactionAdd,
} from "../../types/messages/message_reaction_add.ts";
import { snowflakeToBigint } from "../../util/bigint.ts"; 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", "messages",
snowflakeToBigint(payload.messageId), 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.id === payload.emoji.id &&
reaction.emoji.name === payload.emoji.name, reaction.emoji.name === payload.emoji.name
); );
if (reactionExisted) reactionExisted.count++; if (reactionExisted) reactionExisted.count++;
@@ -36,26 +34,23 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
await cacheHandlers.set( await cacheHandlers.set(
"messages", "messages",
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId),
message, message
); );
} }
if (payload.member && payload.guildId) { if (payload.member && payload.guildId) {
const guild = await cacheHandlers.get( const guild = await cacheHandlers.get(
"guilds", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (guild) { if (guild) {
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
payload.member, payload.member,
guild.id, guild.id
); );
await cacheHandlers.set("members", discordenoMember.id, discordenoMember); await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
} }
} }
eventHandlers.reactionAdd?.( eventHandlers.reactionAdd?.(payload, message);
payload,
message,
);
} }
@@ -1,22 +1,19 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { MessageReactionRemove } from "../../types/messages/message_reaction_remove.ts";
MessageReactionRemove,
} from "../../types/messages/message_reaction_remove.ts";
import { snowflakeToBigint } from "../../util/bigint.ts"; import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageReactionRemove( export async function handleMessageReactionRemove(data: DiscordGatewayPayload) {
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", "messages",
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId)
); );
if (message) { if (message) {
const reaction = message.reactions?.find((reaction) => const reaction = message.reactions?.find(
(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
@@ -33,8 +30,5 @@ export async function handleMessageReactionRemove(
} }
} }
eventHandlers.reactionRemove?.( eventHandlers.reactionRemove?.(payload, message);
payload,
message,
);
} }
@@ -1,18 +1,16 @@
import { eventHandlers } from "../../bot.ts"; import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { import type { MessageReactionRemoveAll } from "../../types/messages/message_reaction_remove_all.ts";
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", "messages",
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId)
); );
if (message?.reactions) { if (message?.reactions) {
@@ -21,12 +19,9 @@ export async function handleMessageReactionRemoveAll(
await cacheHandlers.set( await cacheHandlers.set(
"messages", "messages",
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId),
message, message
); );
} }
eventHandlers.reactionRemoveAll?.( eventHandlers.reactionRemoveAll?.(payload, message);
payload,
message,
);
} }
@@ -5,12 +5,12 @@ import type { MessageReactionRemoveEmoji } from "../../types/messages/message_re
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", "messages",
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId)
); );
if (message?.reactions) { if (message?.reactions) {
@@ -18,9 +18,11 @@ export async function handleMessageReactionRemoveEmoji(
(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 (!message.reactions.length) message.reactions = undefined; if (!message.reactions.length) message.reactions = undefined;
@@ -32,6 +34,6 @@ export async function handleMessageReactionRemoveEmoji(
payload.emoji, payload.emoji,
snowflakeToBigint(payload.messageId), snowflakeToBigint(payload.messageId),
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId),
payload.guildId ? snowflakeToBigint(payload.guildId) : undefined, payload.guildId ? snowflakeToBigint(payload.guildId) : undefined
); );
} }
+3 -6
View File
@@ -9,21 +9,18 @@ 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", "channels",
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
if (!channel) return; if (!channel) return;
const oldMessage = await cacheHandlers.get( const oldMessage = await cacheHandlers.get(
"messages", "messages",
snowflakeToBigint(payload.id), 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
if ( if (!payload.editedTimestamp || oldMessage.content === payload.content) {
!payload.editedTimestamp ||
(oldMessage.content === payload.content)
) {
return; return;
} }
+2 -2
View File
@@ -9,12 +9,12 @@ export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
const oldPresence = await cacheHandlers.get( const oldPresence = await cacheHandlers.get(
"presences", "presences",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id)
); );
await cacheHandlers.set( await cacheHandlers.set(
"presences", "presences",
snowflakeToBigint(payload.user.id), snowflakeToBigint(payload.user.id),
payload, payload
); );
eventHandlers.presenceUpdate?.(payload, oldPresence); eventHandlers.presenceUpdate?.(payload, oldPresence);
+5 -17
View File
@@ -5,10 +5,7 @@ import type { Ready } from "../../types/gateway/ready.ts";
import { snowflakeToBigint } from "../../util/bigint.ts"; import { snowflakeToBigint } from "../../util/bigint.ts";
import { DiscordenoShard, ws } from "../../ws/ws.ts"; import { DiscordenoShard, ws } from "../../ws/ws.ts";
export function handleReady( export function handleReady(data: DiscordGatewayPayload, shardId: number) {
data: DiscordGatewayPayload,
shardId: number,
) {
// Triggered on each shard // Triggered on each shard
eventHandlers.shardReady?.(shardId); eventHandlers.shardReady?.(shardId);
@@ -26,17 +23,14 @@ export function handleReady(
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();
// Start ready check in 2 seconds // Start ready check in 2 seconds
setTimeout(() => { setTimeout(() => {
eventHandlers.debug?.( eventHandlers.debug?.("loop", `1. Running setTimeout in READY file.`);
"loop",
`1. Running setTimeout in READY file.`,
);
checkReady(payload, shard); checkReady(payload, shard);
}, 2000); }, 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 // Not all guilds were loaded but 5 seconds haven't passed so check again
setTimeout(() => { setTimeout(() => {
eventHandlers.debug?.( eventHandlers.debug?.("loop", `2. Running setTimeout in READY file.`);
"loop",
`2. Running setTimeout in READY file.`,
);
checkReady(payload, shard); checkReady(payload, shard);
}, 2000); }, 2000);
} }
@@ -72,10 +63,7 @@ function loaded(shard: DiscordenoShard) {
// Still some shards are loading so wait another 2 seconds for them // Still some shards are loading so wait another 2 seconds for them
if (ws.shards.some((shard) => !shard.ready)) { if (ws.shards.some((shard) => !shard.ready)) {
setTimeout(() => { setTimeout(() => {
eventHandlers.debug?.( eventHandlers.debug?.("loop", `3. Running setTimeout in READY file.`);
"loop",
`3. Running setTimeout in READY file.`,
);
loaded(shard); loaded(shard);
}, 2000); }, 2000);
+1 -3
View File
@@ -3,7 +3,5 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.
import type { TypingStart } from "../../types/misc/typing_start.ts"; import type { TypingStart } from "../../types/misc/typing_start.ts";
export function handleTypingStart(data: DiscordGatewayPayload) { export function handleTypingStart(data: DiscordGatewayPayload) {
eventHandlers.typingStart?.( eventHandlers.typingStart?.(data.d as TypingStart);
data.d as TypingStart,
);
} }
+3 -6
View File
@@ -9,17 +9,14 @@ export async function handleUserUpdate(data: DiscordGatewayPayload) {
const member = await cacheHandlers.get( const member = await cacheHandlers.get(
"members", "members",
snowflakeToBigint(userData.id), snowflakeToBigint(userData.id)
); );
if (!member) return; if (!member) return;
Object.entries(userData).forEach(([key, value]) => { Object.entries(userData).forEach(([key, value]) => {
eventHandlers.debug?.( eventHandlers.debug?.("loop", `Running forEach loop in USER_UPDATE file.`);
"loop",
`Running forEach loop in USER_UPDATE file.`,
);
// @ts-ignore index signatures // @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); await cacheHandlers.set("members", snowflakeToBigint(userData.id), member);
+1 -1
View File
@@ -9,7 +9,7 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
+3 -3
View File
@@ -8,7 +8,7 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
@@ -23,7 +23,7 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
cacheHandlers.forEach("members", (member) => { cacheHandlers.forEach("members", (member) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "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. // Not in the relevant guild so just skip.
if (!member.guilds.has(guild.id)) return; if (!member.guilds.has(guild.id)) return;
@@ -31,7 +31,7 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
member.guilds.forEach((g) => { member.guilds.forEach((g) => {
eventHandlers.debug?.( eventHandlers.debug?.(
"loop", "loop",
`2. Running forEach loop in CHANNEL_DELTE file.`, `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;
+1 -1
View File
@@ -9,7 +9,7 @@ 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", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
+1 -1
View File
@@ -9,7 +9,7 @@ export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
const guild = await cacheHandlers.get( const guild = await cacheHandlers.get(
"guilds", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
+9 -10
View File
@@ -11,15 +11,12 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
const guild = await cacheHandlers.get( const guild = await cacheHandlers.get(
"guilds", "guilds",
snowflakeToBigint(payload.guildId), snowflakeToBigint(payload.guildId)
); );
if (!guild) return; if (!guild) return;
const member = payload.member const member = payload.member
? await structures.createDiscordenoMember( ? await structures.createDiscordenoMember(payload.member, guild.id)
payload.member,
guild.id,
)
: await cacheHandlers.get("members", snowflakeToBigint(payload.userId)); : await cacheHandlers.get("members", snowflakeToBigint(payload.userId));
if (!member) return; if (!member) return;
@@ -28,7 +25,7 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
guild.voiceStates.set( guild.voiceStates.set(
snowflakeToBigint(payload.userId), snowflakeToBigint(payload.userId),
await structures.createDiscordenoVoiceState(guild.id, payload), await structures.createDiscordenoVoiceState(guild.id, payload)
); );
await cacheHandlers.set("guilds", guild.id, guild); await cacheHandlers.set("guilds", guild.id, guild);
@@ -39,16 +36,18 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
) { ) {
// Either joined or moved channels // Either joined or moved channels
if (payload.channelId) { if (payload.channelId) {
if (cachedState?.channelId) { // Was in a channel before if (cachedState?.channelId) {
// Was in a channel before
eventHandlers.voiceChannelSwitch?.( eventHandlers.voiceChannelSwitch?.(
member, member,
snowflakeToBigint(payload.channelId), 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?.( eventHandlers.voiceChannelJoin?.(
member, member,
snowflakeToBigint(payload.channelId), snowflakeToBigint(payload.channelId)
); );
} }
} // Left the channel } // Left the channel
+1 -1
View File
@@ -7,6 +7,6 @@ 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.channelId),
snowflakeToBigint(options.guildId), snowflakeToBigint(options.guildId)
); );
} }
+1 -1
View File
@@ -4,6 +4,6 @@ import { cacheHandlers } from "../../cache.ts";
export async function categoryChildren(id: bigint) { export async function categoryChildren(id: bigint) {
return await cacheHandlers.filter( return await cacheHandlers.filter(
"channels", "channels",
(channel) => channel.parentId === id, (channel) => channel.parentId === id
); );
} }
@@ -11,9 +11,10 @@ export function channelOverwriteHasPermission(
allow: bigint; allow: bigint;
deny: 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); overwrites.find((perm) => perm.id === guildId);
if (!overwrite) return false; if (!overwrite) return false;
@@ -21,14 +22,10 @@ export function channelOverwriteHasPermission(
return permissions.every((perm) => { return permissions.every((perm) => {
const allowBits = overwrite.allow; const allowBits = overwrite.allow;
const denyBits = overwrite.deny; const denyBits = overwrite.deny;
if ( if (BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])
) {
return false; return false;
} }
if ( if (BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])
) {
return true; return true;
} }
}); });
+5 -5
View File
@@ -26,20 +26,20 @@ export async function cloneChannel(channelId: bigint, reason?: string) {
parentId: channelToClone.parentId parentId: channelToClone.parentId
? bigintToSnowflake(channelToClone.parentId) ? bigintToSnowflake(channelToClone.parentId)
: undefined, : 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()),
deny: calculatePermissions(overwrite.deny.toString()), deny: calculatePermissions(overwrite.deny.toString()),
})), })
),
}; };
//Create the channel (also handles permissions) //Create the channel (also handles permissions)
return await helpers.createChannel( return await helpers.createChannel(
channelToClone.guildId!, channelToClone.guildId!,
createChannelOptions, createChannelOptions,
reason, reason
); );
} }
+3 -6
View File
@@ -18,13 +18,10 @@ import { snakelize } from "../../util/utils.ts";
export async function createChannel( export async function createChannel(
guildId: bigint, guildId: bigint,
options?: CreateGuildChannel, options?: CreateGuildChannel,
reason?: string, reason?: string
) { ) {
if (options?.permissionOverwrites) { if (options?.permissionOverwrites) {
await requireOverwritePermissions( await requireOverwritePermissions(guildId, options.permissionOverwrites);
guildId,
options.permissionOverwrites,
);
} }
// 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
@@ -42,7 +39,7 @@ export async function createChannel(
})), })),
type: options?.type || DiscordChannelTypes.GuildText, type: options?.type || DiscordChannelTypes.GuildText,
reason, reason,
}, }
); );
const discordenoChannel = await structures.createDiscordenoChannel(result); const discordenoChannel = await structures.createDiscordenoChannel(result);
@@ -23,9 +23,7 @@ export async function createStageInstance(channelId: bigint, topic: string) {
]); ]);
} }
if ( if (!validateLength(topic, { max: 120, min: 1 })) {
!validateLength(topic, { max: 120, min: 1 })
) {
throw new Error(Errors.INVALID_TOPIC_LENGTH); throw new Error(Errors.INVALID_TOPIC_LENGTH);
} }
@@ -33,8 +31,8 @@ export async function createStageInstance(channelId: bigint, topic: string) {
"post", "post",
endpoints.STAGE_INSTANCES, endpoints.STAGE_INSTANCES,
{ {
"channel_id": channelId, channel_id: channelId,
topic, topic,
}, }
); );
} }
+3 -6
View File
@@ -6,10 +6,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ /** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function deleteChannel( export async function deleteChannel(channelId: bigint, reason?: string) {
channelId: bigint,
reason?: string,
) {
const channel = await cacheHandlers.get("channels", channelId); const channel = await cacheHandlers.get("channels", channelId);
if (channel?.guildId) { if (channel?.guildId) {
@@ -25,7 +22,7 @@ export async function deleteChannel(
ChannelTypes.GuildPublicThread, ChannelTypes.GuildPublicThread,
].includes(channel.type) ].includes(channel.type)
? ["MANAGE_THREADS"] ? ["MANAGE_THREADS"]
: ["MANAGE_CHANNELS"], : ["MANAGE_CHANNELS"]
); );
if (guild.rulesChannelId === channelId) { if (guild.rulesChannelId === channelId) {
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED); throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
@@ -39,6 +36,6 @@ export async function deleteChannel(
return await rest.runMethod<undefined>( return await rest.runMethod<undefined>(
"delete", "delete",
endpoints.CHANNEL_BASE(channelId), endpoints.CHANNEL_BASE(channelId),
{ reason }, { reason }
); );
} }
@@ -6,12 +6,12 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function deleteChannelOverwrite( export async function deleteChannelOverwrite(
guildId: bigint, guildId: bigint,
channelId: bigint, channelId: bigint,
overwriteId: bigint, overwriteId: bigint
): 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", "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>( return await rest.runMethod<undefined>(
"delete", "delete",
endpoints.STAGE_INSTANCE(channelId), endpoints.STAGE_INSTANCE(channelId)
); );
} }
+4 -4
View File
@@ -22,7 +22,7 @@ import { hasOwnProperty, snakelize } from "../../util/utils.ts";
export async function editChannel( export async function editChannel(
channelId: bigint, channelId: bigint,
options: ModifyChannel | ModifyThread, options: ModifyChannel | ModifyThread,
reason?: string, reason?: string
) { ) {
const channel = await cacheHandlers.get("channels", channelId); const channel = await cacheHandlers.get("channels", channelId);
@@ -57,7 +57,7 @@ export async function editChannel(
) { ) {
await requireOverwritePermissions( await requireOverwritePermissions(
channel.guildId, channel.guildId,
options.permissionOverwrites, options.permissionOverwrites
); );
} }
} }
@@ -93,7 +93,7 @@ export async function editChannel(
// deno-lint-ignore camelcase // deno-lint-ignore camelcase
permission_overwrites: hasOwnProperty<ModifyChannel>( permission_overwrites: hasOwnProperty<ModifyChannel>(
options, options,
"permissionOverwrites", "permissionOverwrites"
) )
? options.permissionOverwrites?.map((overwrite) => { ? options.permissionOverwrites?.map((overwrite) => {
return { return {
@@ -111,7 +111,7 @@ export async function editChannel(
{ {
...payload, ...payload,
reason, reason,
}, }
); );
return await structures.createDiscordenoChannel(result); return await structures.createDiscordenoChannel(result);
@@ -11,7 +11,7 @@ export async function editChannelOverwrite(
guildId: bigint, guildId: bigint,
channelId: bigint, channelId: bigint,
overwriteId: bigint, overwriteId: bigint,
options: Omit<Overwrite, "id">, options: Omit<Overwrite, "id">
): Promise<undefined> { ): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
@@ -22,6 +22,6 @@ export async function editChannelOverwrite(
allow: calculateBits(options.allow), allow: calculateBits(options.allow),
deny: calculateBits(options.deny), deny: calculateBits(options.deny),
type: options.type, type: options.type,
}, }
); );
} }
+2 -2
View File
@@ -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. */ /** 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, sourceChannelId: bigint,
targetChannelId: bigint, targetChannelId: bigint
) { ) {
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]); await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
@@ -15,7 +15,7 @@ export async function followChannel(
endpoints.CHANNEL_FOLLOW(sourceChannelId), endpoints.CHANNEL_FOLLOW(sourceChannelId),
{ {
webhook_channel_id: targetChannelId, webhook_channel_id: targetChannelId,
}, }
); );
return data.webhookId; return data.webhookId;
+3 -3
View File
@@ -12,18 +12,18 @@ import { endpoints } from "../../util/constants.ts";
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", "get",
endpoints.CHANNEL_BASE(channelId), 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", "channels",
discordenoChannel.id, discordenoChannel.id,
discordenoChannel, discordenoChannel
); );
} }
+2 -4
View File
@@ -10,10 +10,8 @@ export async function getChannelWebhooks(channelId: bigint) {
const result = await rest.runMethod<Webhook[]>( const result = await rest.runMethod<Webhook[]>(
"get", "get",
endpoints.CHANNEL_WEBHOOKS(channelId), endpoints.CHANNEL_WEBHOOKS(channelId)
); );
return new Collection( return new Collection(result.map((webhook) => [webhook.id, webhook]));
result.map((webhook) => [webhook.id, webhook]),
);
} }
+5 -5
View File
@@ -12,7 +12,7 @@ import { endpoints } from "../../util/constants.ts";
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", "get",
endpoints.GUILD_CHANNELS(guildId), endpoints.GUILD_CHANNELS(guildId)
); );
return new Collection( return new Collection(
@@ -21,19 +21,19 @@ export async function getChannels(guildId: bigint, addToCache = true) {
result.map(async (res) => { result.map(async (res) => {
const discordenoChannel = await structures.createDiscordenoChannel( const discordenoChannel = await structures.createDiscordenoChannel(
res, res,
guildId, guildId
); );
if (addToCache) { if (addToCache) {
await cacheHandlers.set( await cacheHandlers.set(
"channels", "channels",
discordenoChannel.id, discordenoChannel.id,
discordenoChannel, discordenoChannel
); );
} }
return discordenoChannel; return discordenoChannel;
}), })
) )
).map((c) => [c.id, c]), ).map((c) => [c.id, c])
); );
} }
+2 -2
View File
@@ -7,10 +7,10 @@ import { endpoints } from "../../util/constants.ts";
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", "get",
endpoints.CHANNEL_PINS(channelId), endpoints.CHANNEL_PINS(channelId)
); );
return Promise.all( return Promise.all(
result.map((res) => structures.createDiscordenoMessage(res)), result.map((res) => structures.createDiscordenoMessage(res))
); );
} }
+1 -1
View File
@@ -17,6 +17,6 @@ export async function getStageInstance(channelId: bigint) {
return await rest.runMethod<StageInstance>( return await rest.runMethod<StageInstance>(
"get", "get",
endpoints.STAGE_INSTANCE(channelId), endpoints.STAGE_INSTANCE(channelId)
); );
} }
+1 -1
View File
@@ -10,7 +10,7 @@ export async function isChannelSynced(channelId: bigint) {
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 !(
+5 -8
View File
@@ -27,19 +27,16 @@ 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( const hasSendMessagesPerm = await botHasChannelPermissions(channelId, [
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", "post",
endpoints.CHANNEL_TYPING(channelId), endpoints.CHANNEL_TYPING(channelId)
); );
} }
+2 -2
View File
@@ -5,7 +5,7 @@ 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, guildId: bigint,
channelPositions: ModifyGuildChannelPositions[], 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.";
@@ -14,6 +14,6 @@ export async function swapChannels(
return await rest.runMethod<undefined>( return await rest.runMethod<undefined>(
"patch", "patch",
endpoints.GUILD_CHANNELS(guildId), endpoints.GUILD_CHANNELS(guildId),
channelPositions, channelPositions
); );
} }
@@ -26,6 +26,6 @@ export async function addToThread(channelId: bigint, userId?: bigint) {
"put", "put",
userId userId
? endpoints.THREAD_USER(channelId, 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) { export async function getActiveThreads(channelId: bigint) {
// TODO(threads): perm check // TODO(threads): perm check
// TODO(threads): test if it works // TODO(threads): test if it works
return await rest.runMethod( return await rest.runMethod("get", endpoints.THREAD_ACTIVE(channelId));
"get",
endpoints.THREAD_ACTIVE(channelId),
);
} }
@@ -7,7 +7,7 @@ export async function getArchivedThreads(
channelId: bigint, channelId: bigint,
options?: ListPublicArchivedThreads & { options?: ListPublicArchivedThreads & {
type?: "public" | "private" | "privateJoinedThreads"; type?: "public" | "private" | "privateJoinedThreads";
}, }
) { ) {
// TODO(threads): perm check // TODO(threads): perm check
// TODO(threads): check if this works // TODO(threads): check if this works
@@ -19,6 +19,6 @@ export async function getArchivedThreads(
: options?.type === "private" : options?.type === "private"
? endpoints.THREAD_ARCHIVED_PRIVATE(channelId) ? endpoints.THREAD_ARCHIVED_PRIVATE(channelId)
: endpoints.THREAD_ARCHIVED_PUBLIC(channelId), : endpoints.THREAD_ARCHIVED_PUBLIC(channelId),
snakelize(options ?? {}), snakelize(options ?? {})
); );
} }
@@ -24,6 +24,6 @@ export async function removeFromThread(channelId: bigint, userId?: bigint) {
"delete", "delete",
userId userId
? endpoints.THREAD_USER(channelId, userId) ? endpoints.THREAD_USER(channelId, userId)
: endpoints.THREAD_ME(channelId), : endpoints.THREAD_ME(channelId)
); );
} }
+2 -2
View File
@@ -12,7 +12,7 @@ import { snakelize } from "../../../util/utils.ts";
*/ */
export async function startThread( export async function startThread(
channelId: bigint, channelId: bigint,
options: StartThread & { messageId?: bigint }, options: StartThread & { messageId?: bigint }
) { ) {
const channel = await cacheHandlers.get("channels", channelId); const channel = await cacheHandlers.get("channels", channelId);
if (channel) { if (channel) {
@@ -33,6 +33,6 @@ export async function startThread(
options?.messageId options?.messageId
? endpoints.THREAD_START_PUBLIC(channelId, options.messageId) ? endpoints.THREAD_START_PUBLIC(channelId, options.messageId)
: endpoints.THREAD_START_PRIVATE(channelId), : 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), endpoints.STAGE_INSTANCE(channelId),
{ {
topic, topic,
}, }
); );
} }
+4 -6
View File
@@ -1,8 +1,6 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts"; import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts";
import type { import type { UpdateSelfVoiceState } from "../../types/guilds/update_self_voice_state.ts";
UpdateSelfVoiceState,
} from "../../types/guilds/update_self_voice_state.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { hasOwnProperty, snakelize } from "../../util/utils.ts"; import { hasOwnProperty, snakelize } from "../../util/utils.ts";
@@ -19,14 +17,14 @@ import { hasOwnProperty, snakelize } from "../../util/utils.ts";
*/ */
export async function updateBotVoiceState( export async function updateBotVoiceState(
guildId: bigint, guildId: bigint,
options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState, options: UpdateSelfVoiceState | ({ userId: bigint } & UpdateOthersVoiceState)
) { ) {
return await rest.runMethod( return await rest.runMethod(
"patch", "patch",
endpoints.UPDATE_VOICE_STATE( endpoints.UPDATE_VOICE_STATE(
guildId, 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 { rest } from "../../rest/rest.ts";
import type { import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts";
AddGuildDiscoverySubcategory,
} from "../../types/discovery/add_guild_discovery_subcategory.ts";
import { endpoints } from "../../util/constants.ts"; 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, guildId: bigint,
categoryId: number, categoryId: number
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<AddGuildDiscoverySubcategory>( return await rest.runMethod<AddGuildDiscoverySubcategory>(
"post", "post",
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId), endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId)
); );
} }
+2 -2
View File
@@ -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. */ /** 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, guildId: bigint,
data: ModifyGuildDiscoveryMetadata, data: ModifyGuildDiscoveryMetadata
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<DiscoveryMetadata>( return await rest.runMethod<DiscoveryMetadata>(
"patch", "patch",
endpoints.DISCOVERY_MODIFY(guildId), endpoints.DISCOVERY_MODIFY(guildId),
snakelize(data), snakelize(data)
); );
} }
@@ -7,12 +7,10 @@ import { endpoints } from "../../util/constants.ts";
export async function getDiscoveryCategories() { export async function getDiscoveryCategories() {
const result = await rest.runMethod<DiscoveryCategory[]>( const result = await rest.runMethod<DiscoveryCategory[]>(
"get", "get",
endpoints.DISCOVERY_CATEGORIES, endpoints.DISCOVERY_CATEGORIES
); );
return new Collection<number, DiscoveryCategory>( return new Collection<number, DiscoveryCategory>(
result.map( result.map((category) => [category.id, category])
(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. */ /** 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, guildId: bigint,
categoryId: number, categoryId: number
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<undefined>( return await rest.runMethod<undefined>(
"delete", "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>( const result = await rest.runMethod<ValidateDiscoverySearchTerm>(
"get", "get",
endpoints.DISCOVERY_VALID_TERM, endpoints.DISCOVERY_VALID_TERM,
{ term }, { term }
); );
return result.valid; return result.valid;
+2 -2
View File
@@ -11,7 +11,7 @@ export async function createEmoji(
guildId: bigint, guildId: bigint,
name: string, name: string,
image: string, image: string,
options: CreateGuildEmoji, options: CreateGuildEmoji
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
@@ -26,7 +26,7 @@ export async function createEmoji(
...options, ...options,
name, name,
image, image,
}, }
); );
return { return {
+2 -2
View File
@@ -6,13 +6,13 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function deleteEmoji( export async function deleteEmoji(
guildId: bigint, guildId: bigint,
id: bigint, id: bigint,
reason?: string, reason?: string
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
return await rest.runMethod<undefined>( return await rest.runMethod<undefined>(
"delete", "delete",
endpoints.GUILD_EMOJI(guildId, id), endpoints.GUILD_EMOJI(guildId, id),
{ reason }, { reason }
); );
} }
+2 -2
View File
@@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function editEmoji( export async function editEmoji(
guildId: bigint, guildId: bigint,
id: bigint, id: bigint,
options: ModifyGuildEmoji, options: ModifyGuildEmoji
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
@@ -18,6 +18,6 @@ export async function editEmoji(
{ {
name: options.name, name: options.name,
roles: options.roles, roles: options.roles,
}, }
); );
} }
+3 -7
View File
@@ -12,22 +12,18 @@ import { endpoints } from "../../util/constants.ts";
export async function getEmoji( export async function getEmoji(
guildId: bigint, guildId: bigint,
emojiId: bigint, emojiId: bigint,
addToCache = true, addToCache = true
) { ) {
const result = await rest.runMethod<Emoji>( const result = await rest.runMethod<Emoji>(
"get", "get",
endpoints.GUILD_EMOJI(guildId, emojiId), endpoints.GUILD_EMOJI(guildId, emojiId)
); );
if (addToCache) { if (addToCache) {
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);
guild.emojis.set(emojiId, result); guild.emojis.set(emojiId, result);
await cacheHandlers.set( await cacheHandlers.set("guilds", guildId, guild);
"guilds",
guildId,
guild,
);
} }
return result; return result;
+2 -5
View File
@@ -15,7 +15,7 @@ import { endpoints } from "../../util/constants.ts";
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", "get",
endpoints.GUILD_EMOJIS(guildId), endpoints.GUILD_EMOJIS(guildId)
); );
if (addToCache) { if (addToCache) {
@@ -23,10 +23,7 @@ export async function getEmojis(guildId: bigint, addToCache = true) {
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
result.forEach((emoji) => { result.forEach((emoji) => {
eventHandlers.debug?.( eventHandlers.debug?.("loop", `Running forEach loop in get_emojis file.`);
"loop",
`Running forEach loop in get_emojis file.`,
);
guild.emojis.set(snowflakeToBigint(emoji.id!), emoji); guild.emojis.set(snowflakeToBigint(emoji.id!), emoji);
}); });
+1 -5
View File
@@ -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. */ /** 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) { export async function createGuild(options: CreateGuild) {
const result = await rest.runMethod<Guild>( const result = await rest.runMethod<Guild>("post", endpoints.GUILDS, options);
"post",
endpoints.GUILDS,
options,
);
const guild = await structures.createDiscordenoGuild(result, 0); const guild = await structures.createDiscordenoGuild(result, 0);
// MANUALLY CACHE THE GUILD // MANUALLY CACHE THE GUILD
+1 -1
View File
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
export async function deleteGuild(guildId: bigint) { export async function deleteGuild(guildId: bigint) {
return await rest.runMethod<undefined>( return await rest.runMethod<undefined>(
"delete", "delete",
endpoints.GUILDS_BASE(guildId), endpoints.GUILDS_BASE(guildId)
); );
} }
+3 -4
View File
@@ -27,7 +27,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
const result = await rest.runMethod<Guild>( const result = await rest.runMethod<Guild>(
"patch", "patch",
endpoints.GUILDS_BASE(guildId), endpoints.GUILDS_BASE(guildId),
options, options
); );
const cached = await cacheHandlers.get("guilds", guildId); const cached = await cacheHandlers.get("guilds", guildId);
@@ -35,8 +35,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
result, result,
cached?.shardId || cached?.shardId ||
Number( Number(
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)) (BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString()
.toString(), )
),
); );
} }
+2 -2
View File
@@ -6,11 +6,11 @@ import { snakelize } from "../../util/utils.ts";
export async function editWelcomeScreen( export async function editWelcomeScreen(
guildId: bigint, guildId: bigint,
options: ModifyGuildWelcomeScreen, options: ModifyGuildWelcomeScreen
) { ) {
return await rest.runMethod<WelcomeScreen>( return await rest.runMethod<WelcomeScreen>(
"patch", "patch",
endpoints.GUILD_WELCOME_SCREEN(guildId), endpoints.GUILD_WELCOME_SCREEN(guildId),
snakelize(options), snakelize(options)
); );
} }
+2 -2
View File
@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function editWidget( export async function editWidget(
guildId: bigint, guildId: bigint,
enabled: boolean, enabled: boolean,
channelId?: string | null, channelId?: string | null
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
@@ -17,6 +17,6 @@ export async function editWidget(
{ {
enabled, enabled,
channel_id: channelId, channel_id: channelId,
}, }
); );
} }
+4 -6
View File
@@ -6,10 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakelize } from "../../util/utils.ts"; import { snakelize } from "../../util/utils.ts";
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
export async function getAuditLogs( export async function getAuditLogs(guildId: bigint, options: GetGuildAuditLog) {
guildId: bigint,
options: GetGuildAuditLog,
) {
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]); await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
return await rest.runMethod<AuditLog>( return await rest.runMethod<AuditLog>(
@@ -17,9 +14,10 @@ export async function getAuditLogs(
endpoints.GUILD_AUDIT_LOGS(guildId), endpoints.GUILD_AUDIT_LOGS(guildId),
snakelize({ snakelize({
...options, ...options,
limit: options.limit && options.limit >= 1 && options.limit <= 100 limit:
options.limit && options.limit >= 1 && options.limit <= 100
? options.limit ? options.limit
: 50, : 50,
}), })
); );
} }
+1 -1
View File
@@ -9,6 +9,6 @@ export async function getBan(guildId: bigint, memberId: bigint) {
return await rest.runMethod<Ban>( return await rest.runMethod<Ban>(
"get", "get",
endpoints.GUILD_BAN(guildId, memberId), endpoints.GUILD_BAN(guildId, memberId)
); );
} }
+2 -2
View File
@@ -11,10 +11,10 @@ export async function getBans(guildId: bigint) {
const results = await rest.runMethod<Ban[]>( const results = await rest.runMethod<Ban[]>(
"get", "get",
endpoints.GUILD_BANS(guildId), 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])
); );
} }
+3 -3
View File
@@ -17,19 +17,19 @@ export async function getGuild(
options: { counts?: boolean; addToCache?: boolean } = { options: { counts?: boolean; addToCache?: boolean } = {
counts: true, counts: true,
addToCache: true, addToCache: true,
}, }
) { ) {
const result = await rest.runMethod<Guild>( const result = await rest.runMethod<Guild>(
"get", "get",
endpoints.GUILDS_BASE(guildId), endpoints.GUILDS_BASE(guildId),
{ {
with_counts: options.counts, with_counts: options.counts,
}, }
); );
const guild = await structures.createDiscordenoGuild( const guild = await structures.createDiscordenoGuild(
result, result,
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)), Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
); );
if (options.addToCache) { if (options.addToCache) {
+1 -1
View File
@@ -6,6 +6,6 @@ import { endpoints } from "../../util/constants.ts";
export async function getGuildPreview(guildId: bigint) { export async function getGuildPreview(guildId: bigint) {
return await rest.runMethod<GuildPreview>( return await rest.runMethod<GuildPreview>(
"get", "get",
endpoints.GUILD_PREVIEW(guildId), endpoints.GUILD_PREVIEW(guildId)
); );
} }
+2 -2
View File
@@ -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 */ /** 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, guildId: bigint,
options?: GetGuildPruneCountQuery, 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) {
@@ -20,7 +20,7 @@ export async function getPruneCount(
const result = await rest.runMethod( const result = await rest.runMethod(
"get", "get",
endpoints.GUILD_PRUNE(guildId), endpoints.GUILD_PRUNE(guildId),
snakelize(options ?? {}), snakelize(options ?? {})
); );
return result.pruned as number; return result.pruned as number;
+3 -5
View File
@@ -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. */ /** 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) { export async function getVanityURL(guildId: bigint) {
return await rest.runMethod< return await rest.runMethod<
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | { | (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
| {
code: null; code: null;
} }
>( >("get", endpoints.GUILD_VANITY_URL(guildId));
"get",
endpoints.GUILD_VANITY_URL(guildId),
);
} }
+2 -2
View File
@@ -7,10 +7,10 @@ import { endpoints } from "../../util/constants.ts";
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", "get",
endpoints.GUILD_REGIONS(guildId), 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])
); );
} }
+1 -1
View File
@@ -5,6 +5,6 @@ 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", "get",
endpoints.GUILD_WELCOME_SCREEN(guildId), endpoints.GUILD_WELCOME_SCREEN(guildId)
); );
} }
+1 -1
View File
@@ -14,6 +14,6 @@ export async function getWidget(guildId: bigint, options?: { force: boolean }) {
return await rest.runMethod<GuildWidgetDetails>( return await rest.runMethod<GuildWidgetDetails>(
"get", "get",
`${endpoints.GUILD_WIDGET(guildId)}.json`, `${endpoints.GUILD_WIDGET(guildId)}.json`
); );
} }
+4 -3
View File
@@ -6,7 +6,7 @@ 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, guildId: bigint,
options?: GetGuildWidgetImageQuery & { force?: boolean }, options?: GetGuildWidgetImageQuery & { force?: boolean }
) { ) {
if (!options?.force) { if (!options?.force) {
const guild = await cacheHandlers.get("guilds", guildId); 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); if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
} }
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${
"shield"}`; options?.style ?? "shield"
}`;
} }

Some files were not shown because too many files have changed in this diff Show More