mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
remove guild.channels
This commit is contained in:
@@ -79,6 +79,29 @@ function forEach(
|
|||||||
return cache[table].forEach(callback);
|
return cache[table].forEach(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filter(
|
||||||
|
table: "guilds",
|
||||||
|
callback: (value: Guild, key: string) => boolean,
|
||||||
|
): Collection<string, Guild>;
|
||||||
|
function filter(
|
||||||
|
table: "unavailableGuilds",
|
||||||
|
callback: (value: Guild, key: string) => boolean,
|
||||||
|
): Collection<string, Guild>;
|
||||||
|
function filter(
|
||||||
|
table: "channels",
|
||||||
|
callback: (value: Channel, key: string) => boolean,
|
||||||
|
): Collection<string, Channel>;
|
||||||
|
function filter(
|
||||||
|
table: "messages",
|
||||||
|
callback: (value: Message, key: string) => boolean,
|
||||||
|
): Collection<string, Message>;
|
||||||
|
function filter(
|
||||||
|
table: TableName,
|
||||||
|
callback: (value: any, key: string) => boolean,
|
||||||
|
) {
|
||||||
|
return cache[table].filter(callback);
|
||||||
|
}
|
||||||
|
|
||||||
export let cacheHandlers = {
|
export let cacheHandlers = {
|
||||||
/** Deletes all items from the cache */
|
/** Deletes all items from the cache */
|
||||||
clear: async function (table: TableName) {
|
clear: async function (table: TableName) {
|
||||||
@@ -105,4 +128,6 @@ export let cacheHandlers = {
|
|||||||
get,
|
get,
|
||||||
/** Run a function on all items in this cache */
|
/** Run a function on all items in this cache */
|
||||||
forEach,
|
forEach,
|
||||||
|
/** Allows you to filter our all items in this cache. */
|
||||||
|
filter,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { PermissionOverwrite } from "../types/guild.ts";
|
|||||||
import { MessageCreateOptions } from "../types/message.ts";
|
import { MessageCreateOptions } from "../types/message.ts";
|
||||||
import { Permissions } from "../types/permission.ts";
|
import { Permissions } from "../types/permission.ts";
|
||||||
import { endpoints } from "../utils/constants.ts";
|
import { endpoints } from "../utils/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../utils/permissions.ts";
|
import { botHasChannelPermissions, calculateBits } from "../utils/permissions.ts";
|
||||||
|
|
||||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||||
export function channelOverwriteHasPermission(
|
export function channelOverwriteHasPermission(
|
||||||
@@ -455,8 +455,8 @@ export async function isChannelSynced(channelID: string) {
|
|||||||
const parentChannel = await cacheHandlers.get("channels", channel.parentID);
|
const parentChannel = await cacheHandlers.get("channels", channel.parentID);
|
||||||
if (!parentChannel) return false;
|
if (!parentChannel) return false;
|
||||||
|
|
||||||
return channel.permission_overwrites?.every((overwrite) => {
|
return channel.permissionOverwrites?.every((overwrite) => {
|
||||||
const permission = parentChannel.permission_overwrites?.find((ow) =>
|
const permission = parentChannel.permissionOverwrites?.find((ow) =>
|
||||||
ow.id === overwrite.id
|
ow.id === overwrite.id
|
||||||
);
|
);
|
||||||
if (!permission) return false;
|
if (!permission) return false;
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ export function deleteServer(guildID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Gets an array of all the channels ids that are the children of this category. */
|
/** Gets an array of all the channels ids that are the children of this category. */
|
||||||
export function categoryChildrenIDs(guild: Guild, id: string) {
|
export function categoryChildrenIDs(guildID: string, id: string) {
|
||||||
return guild.channels.filter((channel) => channel.parentID === id);
|
return cacheHandlers.filter("channels", (channel) => channel.parentID === id && channel.guildID === guildID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
||||||
@@ -132,7 +132,6 @@ export async function createGuildChannel(
|
|||||||
})) as ChannelCreatePayload;
|
})) as ChannelCreatePayload;
|
||||||
|
|
||||||
const channel = await structures.createChannel(result);
|
const channel = await structures.createChannel(result);
|
||||||
guild.channels.set(result.id, channel);
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { cacheHandlers } from "../controllers/cache.ts";
|
import { cacheHandlers } from "../controllers/cache.ts";
|
||||||
import { ChannelCreatePayload } from "../types/channel.ts";
|
import { ChannelCreatePayload } from "../types/channel.ts";
|
||||||
import { PermissionOverwrite } from "../types/guild.ts";
|
|
||||||
import { Unpromise } from "../types/misc.ts";
|
import { Unpromise } from "../types/misc.ts";
|
||||||
import { calculatePermissions } from "../utils/permissions.ts";
|
|
||||||
|
|
||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
data: ChannelCreatePayload,
|
data: ChannelCreatePayload,
|
||||||
@@ -34,14 +32,7 @@ export async function createChannel(
|
|||||||
/** The last time when a message was pinned in this channel */
|
/** The last time when a message was pinned in this channel */
|
||||||
lastPinTimestamp,
|
lastPinTimestamp,
|
||||||
/** The permission overwrites for this channel */
|
/** The permission overwrites for this channel */
|
||||||
permissionOverwrites:
|
permissionOverwrites: permission_overwrites,
|
||||||
(data.permission_overwrites
|
|
||||||
? data.permission_overwrites.map((perm) => ({
|
|
||||||
...perm,
|
|
||||||
allow: calculatePermissions(BigInt(perm.allow)),
|
|
||||||
deny: calculatePermissions(BigInt(perm.deny)),
|
|
||||||
}))
|
|
||||||
: []) as PermissionOverwrite[],
|
|
||||||
/** Whether this channel is nsfw or not */
|
/** Whether this channel is nsfw or not */
|
||||||
nsfw: data.nsfw || false,
|
nsfw: data.nsfw || false,
|
||||||
/** The mention of the channel */
|
/** The mention of the channel */
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) {
|
|||||||
const roles = await Promise.all(
|
const roles = await Promise.all(
|
||||||
data.roles.map((r) => structures.createRole(r)),
|
data.roles.map((r) => structures.createRole(r)),
|
||||||
);
|
);
|
||||||
const channels = await Promise.all(
|
|
||||||
|
await Promise.all(
|
||||||
data.channels.map((c) => structures.createChannel(c, data.id)),
|
data.channels.map((c) => structures.createChannel(c, data.id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -65,15 +66,12 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) {
|
|||||||
premiumSubscriptionCount,
|
premiumSubscriptionCount,
|
||||||
/** The preferred language in this server. */
|
/** The preferred language in this server. */
|
||||||
preferredLocale,
|
preferredLocale,
|
||||||
|
|
||||||
/** The roles in the guild */
|
/** The roles in the guild */
|
||||||
roles: new Collection(roles.map((r) => [r.id, r])),
|
roles: new Collection(roles.map((r) => [r.id, r])),
|
||||||
/** When this guild was joined at. */
|
/** When this guild was joined at. */
|
||||||
joinedAt: Date.parse(joinedAt),
|
joinedAt: Date.parse(joinedAt),
|
||||||
/** The users in this guild. */
|
/** The users in this guild. */
|
||||||
members: new Collection<string, Member>(),
|
members: new Collection<string, Member>(),
|
||||||
/** The channels in the guild */
|
|
||||||
channels: new Collection(channels.map((c) => [c.id, c])),
|
|
||||||
/** The presences of all the users in the guild. */
|
/** The presences of all the users in the guild. */
|
||||||
presences: new Collection(data.presences.map((p) => [p.user.id, p])),
|
presences: new Collection(data.presences.map((p) => [p.user.id, p])),
|
||||||
/** The total number of members in this guild. This value is updated as members leave and join the server. However, if you do not have the intent enabled to be able to listen to these events, then this will not be accurate. */
|
/** The total number of members in this guild. This value is updated as members leave and join the server. However, if you do not have the intent enabled to be able to listen to these events, then this will not be accurate. */
|
||||||
|
|||||||
Reference in New Issue
Block a user