mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
more refactoring
This commit is contained in:
+4
-48
@@ -4,7 +4,7 @@ import { botHasPermission } from "../utils/permissions.ts";
|
||||
import { RequestManager } from "../module/requestManager.ts";
|
||||
import { endpoints } from "../constants/discord.ts";
|
||||
import { Errors } from "../types/errors.ts";
|
||||
import { Permissions, Permission } from "../types/permission.ts";
|
||||
import { Permissions } from "../types/permission.ts";
|
||||
import {
|
||||
ChannelCreatePayload,
|
||||
ChannelTypes,
|
||||
@@ -39,12 +39,7 @@ import { cacheHandlers } from "../controllers/cache.ts";
|
||||
|
||||
/** Gets an array of all the channels ids that are the children of this category. */
|
||||
export function categoryChildrenIDs(guild: Guild, id: string) {
|
||||
const channelIDs: string[] = [];
|
||||
guild.channels.forEach((channel) => {
|
||||
if (channel.parentID === id) channelIDs.push(channel.id);
|
||||
});
|
||||
|
||||
return channelIDs;
|
||||
return guild.channels.filter((channel) => channel.parentID === id);
|
||||
}
|
||||
|
||||
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
||||
@@ -477,7 +472,7 @@ export function deleteIntegration(guildID: string, id: string) {
|
||||
return RequestManager.delete(endpoints.GUILD_INTEGRATION(guildID, id));
|
||||
}
|
||||
|
||||
/** Sync an integration. Requires teh MANAGE_GUILD permission. */
|
||||
/** Sync an integration. Requires the MANAGE_GUILD permission. */
|
||||
export function syncIntegration(guildID: string, id: string) {
|
||||
if (
|
||||
!botHasPermission(guildID, [Permissions.MANAGE_GUILD])
|
||||
@@ -517,7 +512,7 @@ export function getBan(guildID: string, memberID: string) {
|
||||
) as Promise<BannedUser>;
|
||||
}
|
||||
|
||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires teh BAN_MEMBERS permission. */
|
||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
|
||||
export function ban(guildID: string, id: string, options: BanOptions) {
|
||||
if (
|
||||
!botHasPermission(guildID, [Permissions.BAN_MEMBERS])
|
||||
@@ -541,45 +536,6 @@ export function unban(guildID: string, id: string) {
|
||||
return RequestManager.delete(endpoints.GUILD_BAN(guildID, id));
|
||||
}
|
||||
|
||||
/** Check whether a member has certain permissions in this channel. */
|
||||
export function channelHasPermissions(
|
||||
guild: Guild,
|
||||
channelID: string,
|
||||
memberID: string,
|
||||
permissions: Permission[],
|
||||
) {
|
||||
if (memberID === guild.ownerID) return true;
|
||||
|
||||
const member = guild.members.get(memberID);
|
||||
if (!member) {
|
||||
throw new Error(
|
||||
"Invalid member id provided. This member was not found in the cache. Please fetch them with getMember on guild.",
|
||||
);
|
||||
}
|
||||
|
||||
const channel = guild.channels.get(channelID);
|
||||
if (!channel) {
|
||||
throw new Error(
|
||||
"Invalid channel id provided. This channel was not found in the cache.",
|
||||
);
|
||||
}
|
||||
|
||||
let permissionBits = member.roles.reduce((bits, roleID) => {
|
||||
const role = guild.roles.get(roleID);
|
||||
if (!role) return bits;
|
||||
|
||||
bits |= BigInt(role.permissions_new);
|
||||
|
||||
return bits;
|
||||
}, BigInt(0));
|
||||
|
||||
if (permissionBits & BigInt(Permissions.ADMINISTRATOR)) return true;
|
||||
|
||||
return permissions.every((permission) =>
|
||||
permissionBits & BigInt(Permissions[permission])
|
||||
);
|
||||
}
|
||||
|
||||
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
||||
export async function editGuild(guildID: string, options: GuildEditOptions) {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user