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
+1 -1
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,
@@ -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) ||
+8 -5
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()),
})),
};
+1 -1
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,
) {
+2 -2
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"]);
@@ -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"]);
+4 -4
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() {
@@ -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"]);
+2 -2
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"]);
+3 -2
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(
+1 -1
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[]>(
+1 -1
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),
+1 -1
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),
+1 -1
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;
+1 -1
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) {
+1 -1
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) {