change: ids to use bigint instead of string (#892)

* p1 of bigints change

* shtuff fixes and bits

* Commit from GitHub Actions (Lint)

* finish bigint structs

* typings fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* blame wolf

* Commit from GitHub Actions (Lint)

* foxed

* Commit from GitHub Actions (Lint)

* fix unit tests

* Commit from GitHub Actions (Lint)

* change: guildUpdate guild ID can't change

* delete server has been renamed to delete guild

* fixes

Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com>
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
Skillz4Killz
2021-05-03 13:05:18 -04:00
committed by GitHub
parent ee164bff22
commit 3d39b3878a
186 changed files with 1341 additions and 610 deletions

View File

@@ -2,12 +2,13 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts";
import { rest } from "./rest/rest.ts";
import { EventHandlers } from "./types/discordeno/eventHandlers.ts";
import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts";
import { snowflakeToBigint } from "./util/bigint.ts";
import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
import { ws } from "./ws/ws.ts";
export let secretKey = "";
export let botId = "";
export let applicationId = "";
export let botId = 0n;
export let applicationId = 0n;
export let eventHandlers: EventHandlers = {};
@@ -49,12 +50,12 @@ export function updateEventHandlers(newEventHandlers: EventHandlers) {
/** INTERNAL LIB function used to set the bot Id once the READY event is sent by Discord. */
export function setBotId(id: string) {
if (botId !== id) botId = id;
botId = snowflakeToBigint(id);
}
/** INTERNAL LIB function used to set the application Id once the READY event is sent by Discord. */
export function setApplicationId(id: string) {
if (applicationId !== id) applicationId = id;
applicationId = snowflakeToBigint(id);
}
// BIG BRAIN BOT STUFF ONLY BELOW THIS

View File

@@ -10,26 +10,26 @@ import { Collection } from "./util/collection.ts";
export const cache = {
isReady: false,
/** All of the guild objects the bot has access to, mapped by their Ids */
guilds: new Collection<string, DiscordenoGuild>(),
guilds: new Collection<bigint, DiscordenoGuild>(),
/** All of the channel objects the bot has access to, mapped by their Ids */
channels: new Collection<string, DiscordenoChannel>(),
channels: new Collection<bigint, DiscordenoChannel>(),
/** All of the message objects the bot has cached since the bot acquired `READY` state, mapped by their Ids */
messages: new Collection<string, DiscordenoMessage>(),
messages: new Collection<bigint, DiscordenoMessage>(),
/** All of the member objects that have been cached since the bot acquired `READY` state, mapped by their Ids */
members: new Collection<string, DiscordenoMember>(),
members: new Collection<bigint, DiscordenoMember>(),
/** All of the unavailable guilds, mapped by their Ids (id, timestamp) */
unavailableGuilds: new Collection<string, number>(),
unavailableGuilds: new Collection<bigint, number>(),
/** All of the presence update objects received in PRESENCE_UPDATE gateway event, mapped by their user Id */
presences: new Collection<string, PresenceUpdate>(),
presences: new Collection<bigint, PresenceUpdate>(),
fetchAllMembersProcessingRequests: new Collection<
string,
(
value:
| Collection<string, DiscordenoMember>
| PromiseLike<Collection<string, DiscordenoMember>>,
| Collection<bigint, DiscordenoMember>
| PromiseLike<Collection<bigint, DiscordenoMember>>,
) => void
>(),
executedSlashCommands: new Collection<string, string>(),
executedSlashCommands: new Set<string>(),
get emojis() {
return new Collection<string, Emoji>(
this.guilds.reduce(
@@ -46,11 +46,11 @@ export let cacheHandlers = {
return cache[table].clear();
},
/** Deletes 1 item from cache using the key */
async delete(table: TableName, key: string) {
async delete(table: TableName, key: bigint) {
return cache[table].delete(key);
},
/** Check if something exists in cache with a key */
async has(table: TableName, key: string) {
async has(table: TableName, key: bigint) {
return cache[table].has(key);
},
@@ -80,63 +80,63 @@ export type TableName =
function set(
table: "guilds",
key: string,
key: bigint,
value: DiscordenoGuild,
): Promise<Collection<string, DiscordenoGuild>>;
): Promise<Collection<bigint, DiscordenoGuild>>;
function set(
table: "channels",
key: string,
key: bigint,
value: DiscordenoChannel,
): Promise<Collection<string, DiscordenoChannel>>;
): Promise<Collection<bigint, DiscordenoChannel>>;
function set(
table: "messages",
key: string,
key: bigint,
value: DiscordenoMessage,
): Promise<Collection<string, DiscordenoMessage>>;
): Promise<Collection<bigint, DiscordenoMessage>>;
function set(
table: "members",
key: string,
key: bigint,
value: DiscordenoMember,
): Promise<Collection<string, DiscordenoMember>>;
): Promise<Collection<bigint, DiscordenoMember>>;
function set(
table: "presences",
key: string,
key: bigint,
value: PresenceUpdate,
): Promise<Collection<string, PresenceUpdate>>;
): Promise<Collection<bigint, PresenceUpdate>>;
function set(
table: "unavailableGuilds",
key: string,
key: bigint,
value: number,
): Promise<Collection<string, number>>;
async function set(table: TableName, key: string, value: any) {
): Promise<Collection<bigint, number>>;
async function set(table: TableName, key: bigint, value: any) {
return cache[table].set(key, value);
}
function get(
table: "guilds",
key: string,
key: bigint,
): Promise<DiscordenoGuild | undefined>;
function get(
table: "channels",
key: string,
key: bigint,
): Promise<DiscordenoChannel | undefined>;
function get(
table: "messages",
key: string,
key: bigint,
): Promise<DiscordenoMessage | undefined>;
function get(
table: "members",
key: string,
key: bigint,
): Promise<DiscordenoMember | undefined>;
function get(
table: "presences",
key: string,
key: bigint,
): Promise<PresenceUpdate | undefined>;
function get(
table: "unavailableGuilds",
key: string,
key: bigint,
): Promise<number | undefined>;
async function get(table: TableName, key: string) {
async function get(table: TableName, key: bigint) {
return cache[table].get(key);
}
@@ -144,68 +144,68 @@ function forEach(
table: "guilds",
callback: (
value: DiscordenoGuild,
key: string,
map: Map<string, DiscordenoGuild>,
key: bigint,
map: Map<bigint, DiscordenoGuild>,
) => unknown,
): void;
function forEach(
table: "unavailableGuilds",
callback: (value: number, key: string, map: Map<string, number>) => unknown,
callback: (value: number, key: bigint, map: Map<bigint, number>) => unknown,
): void;
function forEach(
table: "channels",
callback: (
value: DiscordenoChannel,
key: string,
map: Map<string, DiscordenoChannel>,
key: bigint,
map: Map<bigint, DiscordenoChannel>,
) => unknown,
): void;
function forEach(
table: "messages",
callback: (
value: DiscordenoMessage,
key: string,
map: Map<string, DiscordenoMessage>,
key: bigint,
map: Map<bigint, DiscordenoMessage>,
) => unknown,
): void;
function forEach(
table: "members",
callback: (
value: DiscordenoMember,
key: string,
map: Map<string, DiscordenoMember>,
key: bigint,
map: Map<bigint, DiscordenoMember>,
) => unknown,
): void;
function forEach(
table: TableName,
callback: (value: any, key: string, map: Map<string, any>) => unknown,
callback: (value: any, key: bigint, map: Map<bigint, any>) => unknown,
) {
return cache[table].forEach(callback);
}
function filter(
table: "guilds",
callback: (value: DiscordenoGuild, key: string) => boolean,
): Promise<Collection<string, DiscordenoGuild>>;
callback: (value: DiscordenoGuild, key: bigint) => boolean,
): Promise<Collection<bigint, DiscordenoGuild>>;
function filter(
table: "unavailableGuilds",
callback: (value: number, key: string) => boolean,
): Promise<Collection<string, number>>;
callback: (value: number, key: bigint) => boolean,
): Promise<Collection<bigint, number>>;
function filter(
table: "channels",
callback: (value: DiscordenoChannel, key: string) => boolean,
): Promise<Collection<string, DiscordenoChannel>>;
callback: (value: DiscordenoChannel, key: bigint) => boolean,
): Promise<Collection<bigint, DiscordenoChannel>>;
function filter(
table: "messages",
callback: (value: DiscordenoMessage, key: string) => boolean,
): Promise<Collection<string, DiscordenoMessage>>;
callback: (value: DiscordenoMessage, key: bigint) => boolean,
): Promise<Collection<bigint, DiscordenoMessage>>;
function filter(
table: "members",
callback: (value: DiscordenoMember, key: string) => boolean,
): Promise<Collection<string, DiscordenoMember>>;
callback: (value: DiscordenoMember, key: bigint) => boolean,
): Promise<Collection<bigint, DiscordenoMember>>;
async function filter(
table: TableName,
callback: (value: any, key: string) => boolean,
callback: (value: any, key: bigint) => boolean,
) {
return cache[table].filter(callback);
}

