mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactoring
This commit is contained in:
@@ -1,9 +1,20 @@
|
|||||||
import createClient from "./src/module/client.ts";
|
import createClient from "./src/module/client.ts";
|
||||||
|
|
||||||
|
export * from "./src/controllers/mod.ts";
|
||||||
|
export * from "./src/controllers/bans.ts";
|
||||||
|
export * from "./src/controllers/channels.ts";
|
||||||
|
export * from "./src/controllers/guilds.ts";
|
||||||
|
export * from "./src/controllers/members.ts";
|
||||||
|
export * from "./src/controllers/messages.ts";
|
||||||
|
export * from "./src/controllers/misc.ts";
|
||||||
|
export * from "./src/controllers/reactions.ts";
|
||||||
|
export * from "./src/controllers/roles.ts";
|
||||||
|
|
||||||
export * from "./src/module/client.ts";
|
export * from "./src/module/client.ts";
|
||||||
export * from "./src/module/requestManager.ts";
|
export * from "./src/module/requestManager.ts";
|
||||||
export * from "./src/module/shardingManager.ts";
|
export * from "./src/module/shardingManager.ts";
|
||||||
|
|
||||||
|
export * from "./src/structures/mod.ts";
|
||||||
export * from "./src/structures/channel.ts";
|
export * from "./src/structures/channel.ts";
|
||||||
export * from "./src/structures/guild.ts";
|
export * from "./src/structures/guild.ts";
|
||||||
export * from "./src/structures/member.ts";
|
export * from "./src/structures/member.ts";
|
||||||
|
|||||||
@@ -78,8 +78,11 @@ export let controllers = {
|
|||||||
WEBHOOKS_UPDATE: handleInternalWebhooksUpdate,
|
WEBHOOKS_UPDATE: handleInternalWebhooksUpdate,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Controllers = typeof controllers
|
export type Controllers = typeof controllers;
|
||||||
|
|
||||||
export function updateControllers(newControllers: Controllers) {
|
export function updateControllers(newControllers: Controllers) {
|
||||||
controllers = newControllers
|
controllers = {
|
||||||
|
...controllers,
|
||||||
|
...newControllers,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Collection } from "./collection.ts";
|
|||||||
import { Message } from "../structures/message.ts";
|
import { Message } from "../structures/message.ts";
|
||||||
import { Guild } from "../structures/guild.ts";
|
import { Guild } from "../structures/guild.ts";
|
||||||
import { Channel } from "../structures/channel.ts";
|
import { Channel } from "../structures/channel.ts";
|
||||||
import { delay } from "https://deno.land/std@0.67.0/async/delay.ts";
|
|
||||||
import { PresenceUpdatePayload } from "../types/discord.ts";
|
import { PresenceUpdatePayload } from "../types/discord.ts";
|
||||||
|
|
||||||
export interface CacheData {
|
export interface CacheData {
|
||||||
@@ -25,42 +24,4 @@ export const cache: CacheData = {
|
|||||||
fetchAllMembersProcessingRequests: new Collection<string, Function>(),
|
fetchAllMembersProcessingRequests: new Collection<string, Function>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
async function cleanMessageCache() {
|
|
||||||
// Find all messages for each channel and if more than 100 we need to remove the oldest messages.
|
|
||||||
const messagesPerChannel = new Map<string, Message[]>();
|
|
||||||
|
|
||||||
for (const message of cache.messages.values()) {
|
|
||||||
if (
|
|
||||||
// If the guild isn't in cache the message is useless to cache
|
|
||||||
(message.guildID && !cache.guilds.has(message.guildID)) ||
|
|
||||||
// If the channel isn't in cache the message is useless in cache
|
|
||||||
!cache.channels.has(message.channelID)
|
|
||||||
) {
|
|
||||||
cache.messages.delete(message.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const channel = messagesPerChannel.get(message.channelID);
|
|
||||||
if (!channel) {
|
|
||||||
messagesPerChannel.set(message.channelID, [message]);
|
|
||||||
} else {
|
|
||||||
channel.push(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
messagesPerChannel.forEach((messages) => {
|
|
||||||
if (messages.length < 100) return;
|
|
||||||
|
|
||||||
// This channel has more than 100 messages in cache. Delete the oldest
|
|
||||||
const sortedMessages = messages.sort((a, b) => b.timestamp - a.timestamp);
|
|
||||||
|
|
||||||
sortedMessages.slice(100).forEach((message) =>
|
|
||||||
cache.messages.delete(message.id)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check once per minute
|
|
||||||
await delay(60000);
|
|
||||||
cleanMessageCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanMessageCache();
|
|
||||||
|
|||||||
Reference in New Issue
Block a user