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
+2 -2
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,
+2 -2
View File
@@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
export async function ban(
guildId: string,
id: string,
guildId: bigint,
id: bigint,
options: CreateGuildBan,
) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
+1 -1
View File
@@ -1,6 +1,6 @@
import { editMember } from "./edit_member.ts";
/** Kicks a member from a voice channel */
export function disconnectMember(guildId: string, memberId: string) {
export function disconnectMember(guildId: bigint, memberId: bigint) {
return editMember(guildId, memberId, { channelId: null });
}
+1 -1
View File
@@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Edit the nickname of the bot in this guild */
export async function editBotNickname(
guildId: string,
guildId: bigint,
nickname: string | null,
) {
await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]);
+10 -4
View File
@@ -5,6 +5,7 @@ import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { Errors } from "../../types/misc/errors.ts";
import { ModifyGuildMember } from "../../types/mod.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import { bigintToSnowflake } from "../../util/bigint.ts";
import { endpoints } from "../../util/constants.ts";
import {
requireBotChannelPermissions,
@@ -14,9 +15,9 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Edit the member */
export async function editMember(
guildId: string,
memberId: string,
options: ModifyGuildMember,
guildId: bigint,
memberId: bigint,
options: Omit<ModifyGuildMember, "channelId"> & { channelId?: bigint | null },
) {
const requiredPerms: Set<PermissionStrings> = new Set();
@@ -72,7 +73,12 @@ export async function editMember(
const result = await rest.runMethod<GuildMemberWithUser>(
"patch",
endpoints.GUILD_MEMBER(guildId, memberId),
camelKeysToSnakeCase(options),
camelKeysToSnakeCase({
...options,
channelId: options.channelId
? bigintToSnowflake(options.channelId)
: undefined,
}) as ModifyGuildMember,
);
const member = await structures.createDiscordenoMember(
+2 -2
View File
@@ -17,7 +17,7 @@ import { ws } from "../../ws/ws.ts";
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
*/
export function fetchMembers(
guildId: string,
guildId: bigint,
shardId: number,
options?: Omit<RequestGuildMembers, "guildId">,
) {
@@ -49,5 +49,5 @@ export function fetchMembers(
nonce,
},
});
}) as Promise<Collection<string, DiscordenoMember>>;
}) as Promise<Collection<bigint, DiscordenoMember>>;
}
+2 -2
View File
@@ -9,8 +9,8 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
*/
export async function getMember(
guildId: string,
id: string,
guildId: bigint,
id: bigint,
options?: { force?: boolean },
) {
const guild = await cacheHandlers.get("guilds", guildId);
+6 -3
View File
@@ -7,6 +7,7 @@ import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts";
import { Errors } from "../../types/misc/errors.ts";
import { bigintToSnowflake } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { ws } from "../../ws/ws.ts";
@@ -20,7 +21,7 @@ import { ws } from "../../ws/ws.ts";
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
*/
export async function getMembers(
guildId: string,
guildId: bigint,
options?: ListGuildMembers & { addToCache?: boolean },
) {
if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
@@ -30,7 +31,7 @@ export async function getMembers(
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
const members = new Collection<string, DiscordenoMember>();
const members = new Collection<bigint, DiscordenoMember>();
let membersLeft = options?.limit ?? guild.memberCount;
let loops = 1;
@@ -88,7 +89,9 @@ export async function getMembers(
options = {
limit: options?.limit,
after: discordenoMembers[discordenoMembers.length - 1].id,
after: bigintToSnowflake(
discordenoMembers[discordenoMembers.length - 1].id,
),
};
membersLeft -= 1000;
+1 -1
View File
@@ -8,7 +8,7 @@ import {
} from "../../util/permissions.ts";
/** Kick a member from the server */
export async function kick(guildId: string, memberId: string, reason?: string) {
export async function kick(guildId: bigint, memberId: bigint, reason?: string) {
const botsHighestRole = await highestRole(guildId, botId);
const membersHighestRole = await highestRole(guildId, memberId);
if (
+3 -3
View File
@@ -7,9 +7,9 @@ import { editMember } from "./edit_member.ts";
* @param channelId id of channel to move user to (if they are connected to voice)
*/
export function moveMember(
guildId: string,
memberId: string,
channelId: string,
guildId: bigint,
memberId: bigint,
channelId: bigint,
) {
return editMember(guildId, memberId, { channelId });
}
+1 -1
View File
@@ -11,7 +11,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
* By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the roles (resolved to include_roles internally) parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not.
*/
export async function pruneMembers(
guildId: string,
guildId: bigint,
options: BeginGuildPrune,
) {
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
+2 -2
View File
@@ -13,7 +13,7 @@ import { endpoints } from "../../util/constants.ts";
* @param query Query string to match username(s) and nickname(s) against
*/
export async function searchMembers(
guildId: string,
guildId: bigint,
query: string,
options?: Omit<SearchGuildMembers, "query"> & { cache?: boolean },
) {
@@ -45,7 +45,7 @@ export async function searchMembers(
return discordenoMember;
}));
return new Collection<string, DiscordenoMember>(
return new Collection<bigint, DiscordenoMember>(
members.map((member) => [member.id, member]),
);
}
+1 -1
View File
@@ -8,7 +8,7 @@ import { sendMessage } from "../messages/send_message.ts";
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
export async function sendDirectMessage(
memberId: string,
memberId: bigint,
content: string | CreateMessage,
) {
let dmChannel = await cacheHandlers.get("channels", memberId);
+1 -1
View File
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
export async function unban(guildId: string, id: string) {
export async function unban(guildId: bigint, id: bigint) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
return await rest.runMethod<undefined>(