mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
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:
@@ -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),
|
||||
|
||||
@@ -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/")) {
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user