View File

@@ -3,21 +3,25 @@ import { cacheHandlers } from "../../cache.ts";
import { Channel } from "../../types/channels/channel.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleChannelDelete(data: DiscordGatewayPayload) {
const payload = data.d as Channel;
const cachedChannel = await cacheHandlers.get("channels", payload.id);
const cachedChannel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.id),
);
if (!cachedChannel) return;
if (
cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId
) {
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
if (guild) {
return Promise.all(guild.voiceStates.map(async (vs, key) => {
if (vs.channelId !== payload.id) return;
if (vs.channelId !== cachedChannel.id) return;
// Since this channel was deleted all voice states for this channel should be deleted
guild.voiceStates.delete(key);
@@ -30,13 +34,13 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
}
}
await cacheHandlers.delete("channels", payload.id);
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
cacheHandlers.forEach("messages", (message) => {
eventHandlers.debug?.(
"loop",
`Running forEach messages loop in CHANNEL_DELTE file.`,
);
if (message.channelId === payload.id) {
if (message.channelId === snowflakeToBigint(payload.id)) {
cacheHandlers.delete("messages", message.id);
}
});

View File

@@ -2,15 +2,19 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
const payload = data.d as ChannelPinsUpdate;
const channel = await cacheHandlers.get("channels", payload.channelId);
const channel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.channelId),
);
if (!channel) return;
const guild = payload.guildId
? await cacheHandlers.get("guilds", payload.guildId)
? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId))
: undefined;
eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp);

View File

@@ -3,10 +3,14 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { Channel } from "../../types/channels/channel.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
const payload = data.d as Channel;
const cachedChannel = await cacheHandlers.get("channels", payload.id);
const cachedChannel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.id),
);
const discordenoChannel = await structures.createDiscordenoChannel(payload);
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);

View File

@@ -2,19 +2,23 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
const payload = data.d as GuildEmojisUpdate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const cachedEmojis = guild.emojis;
guild.emojis = new Collection(
payload.emojis.map((emoji) => [emoji.id!, emoji]),
payload.emojis.map((emoji) => [snowflakeToBigint(emoji.id!), emoji]),
);
await cacheHandlers.set("guilds", payload.guildId, guild);
await cacheHandlers.set("guilds", guild.id, guild);
eventHandlers.guildEmojisUpdate?.(
guild,

View File

@@ -2,12 +2,19 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
const payload = data.d as GuildBanAddRemove;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const member = await cacheHandlers.get("members", payload.user.id);
const member = await cacheHandlers.get(
"members",
snowflakeToBigint(payload.user.id),
);
eventHandlers.guildBanAdd?.(guild, payload.user, member);
}

View File

@@ -2,12 +2,19 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
const payload = data.d as GuildBanAddRemove;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const member = await cacheHandlers.get("members", payload.user.id);
const member = await cacheHandlers.get(
"members",
snowflakeToBigint(payload.user.id),
);
eventHandlers.guildBanRemove?.(guild, payload.user, member);
}

View File

