mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
custom caching complete
This commit is contained in:
@@ -31,11 +31,11 @@ import { Intents } from "../types/options.ts";
|
||||
import { identifyPayload } from "../module/client.ts";
|
||||
import { requestAllMembers } from "../module/shardingManager.ts";
|
||||
import { MemberCreatePayload } from "../types/member.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
import { Member } from "../structures/member.ts";
|
||||
import { urlToBase64 } from "../utils/utils.ts";
|
||||
import { Collection } from "../utils/collection.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
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) {
|
||||
@@ -144,7 +144,7 @@ export async function getChannels(guildID: string, addToCache = true) {
|
||||
return result.map((res) => {
|
||||
const channel = structures.createChannel(res, guildID);
|
||||
if (addToCache) {
|
||||
cache.channels.set(channel.id, channel);
|
||||
cacheHandlers.set("channels", channel.id, channel);
|
||||
}
|
||||
return channel;
|
||||
});
|
||||
@@ -159,7 +159,7 @@ export async function getChannel(channelID: string, addToCache = true) {
|
||||
endpoints.GUILD_CHANNEL(channelID),
|
||||
) as ChannelCreatePayload;
|
||||
const channel = structures.createChannel(result, result.guild_id);
|
||||
if (addToCache) cache.channels.set(channel.id, channel);
|
||||
if (addToCache) cacheHandlers.set("channels", channel.id, channel);
|
||||
return channel;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ export function swapChannels(
|
||||
* ⚠️ **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) {
|
||||
const guild = cache.guilds.get(guildID);
|
||||
const guild = await cacheHandlers.get("guilds", guildID);
|
||||
if (!guild) return;
|
||||
|
||||
const data = await RequestManager.get(
|
||||
@@ -203,7 +203,7 @@ export async function getMembersByQuery(
|
||||
name: string,
|
||||
limit = 1,
|
||||
) {
|
||||
const guild = cache.guilds.get(guildID);
|
||||
const guild = await cacheHandlers.get("guilds", guildID);
|
||||
if (!guild) return;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
@@ -296,7 +296,7 @@ export async function createGuildRole(
|
||||
|
||||
const roleData = result as RoleData;
|
||||
const role = structures.createRole(roleData);
|
||||
const guild = cache.guilds.get(guildID);
|
||||
const guild = await cacheHandlers.get("guilds", guildID);
|
||||
guild?.roles.set(role.id, role);
|
||||
return role;
|
||||
}
|
||||
|
||||
+11
-11
@@ -12,10 +12,10 @@ import { Permissions } from "../types/permission.ts";
|
||||
import { Errors } from "../types/errors.ts";
|
||||
import { RequestManager } from "../module/requestManager.ts";
|
||||
import { MessageContent, DMChannelCreatePayload } from "../types/channel.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
import { EditMemberOptions } from "../types/member.ts";
|
||||
import { sendMessage } from "./channel.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
|
||||
/** The users custom avatar or the default avatar if you don't have a member object. */
|
||||
export function rawAvatarURL(
|
||||
@@ -46,13 +46,13 @@ export function avatarURL(
|
||||
}
|
||||
|
||||
/** Add a role to the member */
|
||||
export function addRole(
|
||||
export async function addRole(
|
||||
guildID: string,
|
||||
memberID: string,
|
||||
roleID: string,
|
||||
reason?: string,
|
||||
) {
|
||||
const botsHighestRole = highestRole(guildID, botID);
|
||||
const botsHighestRole = await highestRole(guildID, botID);
|
||||
if (
|
||||
botsHighestRole &&
|
||||
!higherRolePosition(guildID, botsHighestRole.id, roleID)
|
||||
@@ -71,13 +71,13 @@ export function addRole(
|
||||
}
|
||||
|
||||
/** Remove a role from the member */
|
||||
export function removeRole(
|
||||
export async function removeRole(
|
||||
guildID: string,
|
||||
memberID: string,
|
||||
roleID: string,
|
||||
reason?: string,
|
||||
) {
|
||||
const botsHighestRole = highestRole(guildID, botID);
|
||||
const botsHighestRole = await highestRole(guildID, botID);
|
||||
if (
|
||||
botsHighestRole &&
|
||||
!higherRolePosition(guildID, botsHighestRole.id, roleID)
|
||||
@@ -99,7 +99,7 @@ export async function sendDirectMessage(
|
||||
memberID: string,
|
||||
content: string | MessageContent,
|
||||
) {
|
||||
let dmChannel = cache.channels.get(memberID);
|
||||
let dmChannel = await cacheHandlers.get("channels", memberID);
|
||||
if (!dmChannel) {
|
||||
// If not available in cache create a new one.
|
||||
const dmChannelData = await RequestManager.post(
|
||||
@@ -107,10 +107,10 @@ export async function sendDirectMessage(
|
||||
{ recipient_id: memberID },
|
||||
) as DMChannelCreatePayload;
|
||||
// Channel create event will have added this channel to the cache
|
||||
cache.channels.delete(dmChannelData.id);
|
||||
cacheHandlers.delete("channels", dmChannelData.id);
|
||||
const channel = structures.createChannel(dmChannelData);
|
||||
// Recreate the channel and add it undert he users id
|
||||
cache.channels.set(memberID, channel);
|
||||
cacheHandlers.set("channels", memberID, channel);
|
||||
dmChannel = channel;
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ export async function sendDirectMessage(
|
||||
}
|
||||
|
||||
/** Kick a member from the server */
|
||||
export function kick(guildID: string, memberID: string, reason?: string) {
|
||||
const botsHighestRole = highestRole(guildID, botID);
|
||||
const membersHighestRole = highestRole(guildID, memberID);
|
||||
export async function kick(guildID: string, memberID: string, reason?: string) {
|
||||
const botsHighestRole = await highestRole(guildID, botID);
|
||||
const membersHighestRole = await highestRole(guildID, memberID);
|
||||
if (
|
||||
botsHighestRole && membersHighestRole &&
|
||||
botsHighestRole.position <= membersHighestRole.position
|
||||
|
||||
@@ -10,6 +10,7 @@ import { MessageContent } from "../types/channel.ts";
|
||||
import { UserPayload } from "../types/guild.ts";
|
||||
import { MessageCreateOptions } from "../types/message.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
|
||||
/** Delete a message */
|
||||
export async function deleteMessage(
|
||||
@@ -178,7 +179,7 @@ export async function getReactions(message: Message, reaction: string) {
|
||||
const result = (await RequestManager.get(
|
||||
endpoints.CHANNEL_MESSAGE_REACTION(message.channelID, message.id, reaction),
|
||||
)) as UserPayload[];
|
||||
const guild = message.guild();
|
||||
const guild = await cacheHandlers.get("guilds", message.guildID);
|
||||
|
||||
return result.map((res) => {
|
||||
return guild?.members.get(res.id) || res;
|
||||
|
||||
Reference in New Issue
Block a user