mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Moar - rip commit history
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
import { eventHandlers, identifyPayload } from "../../bot.ts";
|
import { eventHandlers, identifyPayload } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { Member, structures } from "../../structures/mod.ts";
|
import { DiscordenoMember } from "../../structures/member.ts";
|
||||||
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
|
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
|
||||||
import { DiscordGuildMember } from "../../types/guilds/guild_member.ts";
|
import {
|
||||||
|
DiscordGuildMemberWithUser,
|
||||||
|
GuildMember,
|
||||||
|
} from "../../types/guilds/guild_member.ts";
|
||||||
|
import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -16,7 +21,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* REST(this function): 50/s global(across all shards) rate limit with ALL requests this included
|
* REST(this function): 50/s global(across all shards) rate limit with ALL requests this included
|
||||||
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
|
* 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, options?: GetMemberOptions) {
|
export async function getMembers(guildId: string, options?: ListGuildMembers) {
|
||||||
if (!(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
|
if (!(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
|
||||||
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
||||||
}
|
}
|
||||||
@@ -24,7 +29,7 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
|
|||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
|
||||||
const members = new Collection<string, Member>();
|
const members = new Collection<string, DiscordenoMember>();
|
||||||
|
|
||||||
let membersLeft = options?.limit ?? guild.memberCount;
|
let membersLeft = options?.limit ?? guild.memberCount;
|
||||||
let loops = 1;
|
let loops = 1;
|
||||||
@@ -44,17 +49,17 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result: GuildMember[] = (await rest.runMethod(
|
||||||
"get",
|
"get",
|
||||||
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
|
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
|
||||||
membersLeft > 1000 ? 1000 : membersLeft
|
membersLeft > 1000 ? 1000 : membersLeft
|
||||||
}${options?.after ? `&after=${options.after}` : ""}`,
|
}${options?.after ? `&after=${options.after}` : ""}`,
|
||||||
)) as DiscordGuildMember[];
|
));
|
||||||
|
|
||||||
const discordenoMembers = await Promise.all(
|
const discordenoMembers = await Promise.all(
|
||||||
result.map(async (member) => {
|
result.map(async (member) => {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
member,
|
member as DiscordGuildMemberWithUser,
|
||||||
guildId,
|
guildId,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
|
|||||||
|
|
||||||
return discordenoMember;
|
return discordenoMember;
|
||||||
}),
|
}),
|
||||||
) as Member[];
|
) as DiscordenoMember[];
|
||||||
|
|
||||||
if (!discordenoMembers.length) break;
|
if (!discordenoMembers.length) break;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
@@ -11,7 +12,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
|||||||
*/
|
*/
|
||||||
export async function pruneMembers(
|
export async function pruneMembers(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
options: PruneOptions,
|
options: BeginGuildPrune,
|
||||||
) {
|
) {
|
||||||
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||||
if (options.days && options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS);
|
if (options.days && options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { User } from "../../types/users/user.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
@@ -7,13 +8,13 @@ export async function getReactions(
|
|||||||
channelId: string,
|
channelId: string,
|
||||||
messageId: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
options?: DiscordGetReactionsParams,
|
options?: DiscordGetReactions,
|
||||||
) {
|
) {
|
||||||
const users = (await rest.runMethod(
|
const users = (await rest.runMethod(
|
||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
options,
|
options,
|
||||||
)) as UserPayload[];
|
)) as User[];
|
||||||
|
|
||||||
return new Collection(users.map((user) => [user.id, user]));
|
return new Collection(users.map((user) => [user.id, user]));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user