@@ -3,6 +3,7 @@ import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { ws } from "../../ws/ws.ts";
export async function handleGuildCreate(
@@ -11,24 +12,24 @@ export async function handleGuildCreate(
) {
const payload = data.d as Guild;
// When shards resume they emit GUILD_CREATE again.
if (await cacheHandlers.has("guilds", payload.id)) return;
if (await cacheHandlers.has("guilds", snowflakeToBigint(payload.id))) return;
const discordenoGuild = await structures.createDiscordenoGuild(
const guild = await structures.createDiscordenoGuild(
payload,
shardId,
);
await cacheHandlers.set("guilds", discordenoGuild.id, discordenoGuild);
await cacheHandlers.set("guilds", guild.id, guild);
const shard = ws.shards.get(shardId);
if (shard?.unavailableGuildIds.has(payload.id)) {
await cacheHandlers.delete("unavailableGuilds", payload.id);
if (shard?.unavailableGuildIds.has(guild.id)) {
await cacheHandlers.delete("unavailableGuilds", guild.id);
shard.unavailableGuildIds.delete(payload.id);
shard.unavailableGuildIds.delete(guild.id);
return eventHandlers.guildAvailable?.(discordenoGuild);
return eventHandlers.guildAvailable?.(guild);
}
if (!cache.isReady) return eventHandlers.guildLoaded?.(discordenoGuild);
eventHandlers.guildCreate?.(discordenoGuild);
if (!cache.isReady) return eventHandlers.guildLoaded?.(guild);
eventHandlers.guildCreate?.(guild);
}

View File

@@ -2,6 +2,7 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { ws } from "../../ws/ws.ts";
export async function handleGuildDelete(
@@ -10,16 +11,19 @@ export async function handleGuildDelete(
) {
const payload = data.d as UnavailableGuild;
const guild = await cacheHandlers.get("guilds", payload.id);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.id),
);
if (!guild) return;
await cacheHandlers.delete("guilds", payload.id);
await cacheHandlers.delete("guilds", guild.id);
if (payload.unavailable) {
const shard = ws.shards.get(shardId);
if (shard) shard.unavailableGuildIds.add(payload.id);
if (shard) shard.unavailableGuildIds.add(guild.id);
await cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
await cacheHandlers.set("unavailableGuilds", guild.id, Date.now());
eventHandlers.guildUnavailable?.(guild);
} else {
@@ -31,7 +35,7 @@ export async function handleGuildDelete(
"loop",
`1. Running forEach messages loop in CHANNEL_DELTE file.`,
);
if (message.guildId === payload.id) {
if (message.guildId === guild.id) {
cacheHandlers.delete("messages", message.id);
}
});
@@ -41,7 +45,7 @@ export async function handleGuildDelete(
"loop",
`2. Running forEach channels loop in CHANNEL_DELTE file.`,
);
if (channel.guildId === payload.id) {
if (channel.guildId === guild.id) {
cacheHandlers.delete("channels", channel.id);
}
});
@@ -51,9 +55,9 @@ export async function handleGuildDelete(
"loop",
`3. Running forEach members loop in CHANNEL_DELTE file.`,
);
if (!member.guilds.has(payload.id)) return;
if (!member.guilds.has(guild.id)) return;
member.guilds.delete(payload.id);
member.guilds.delete(guild.id);
if (!member.guilds.size) {
return cacheHandlers.delete("members", member.id);

View File

@@ -2,13 +2,17 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildIntegrationsUpdate(
data: DiscordGatewayPayload,
) {
const payload = data.d as GuildIntegrationsUpdate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
eventHandlers.guildIntegrationsUpdate?.(guild);

View File

@@ -3,13 +3,18 @@ import { cacheHandlers } from "../../cache.ts";
import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
const payload = data.d as Guild;
const newGuild = await cacheHandlers.get("guilds", payload.id);
const newGuild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.id),
);
if (!newGuild) return;
const keysToSkip = [
"id",
"roles",
"guildHashes",
"guildId",
@@ -40,7 +45,7 @@ export async function handleGuildUpdate(data: DiscordGatewayPayload) {
}
}).filter((change) => change) as GuildUpdateChange[];
await cacheHandlers.set("guilds", payload.id, newGuild);
await cacheHandlers.set("guilds", newGuild.id, newGuild);
eventHandlers.guildUpdate?.(newGuild, changes);
}

View File

@@ -4,13 +4,14 @@ import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { Interaction } from "../../types/interactions/interaction.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
const payload = data.d as Interaction;
const discordenoMember = payload.guildId
? await structures.createDiscordenoMember(
payload.member as GuildMemberWithUser,
payload.guildId,
snowflakeToBigint(payload.guildId),
)
: undefined;
if (discordenoMember) {

View File

@@ -2,16 +2,19 @@ import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
const payload = data.d as GuildMembersChunk;
const guildId = snowflakeToBigint(payload.guildId);
const members = await Promise.all(
payload.members.map(async (member) => {
const discordenoMember = await structures.createDiscordenoMember(
member,
payload.guildId,
guildId,
);
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
@@ -36,7 +39,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
return resolve(
await cacheHandlers.filter(
"members",
(m) => m.guilds.has(payload.guildId),
(m) => m.guilds.has(guildId),
),
);
}

View File

@@ -3,16 +3,20 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMemberAdd } from "../../types/members/guild_member_add.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
const payload = data.d as GuildMemberAdd;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
guild.memberCount++;
const discordenoMember = await structures.createDiscordenoMember(
payload,
payload.guildId,
guild.id,
);
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);

View File

@@ -2,14 +2,21 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMemberRemove } from "../../types/members/guild_member_remove.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
const payload = data.d as GuildMemberRemove;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
guild.memberCount--;
const member = await cacheHandlers.get("members", payload.user.id);
const member = await cacheHandlers.get(
"members",
snowflakeToBigint(payload.user.id),
);
eventHandlers.guildMemberRemove?.(guild, payload.user, member);
member?.guilds.delete(guild.id);

View File

@@ -3,14 +3,21 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMemberUpdate } from "../../types/members/guild_member_update.ts";
import { bigintToSnowflake, snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
const payload = data.d as GuildMemberUpdate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const cachedMember = await cacheHandlers.get("members", payload.user.id);
const guildMember = cachedMember?.guilds.get(payload.guildId);
const cachedMember = await cacheHandlers.get(
"members",
snowflakeToBigint(payload.user.id),
);
const guildMember = cachedMember?.guilds.get(guild.id);
const newMemberData = {
...payload,
@@ -23,7 +30,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
};
const discordenoMember = await structures.createDiscordenoMember(
newMemberData,
payload.guildId,
guild.id,
);
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
@@ -48,7 +55,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
"loop",
`1. Running forEach loop in GUILD_MEMBER_UPDATE file.`,
);
if (!payload.roles.includes(id)) {
if (!payload.roles.includes(bigintToSnowflake(id))) {
eventHandlers.roleLost?.(guild, discordenoMember, id);
}
});
@@ -58,8 +65,12 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
"loop",
`2. Running forEach loop in GUILD_MEMBER_UPDATE file.`,
);
if (!roleIds.includes(id)) {
eventHandlers.roleGained?.(guild, discordenoMember, id);
if (!roleIds.includes(snowflakeToBigint(id))) {
eventHandlers.roleGained?.(
guild,
discordenoMember,
snowflakeToBigint(id),
);
}
});
}

