fix: member helper perms

This commit is contained in:
Skillz4Killz
2021-12-08 20:17:49 +00:00
committed by GitHub
parent b422e6b62a
commit 854db909ae
8 changed files with 18 additions and 71 deletions
-6
View File
@@ -1,6 +0,0 @@
import type { Bot } from "../../bot.ts";
/** Kicks a member from a voice channel */
export function disconnectMember(bot: Bot, guildId: bigint, memberId: bigint) {
return bot.helpers.editMember(guildId, memberId, { channelId: null });
}
-1
View File
@@ -1,6 +1,5 @@
import type { ModifyGuildMember } from "../../types/guilds/modifyGuildMember.ts";
import type { GuildMemberWithUser } from "../../types/members/guildMember.ts";
import type { PermissionStrings } from "../../types/permissions/permissionStrings.ts";
import type { Bot } from "../../bot.ts";
/** Edit the member */
+1
View File
@@ -8,5 +8,6 @@ export async function getDmChannel(bot: Bot, userId: bigint) {
const dmChannelData = await bot.rest.runMethod<Channel>(bot.rest, "post", bot.constants.endpoints.USER_DM, {
recipient_id: userId.toString(),
});
return bot.transformers.channel(bot, { channel: dmChannelData });
}
+11 -37
View File
@@ -10,46 +10,20 @@ import type { DiscordenoMember } from "../../transformers/member.ts";
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
*/
export async function getMembers(bot: Bot, guildId: bigint, options: ListGuildMembers & { memberCount: number }) {
const members = new Collection<bigint, DiscordenoMember>();
let membersLeft = options?.limit ?? options.memberCount;
let loops = 1;
while ((options?.limit ?? options.memberCount) > members.size && membersLeft > 0) {
bot.events.debug("Running while loop in getMembers function.");
if (options?.limit && options.limit > 1000) {
console.log(`Paginating get members from REST. #${loops} / ${Math.ceil((options?.limit ?? 1) / 1000)}`);
}
const result = await bot.rest.runMethod<GuildMemberWithUser[]>(
bot.rest,
"get",
`${bot.constants.endpoints.GUILD_MEMBERS(guildId)}?limit=${membersLeft > 1000 ? 1000 : membersLeft}${
options?.after ? `&after=${options.after}` : ""
}`
);
const discordenoMembers = result.map((member) =>
bot.transformers.member(bot, member, guildId, bot.transformers.snowflake(member.user.id))
);
if (!discordenoMembers.length) break;
discordenoMembers.forEach((member) => {
bot.events.debug(`Running forEach loop in get_members file.`);
members.set(member.id, member);
});
options = {
limit: options?.limit,
after: discordenoMembers[discordenoMembers.length - 1].id.toString(),
memberCount: options.memberCount,
};
membersLeft -= 1000;
loops++;
bot.constants.endpoints.GUILD_MEMBERS(guildId),
{
limit: options?.limit ?? options.memberCount,
after: options?.after,
}
);
return members;
return new Collection(
result.map((res) => {
const member = bot.transformers.member(bot, res, guildId, bot.transformers.snowflake(res.user.id));
return [member.id, member];
})
);
}
-12
View File
@@ -1,12 +0,0 @@
import type { Bot } from "../../bot.ts";
/**
* Move a member from a voice channel to another.
* @param bot the bot
* @param guildId the id of the guild which the channel exists in
* @param memberId the id of the member to move.
* @param channelId id of channel to move user to (if they are connected to voice)
*/
export function moveMember(bot: Bot, guildId: bigint, memberId: bigint, channelId: bigint) {
return bot.helpers.editMember(guildId, memberId, { channelId });
}
+1 -1
View File
@@ -10,7 +10,7 @@ export async function searchMembers(
bot: Bot,
guildId: bigint,
query: string,
options?: Omit<SearchGuildMembers, "query"> & { cache?: boolean }
options?: Omit<SearchGuildMembers, "query">
) {
if (options?.limit) {
if (options.limit < 1) throw new Error(bot.constants.Errors.MEMBER_SEARCH_LIMIT_TOO_LOW);
-2
View File
@@ -86,14 +86,12 @@ export * from "./invites/getInvites.ts";
//members
export * from "./members/avatarUrl.ts";
export * from "./members/banMember.ts";
export * from "./members/disconnectMember.ts";
export * from "./members/editBotNickname.ts";
export * from "./members/editMember.ts";
export * from "./members/fetchMembers.ts";
export * from "./members/getMember.ts";
export * from "./members/getMembers.ts";
export * from "./members/kickMember.ts";
export * from "./members/moveMember.ts";
export * from "./members/pruneMembers.ts";
export * from "./members/getDmChannel.ts";
export * from "./members/unbanMember.ts";
+1 -8
View File
@@ -3,7 +3,7 @@ import { assertEquals } from "../deps.ts";
import { bot, guild } from "../mod.ts";
import { delayUntil } from "../utils.ts";
Deno.test("[channel] Connect to voice channel and disconnect.", async () => {
Deno.test("[channel] Connect to voice channel.", async () => {
const channel = await bot.helpers.createChannel(guild.id, {
name: "lumap",
type: ChannelTypes.GuildVoice,
@@ -22,11 +22,4 @@ Deno.test("[channel] Connect to voice channel and disconnect.", async () => {
await delayUntil(10000, () => joined);
assertEquals(joined, true);
// DISCONNECT BOT
await bot.helpers.disconnectMember(guild.id, bot.id);
// WAIT FOR EVENT TO ARRIVE
await delayUntil(10000, () => !joined);
assertEquals(joined, false);
});