View File

@@ -4,14 +4,18 @@ import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { Message } from "../../types/messages/message.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageCreate(data: DiscordGatewayPayload) {
const payload = data.d as Message;
const channel = await cacheHandlers.get("channels", payload.channelId);
if (channel) channel.lastMessageId = payload.id;
const channel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.channelId),
);
if (channel) channel.lastMessageId = snowflakeToBigint(payload.id);
const guild = payload.guildId
? await cacheHandlers.get("guilds", payload.guildId)
? await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId))
: undefined;
if (payload.member && guild) {
@@ -34,7 +38,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
return cacheHandlers.set(
"members",
mention.id,
snowflakeToBigint(mention.id),
discordenoMember,
);
}
@@ -45,7 +49,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
data.d as Message,
);
// Cache the message
await cacheHandlers.set("messages", payload.id, message);
await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message);
eventHandlers.messageCreate?.(message);
}

View File

@@ -2,16 +2,20 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { MessageDelete } from "../../types/messages/message_delete.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageDelete(data: DiscordGatewayPayload) {
const payload = data.d as MessageDelete;
const channel = await cacheHandlers.get("channels", payload.channelId);
const channel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.channelId),
);
if (!channel) return;
eventHandlers.messageDelete?.(
{ id: payload.id, channel },
await cacheHandlers.get("messages", payload.id),
await cacheHandlers.get("messages", snowflakeToBigint(payload.id)),
);
await cacheHandlers.delete("messages", payload.id);
await cacheHandlers.delete("messages", snowflakeToBigint(payload.id));
}

View File

@@ -2,17 +2,21 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
const payload = data.d as MessageDeleteBulk;
const channel = await cacheHandlers.get("channels", payload.channelId);
const channel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.channelId),
);
if (!channel) return;
return Promise.all(payload.ids.map(async (id) => {
eventHandlers.messageDelete?.(
{ id, channel },
await cacheHandlers.get("messages", id),
await cacheHandlers.get("messages", snowflakeToBigint(id)),
);
await cacheHandlers.delete("messages", id);
await cacheHandlers.delete("messages", snowflakeToBigint(id));
}));
}

View File

@@ -5,11 +5,15 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import {
MessageReactionAdd,
} from "../../types/messages/message_reaction_add.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
const payload = data.d as MessageReactionAdd;
const message = await cacheHandlers.get("messages", payload.messageId);
const message = await cacheHandlers.get(
"messages",
snowflakeToBigint(payload.messageId),
);
if (message) {
const reactionExisted = message.reactions?.find(
@@ -22,7 +26,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
else {
const newReaction = {
count: 1,
me: payload.userId === botId,
me: snowflakeToBigint(payload.userId) === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions
@@ -30,11 +34,18 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
: [newReaction];
}
await cacheHandlers.set("messages", payload.messageId, message);
await cacheHandlers.set(
"messages",
snowflakeToBigint(payload.messageId),
message,
);
}
if (payload.member && payload.guildId) {
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (guild) {
const discordenoMember = await structures.createDiscordenoMember(
payload.member,

View File

@@ -4,12 +4,16 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import {
MessageReactionRemove,
} from "../../types/messages/message_reaction_remove.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageReactionRemove(
data: DiscordGatewayPayload,
) {
const payload = data.d as MessageReactionRemove;
const message = await cacheHandlers.get("messages", payload.messageId);
const message = await cacheHandlers.get(
"messages",
snowflakeToBigint(payload.messageId),
);
if (message) {
const reaction = message.reactions?.find((reaction) =>
@@ -25,7 +29,7 @@ export async function handleMessageReactionRemove(
}
if (!message.reactions?.length) message.reactions = undefined;
await cacheHandlers.set("messages", payload.messageId, message);
await cacheHandlers.set("messages", message.id, message);
}
}

View File

@@ -4,17 +4,25 @@ import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import {
MessageReactionRemoveAll,
} from "../../types/messages/message_reaction_remove_all.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageReactionRemoveAll(
data: DiscordGatewayPayload,
) {
const payload = data.d as MessageReactionRemoveAll;
const message = await cacheHandlers.get("messages", payload.messageId);
const message = await cacheHandlers.get(
"messages",
snowflakeToBigint(payload.messageId),
);
if (message?.reactions) {
message.reactions = undefined;
await cacheHandlers.set("messages", payload.messageId, message);
await cacheHandlers.set(
"messages",
snowflakeToBigint(payload.messageId),
message,
);
}
eventHandlers.reactionRemoveAll?.(

View File

@@ -2,12 +2,16 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageReactionRemoveEmoji(
data: DiscordGatewayPayload,
) {
const payload = data.d as MessageReactionRemoveEmoji;
const message = await cacheHandlers.get("messages", payload.messageId);
const message = await cacheHandlers.get(
"messages",
snowflakeToBigint(payload.messageId),
);
if (message?.reactions) {
message.reactions = message.reactions.filter(
@@ -21,13 +25,13 @@ export async function handleMessageReactionRemoveEmoji(
if (!message.reactions.length) message.reactions = undefined;
await cacheHandlers.set("messages", payload.messageId, message);
await cacheHandlers.set("messages", message.id, message);
}
eventHandlers.reactionRemoveEmoji?.(
payload.emoji,
payload.messageId,
payload.channelId,
payload.guildId,
snowflakeToBigint(payload.messageId),
snowflakeToBigint(payload.channelId),
payload.guildId ? snowflakeToBigint(payload.guildId) : undefined,
);
}

View File

@@ -3,13 +3,20 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { Message } from "../../types/messages/message.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
const payload = data.d as Message;
const channel = await cacheHandlers.get("channels", payload.channelId);
const channel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.channelId),
);
if (!channel) return;
const oldMessage = await cacheHandlers.get("messages", payload.id);
const oldMessage = await cacheHandlers.get(
"messages",
snowflakeToBigint(payload.id),
);
if (!oldMessage) return;
// Messages with embeds can trigger update but they wont have edited_timestamp
@@ -22,7 +29,7 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) {
const message = await structures.createDiscordenoMessage(payload);
await cacheHandlers.set("messages", payload.id, message);
await cacheHandlers.set("messages", snowflakeToBigint(payload.id), message);
eventHandlers.messageUpdate?.(message, oldMessage);
}

View File

@@ -2,12 +2,20 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { PresenceUpdate } from "../../types/misc/presence_update.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
const payload = data.d as PresenceUpdate;
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
await cacheHandlers.set("presences", payload.user.id, payload);
const oldPresence = await cacheHandlers.get(
"presences",
snowflakeToBigint(payload.user.id),
);
await cacheHandlers.set(
"presences",
snowflakeToBigint(payload.user.id),
payload,
);
eventHandlers.presenceUpdate?.(payload, oldPresence);
}

View File

@@ -5,6 +5,7 @@ import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { Ready } from "../../types/gateway/ready.ts";
import { GuildMemberWithUser } from "../../types/mod.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { ws } from "../../ws/ws.ts";
export function handleReady(
@@ -29,7 +30,9 @@ export function handleReady(
// Set ready to false just to go sure
shard.ready = false;
// All guilds are unavailable at first
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
shard.unavailableGuildIds = new Set(
payload.guilds.map((g) => snowflakeToBigint(g.id)),
);
// Start ready check in 2 seconds
setTimeout(async () => {

View File

@@ -2,11 +2,15 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { User } from "../../types/users/user.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleUserUpdate(data: DiscordGatewayPayload) {
const userData = data.d as User;
const member = await cacheHandlers.get("members", userData.id);
const member = await cacheHandlers.get(
"members",
snowflakeToBigint(userData.id),
);
if (!member) return;
Object.entries(userData).forEach(([key, value]) => {
@@ -18,7 +22,7 @@ export async function handleUserUpdate(data: DiscordGatewayPayload) {
if (member[key] !== value) return member[key] = value;
});
await cacheHandlers.set("members", userData.id, member);
await cacheHandlers.set("members", snowflakeToBigint(userData.id), member);
eventHandlers.botUpdate?.(userData);
}

View File

@@ -3,15 +3,22 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildRoleCreate } from "../../types/mod.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
const payload = data.d as GuildRoleCreate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const role = await structures.createDiscordenoRole(payload);
guild.roles = guild.roles.set(payload.role.id, role);
await cacheHandlers.set("guilds", payload.guildId, guild);
const role = await structures.createDiscordenoRole({
...payload,
guildId: guild.id,
});
guild.roles = guild.roles.set(snowflakeToBigint(payload.role.id), role);
await cacheHandlers.set("guilds", guild.id, guild);
eventHandlers.roleCreate?.(guild, role);
}

View File

@@ -2,14 +2,20 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
const payload = data.d as GuildRoleDelete;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const cachedRole = guild.roles.get(payload.roleId)!;
guild.roles.delete(payload.roleId);
const roleId = snowflakeToBigint(payload.roleId);
const cachedRole = guild.roles.get(roleId)!;
guild.roles.delete(roleId);
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
@@ -28,9 +34,9 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
`2. Running forEach loop in CHANNEL_DELTE file.`,
);
// Member does not have this role
if (!g.roles.includes(payload.roleId)) return;
if (!g.roles.includes(roleId)) return;
// Remove this role from the members cache
g.roles = g.roles.filter((id) => id !== payload.roleId);
g.roles = g.roles.filter((id) => id !== roleId);
cacheHandlers.set("members", member.id, member);
});
});

View File

@@ -3,17 +3,24 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { GuildRoleUpdate } from "../../types/mod.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
const payload = data.d as GuildRoleUpdate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const cachedRole = guild.roles.get(payload.role.id);
const cachedRole = guild.roles.get(snowflakeToBigint(payload.role.id));
if (!cachedRole) return;
const role = await structures.createDiscordenoRole(payload);
guild.roles.set(payload.role.id, role);
const role = await structures.createDiscordenoRole({
...payload,
guildId: guild.id,
});
guild.roles.set(snowflakeToBigint(payload.role.id), role);
await cacheHandlers.set("guilds", guild.id, guild);
eventHandlers.roleUpdate?.(guild, role, cachedRole);

View File

@@ -2,11 +2,15 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) {
const payload = data.d as VoiceServerUpdate;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
eventHandlers.voiceServerUpdate?.(payload, guild);

View File

@@ -3,13 +3,16 @@ import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { VoiceState } from "../../types/voice/voice_state.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
const payload = data.d as VoiceState;
if (!payload.guildId) return;
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get(
"guilds",
snowflakeToBigint(payload.guildId),
);
if (!guild) return;
const member = payload.member
@@ -17,34 +20,40 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
payload.member,
guild.id,
)
: await cacheHandlers.get("members", payload.userId);
: await cacheHandlers.get("members", snowflakeToBigint(payload.userId));
if (!member) return;
// No cached state before so lets make one for em
const cachedState = guild.voiceStates.get(payload.userId);
const cachedState = guild.voiceStates.get(snowflakeToBigint(payload.userId));
guild.voiceStates.set(
payload.userId,
payload,
snowflakeToBigint(payload.userId),
await structures.createDiscordenoVoiceState(guild.id, payload),
);
await cacheHandlers.set("guilds", payload.guildId, guild);
await cacheHandlers.set("guilds", guild.id, guild);
if (cachedState?.channelId !== payload.channelId) {
if (
cachedState?.channelId !==
(payload.channelId ? snowflakeToBigint(payload.channelId) : null)
) {
// Either joined or moved channels
if (payload.channelId) {
if (cachedState?.channelId) { // Was in a channel before
eventHandlers.voiceChannelSwitch?.(
member,
payload.channelId,
snowflakeToBigint(payload.channelId),
cachedState.channelId,
);
} else { // Was not in a channel before so user just joined
eventHandlers.voiceChannelJoin?.(member, payload.channelId);
eventHandlers.voiceChannelJoin?.(
member,
snowflakeToBigint(payload.channelId),
);
}
} // Left the channel
else if (cachedState?.channelId) {
guild.voiceStates.delete(payload.userId);
guild.voiceStates.delete(snowflakeToBigint(payload.userId));
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
}
}

View File

@@ -1,11 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export function handleWebhooksUpdate(data: DiscordGatewayPayload) {
const options = data.d as WebhookUpdate;
eventHandlers.webhooksUpdate?.(
options.channelId,
options.guildId,
snowflakeToBigint(options.channelId),
snowflakeToBigint(options.guildId),
);
}

View File

@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
/** Gets an array of all the channels ids that are the children of this category. */
export function categoryChildren(id: string) {
export function categoryChildren(id: bigint) {
return cacheHandlers.filter(
"channels",
(channel) => channel.parentId === id,

View File

@@ -4,9 +4,13 @@ import { PermissionStrings } from "../../types/permissions/permission_strings.ts
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
export function channelOverwriteHasPermission(
guildId: string,
id: string,
overwrites: DiscordOverwrite[],
guildId: bigint,
id: bigint,
overwrites: (Omit<DiscordOverwrite, "id" | "allow" | "deny"> & {
id: bigint;
allow: bigint;
deny: bigint;
})[],
permissions: PermissionStrings[],
) {
const overwrite = overwrites.find((perm) => perm.id === id) ||

View File

@@ -2,11 +2,12 @@ import { cacheHandlers } from "../../cache.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
import { Errors } from "../../types/misc/errors.ts";
import { bigintToSnowflake } from "../../util/bigint.ts";
import { calculatePermissions } from "../../util/permissions.ts";
import { createChannel } from "./create_channel.ts";
/** Create a copy of a channel */
export async function cloneChannel(channelId: string, reason?: string) {
export async function cloneChannel(channelId: bigint, reason?: string) {
const channelToClone = await cacheHandlers.get("channels", channelId);
//Return undefined if channel is not cached
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
@@ -23,14 +24,16 @@ export async function cloneChannel(channelId: string, reason?: string) {
...channelToClone,
name: channelToClone.name!,
topic: channelToClone.topic || undefined,
parentId: channelToClone.parentId || undefined,
parentId: channelToClone.parentId
? bigintToSnowflake(channelToClone.parentId)
: undefined,
permissionOverwrites: channelToClone.permissionOverwrites.map((
overwrite,
) => ({
id: overwrite.id,
id: overwrite.id.toString(),
type: overwrite.type,
allow: calculatePermissions(overwrite.allow),
deny: calculatePermissions(overwrite.deny),
allow: calculatePermissions(overwrite.allow.toString()),
deny: calculatePermissions(overwrite.deny.toString()),
})),
};

View File

@@ -18,7 +18,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createChannel(
guildId: string,
guildId: bigint,
options?: CreateGuildChannel,
reason?: string,
) {

View File

@@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function deleteChannel(
guildId: string,
channelId: string,
guildId: bigint,
channelId: bigint,
reason?: string,
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]);

View File

@@ -4,9 +4,9 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function deleteChannelOverwrite(
guildId: string,
channelId: string,
overwriteId: string,
guildId: bigint,
channelId: bigint,
overwriteId: bigint,
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);

View File

@@ -10,7 +10,7 @@ import {
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editChannel(
channelId: string,
channelId: bigint,
options: ModifyChannel,
reason?: string,
) {
@@ -72,14 +72,14 @@ export async function editChannel(
interface EditChannelRequest {
amount: number;
timestamp: number;
channelId: string;
channelId: bigint;
items: {
channelId: string;
channelId: bigint;
options: ModifyChannel;
}[];
}
const editChannelNameTopicQueue = new Map<string, EditChannelRequest>();
const editChannelNameTopicQueue = new Map<bigint, EditChannelRequest>();
let editChannelProcessing = false;
function processEditChannelQueue() {

View File

@@ -8,9 +8,9 @@ import {
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function editChannelOverwrite(
guildId: string,
channelId: string,
overwriteId: string,
guildId: bigint,
channelId: bigint,
overwriteId: bigint,
options: Omit<Overwrite, "id">,
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);

View File

@@ -5,8 +5,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
export async function followChannel(
sourceChannelId: string,
targetChannelId: string,
sourceChannelId: bigint,
targetChannelId: bigint,
) {
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);

View File

@@ -2,13 +2,14 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Channel } from "../../types/channels/channel.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { endpoints } from "../../util/constants.ts";
/** Fetches a single channel object from the api.
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(channelId: string, addToCache = true) {
export async function getChannel(channelId: bigint, addToCache = true) {
const result = await rest.runMethod<Channel>(
"get",
endpoints.CHANNEL_BASE(channelId),
@@ -16,7 +17,7 @@ export async function getChannel(channelId: string, addToCache = true) {
const discordenoChannel = await structures.createDiscordenoChannel(
result,
result.guildId,
result.guildId ? snowflakeToBigint(result.guildId) : undefined,
);
if (addToCache) {
await cacheHandlers.set(

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
export async function getChannelWebhooks(channelId: string) {
export async function getChannelWebhooks(channelId: bigint) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result = await rest.runMethod<Webhook[]>(

View File

@@ -9,7 +9,7 @@ import { endpoints } from "../../util/constants.ts";
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannels(guildId: string, addToCache = true) {
export async function getChannels(guildId: bigint, addToCache = true) {
const result = await rest.runMethod<Channel[]>(
"get",
endpoints.GUILD_CHANNELS(guildId),

View File

@@ -4,7 +4,7 @@ import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
/** Get pinned messages in this channel. */
export async function getPins(channelId: string) {
export async function getPins(channelId: bigint) {
const result = await rest.runMethod<Message[]>(
"get",
endpoints.CHANNEL_PINS(channelId),

View File

@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
/** Checks whether a channel is synchronized with its parent/category channel or not. */
export async function isChannelSynced(channelId: string) {
export async function isChannelSynced(channelId: bigint) {
const channel = await cacheHandlers.get("channels", channelId);
if (!channel?.parentId) return false;

View File

@@ -10,7 +10,7 @@ import { botHasChannelPermissions } from "../../util/permissions.ts";
* However, if a bot is responding to a command and expects the computation to take a few seconds,
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(channelId: string) {
export async function startTyping(channelId: bigint) {
const channel = await cacheHandlers.get("channels", channelId);
// If the channel is cached, we can do extra checks/safety
if (channel) {

View File

@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
export async function swapChannels(
guildId: string,
guildId: bigint,
channelPositions: ModifyGuildChannelPositions[],
) {
if (channelPositions.length < 2) {

View File

@@ -6,7 +6,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
export async function batchEditSlashCommandPermissions(
guildId: string,
guildId: bigint,
options: { id: string; permissions: ApplicationCommandPermissions[] }[],
) {
return await rest.runMethod(

View File

@@ -21,7 +21,7 @@ import {
*/
export async function createSlashCommand(
options: CreateGlobalApplicationCommand,
guildId?: string,
guildId?: bigint,
) {
validateSlashCommands([options], true);

View File

@@ -4,8 +4,8 @@ import { endpoints } from "../../util/constants.ts";
/** Deletes a slash command. */
export async function deleteSlashCommand(
id: string,
guildId?: string,
id: bigint,
guildId?: bigint,
) {
return await rest.runMethod<undefined>(
"delete",

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
/** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */
export async function deleteSlashResponse(
token: string,
messageId?: string,
messageId?: bigint,
) {
return await rest.runMethod<undefined>(
"delete",

View File

@@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Edits command permissions for a specific command for your application in a guild. */
export async function editSlashCommandPermissions(
guildId: string,
commandId: string,
guildId: bigint,
commandId: bigint,
options: ApplicationCommandPermissions[],
) {
return await rest.runMethod(

View File

@@ -4,7 +4,7 @@ import { ApplicationCommand } from "../../types/interactions/application_command
import { endpoints } from "../../util/constants.ts";
/** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
export async function getSlashCommand(commandId: string, guildId?: string) {
export async function getSlashCommand(commandId: bigint, guildId?: bigint) {
return await rest.runMethod<ApplicationCommand>(
"get",
guildId

View File

@@ -5,8 +5,8 @@ import { endpoints } from "../../util/constants.ts";
/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */
export async function getSlashCommandPermission(
guildId: string,
commandId: string,
guildId: bigint,
commandId: bigint,
) {
return await rest.runMethod<GuildApplicationCommandPermissions>(
"get",

View File

@@ -4,7 +4,7 @@ import { GuildApplicationCommandPermissions } from "../../types/interactions/gui
import { endpoints } from "../../util/constants.ts";
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
export async function getSlashCommandPermissions(guildId: string) {
export async function getSlashCommandPermissions(guildId: bigint) {
return await rest.runMethod<GuildApplicationCommandPermissions[]>(
"get",
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),

View File

@@ -5,7 +5,7 @@ import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
/** Fetch all of the global commands for your application. */
export async function getSlashCommands(guildId?: string) {
export async function getSlashCommands(guildId?: bigint) {
const result = await rest.runMethod<ApplicationCommand[]>(
"get",
guildId

View File

@@ -11,7 +11,7 @@ import { endpoints } from "../../util/constants.ts";
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
*/
export async function sendInteractionResponse(
id: string,
id: bigint,
token: string,
options: DiscordenoInteractionResponse,
) {
@@ -27,7 +27,7 @@ export async function sendInteractionResponse(
}
// Expire in 15 minutes
cache.executedSlashCommands.set(token, id);
cache.executedSlashCommands.add(token);
setTimeout(
() => {
eventHandlers.debug?.(

View File

@@ -9,9 +9,9 @@ import { validateSlashCommands } from "../../util/utils.ts";
* Edit an existing slash command. If this command did not exist, it will create it.
*/
export async function upsertSlashCommand(
commandId: string,
commandId: bigint,
options: EditGlobalApplicationCommand,
guildId?: string,
guildId?: bigint,
) {
validateSlashCommands([options]);

View File

@@ -12,7 +12,7 @@ import { validateSlashCommands } from "../../util/utils.ts";
*/
export async function upsertSlashCommands(
options: EditGlobalApplicationCommand[],
guildId?: string,
guildId?: bigint,
) {
validateSlashCommands(options);

View File

@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
export async function addDiscoverySubcategory(
guildId: string,
guildId: bigint,
categoryId: number,
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);

View File

@@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
export async function editDiscovery(
guildId: string,
guildId: bigint,
data: ModifyGuildDiscoveryMetadata,
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);

View File

@@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */
export async function removeDiscoverySubcategory(
guildId: string,
guildId: bigint,
categoryId: number,
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);

View File

@@ -1,13 +1,14 @@
import { rest } from "../../rest/rest.ts";
import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts";
import { Emoji } from "../../types/emojis/emoji.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts";
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
export async function createEmoji(
guildId: string,
guildId: bigint,
name: string,
image: string,
options: CreateGuildEmoji,
@@ -18,9 +19,18 @@ export async function createEmoji(
image = await urlToBase64(image);
}
return await rest.runMethod<Emoji>("post", endpoints.GUILD_EMOJIS(guildId), {
...options,
name,
image,
});
const emoji = await rest.runMethod<Emoji>(
"post",
endpoints.GUILD_EMOJIS(guildId),
{
...options,
name,
image,
},
);
return {
...emoji,
id: snowflakeToBigint(emoji.id!),
};
}

View File

@@ -4,8 +4,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
export async function deleteEmoji(
guildId: string,
id: string,
guildId: bigint,
id: bigint,
reason?: string,
) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);

View File

@@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
export async function editEmoji(
guildId: string,
id: string,
guildId: bigint,
id: bigint,
options: ModifyGuildEmoji,
) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);

View File

@@ -1,4 +1,4 @@
/** Creates a url to the emoji from the Discord CDN. */
export function emojiURL(id: string, animated = false) {
export function emojiURL(id: bigint, animated = false) {
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`;
}

View File

@@ -10,8 +10,8 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
*/
export async function getEmoji(
guildId: string,
emojiId: string,
guildId: bigint,
emojiId: bigint,
addToCache = true,
) {
const result = await rest.runMethod<Emoji>(

View File

@@ -3,6 +3,7 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { Emoji } from "../../types/emojis/emoji.ts";
import { Errors } from "../../types/misc/errors.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
@@ -11,7 +12,7 @@ import { endpoints } from "../../util/constants.ts";
*
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
*/
export async function getEmojis(guildId: string, addToCache = true) {
export async function getEmojis(guildId: bigint, addToCache = true) {
const result = await rest.runMethod<Emoji[]>(
"get",
endpoints.GUILD_EMOJIS(guildId),
@@ -26,7 +27,7 @@ export async function getEmojis(guildId: string, addToCache = true) {
"loop",
`Running forEach loop in get_emojis file.`,
);
guild.emojis.set(emoji.id!, emoji);
guild.emojis.set(snowflakeToBigint(emoji.id!), emoji);
});
await cacheHandlers.set("guilds", guildId, guild);

View File

@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
import { endpoints } from "../../util/constants.ts";
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
export async function deleteGuild(guildId: string) {
export async function deleteGuild(guildId: bigint) {
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILDS_BASE(guildId),

View File

@@ -9,7 +9,7 @@ import { urlToBase64 } from "../../util/utils.ts";
import { ws } from "../../ws/ws.ts";
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
export async function editGuild(guildId: string, options: ModifyGuild) {
export async function editGuild(guildId: bigint, options: ModifyGuild) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
if (options.icon && !options.icon.startsWith("data:image/")) {

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
export async function editWelcomeScreen(
guildId: string,
guildId: bigint,
options: ModifyGuildWelcomeScreen,
) {
return await rest.runMethod<WelcomeScreen>(

View File

@@ -5,7 +5,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
export async function editWidget(
guildId: string,
guildId: bigint,
enabled: boolean,
channelId?: string | null,
) {

View File

@@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
export async function getAuditLogs(
guildId: string,
guildId: bigint,
options: GetGuildAuditLog,
) {
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);

View File

@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */
export async function getBan(guildId: string, memberId: string) {
export async function getBan(guildId: bigint, memberId: bigint) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
return await rest.runMethod<Ban>(

View File

@@ -1,11 +1,12 @@
import { rest } from "../../rest/rest.ts";
import { Ban } from "../../types/guilds/ban.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
export async function getBans(guildId: string) {
export async function getBans(guildId: bigint) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const results = await rest.runMethod<Ban[]>(
@@ -13,7 +14,7 @@ export async function getBans(guildId: string) {
endpoints.GUILD_BANS(guildId),
);
return new Collection<string, Ban>(
results.map((res) => [res.user.id, res]),
return new Collection<bigint, Ban>(
results.map((res) => [snowflakeToBigint(res.user.id), res]),
);
}

View File

@@ -13,7 +13,7 @@ import { ws } from "../../ws/ws.ts";
* So it does not cache the guild, you must do it manually.
* */
export async function getGuild(
guildId: string,
guildId: bigint,
options: { counts?: boolean; addToCache?: boolean } = {
counts: true,
addToCache: true,
@@ -27,14 +27,14 @@ export async function getGuild(
},
);
const structure = await structures.createDiscordenoGuild(
const guild = await structures.createDiscordenoGuild(
result,
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
);
if (options.addToCache) {
await cacheHandlers.set("guilds", guildId, structure);
await cacheHandlers.set("guilds", guild.id, guild);
}
return structure;
return guild;
}

View File

@@ -3,7 +3,7 @@ import { GuildPreview } from "../../types/guilds/guild_preview.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
export async function getGuildPreview(guildId: string) {
export async function getGuildPreview(guildId: bigint) {
return await rest.runMethod<GuildPreview>(
"get",
endpoints.GUILD_PREVIEW(guildId),

View File

@@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
export async function getPruneCount(
guildId: string,
guildId: bigint,
options?: GetGuildPruneCountQuery,
) {
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);

View File

@@ -3,7 +3,7 @@ import { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
export async function getVanityURL(guildId: string) {
export async function getVanityURL(guildId: bigint) {
return await rest.runMethod<
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
code: null;

View File

@@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
export async function getVoiceRegions(guildId: string) {
export async function getVoiceRegions(guildId: bigint) {
const result = await rest.runMethod<VoiceRegion[]>(
"get",
endpoints.GUILD_REGIONS(guildId),

View File

@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
import { WelcomeScreen } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
export async function getWelcomeScreen(guildId: string) {
export async function getWelcomeScreen(guildId: bigint) {
return await rest.runMethod<WelcomeScreen>(
"get",
endpoints.GUILD_WELCOME_SCREEN(guildId),

View File

@@ -5,7 +5,7 @@ import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns the widget for the guild. */
export async function getWidget(guildId: string, options?: { force: boolean }) {
export async function getWidget(guildId: bigint, options?: { force: boolean }) {
if (!options?.force) {
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
/** Returns the widget image URL for the guild. */
export async function getWidgetImageURL(
guildId: string,
guildId: bigint,
options?: GetGuildWidgetImageQuery & { force?: boolean },
) {
if (!options?.force) {

View File

@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
export async function getWidgetSettings(guildId: string) {
export async function getWidgetSettings(guildId: bigint) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<GuildWidget>(

View File

@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
/** The full URL of the banner from Discords CDN. Undefined if no banner is set. */
export function guildBannerURL(
id: string,
id: bigint,
banner?: string,
size: DiscordImageSize = 128,
format?: DiscordImageFormat,

View File

@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
export function guildIconURL(
id: string,
id: bigint,
icon?: string,
size: DiscordImageSize = 128,
format?: DiscordImageFormat,

View File

@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
/** The full URL of the splash from Discords CDN. Undefined if no splash is set. */
export function guildSplashURL(
id: string,
id: bigint,
splash?: string,
size: DiscordImageSize = 128,
format?: DiscordImageFormat,

View File

@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
import { endpoints } from "../../util/constants.ts";
/** Leave a guild */
export async function leaveGuild(guildId: string) {
export async function leaveGuild(guildId: bigint) {
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_LEAVE(guildId),

View File

@@ -16,7 +16,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
* - You are able to set `request_to_speak_timestamp` to any present or future time.
*/
export function updateBotVoiceState(
guildId: string,
guildId: bigint,
data: UpdateSelfVoiceState,
) {
const payload = camelKeysToSnakeCase<DiscordUpdateSelfVoiceState>(data);

View File

@@ -16,8 +16,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
* - When suppressed, the user will have their `request_to_speak_timestamp` removed.
*/
export function updateVoiceState(
guildId: string,
userId: string,
guildId: bigint,
userId: bigint,
data: UpdateOthersVoiceState,
) {
const payload = camelKeysToSnakeCase<DiscordUpdateOthersVoiceState>(data);

View File

@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */
export async function deleteIntegration(guildId: string, id: string) {
export async function deleteIntegration(guildId: bigint, id: bigint) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<undefined>(

View File

@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
export async function getIntegrations(guildId: string) {
export async function getIntegrations(guildId: bigint) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await rest.runMethod<Integration>(

View File

@@ -7,7 +7,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
export async function createInvite(
channelId: string,
channelId: bigint,
options: CreateChannelInvite,
) {
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);

View File

@@ -9,7 +9,7 @@ import {
} from "../../util/permissions.ts";
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
export async function deleteInvite(channelId: string, inviteCode: string) {
export async function deleteInvite(channelId: bigint, inviteCode: string) {
const channel = await cacheHandlers.get("channels", channelId);
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
export async function getChannelInvites(channelId: string) {
export async function getChannelInvites(channelId: bigint) {
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
const result = await rest.runMethod<Invite[]>(

View File

@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
export async function getInvites(guildId: string) {
export async function getInvites(guildId: bigint) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod<Invite[]>(

View File

@@ -5,8 +5,8 @@ import { formatImageURL } from "../../util/utils.ts";
/** The users custom avatar or the default avatar if you don't have a member object. */
export function avatarURL(
userId: string,
discriminator: string,
userId: bigint,
discriminator: bigint,
avatar?: string | null,
size: DiscordImageSize = 128,
format?: DiscordImageFormat,

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