Merge pull request #79 from Androz2091/presence-update

Add oldPresence to presenceUpdate event
This commit is contained in:
Skillz4Killz
2020-07-30 18:02:38 -04:00
committed by GitHub
3 changed files with 11 additions and 2 deletions

View File

@@ -563,7 +563,10 @@ export async function handleDiscordPayload(
}
if (data.t === "PRESENCE_UPDATE") {
return eventHandlers.presenceUpdate?.(data.d as PresenceUpdatePayload);
const payload = data.d as PresenceUpdatePayload;
const oldPresence = cache.presences.get(payload.user.id);
cache.presences.set(payload.user.id, payload);
return eventHandlers.presenceUpdate?.(payload, oldPresence);
}
if (data.t === "TYPING_START") {

View File

@@ -105,7 +105,10 @@ export interface EventHandlers {
nickname: string,
oldNickname?: string,
) => unknown;
presenceUpdate?: (data: PresenceUpdatePayload) => unknown;
presenceUpdate?: (
presence: PresenceUpdatePayload,
oldPresence?: PresenceUpdatePayload,
) => unknown;
raw?: (data: DiscordPayload) => unknown;
ready?: () => unknown;
reactionAdd?: (

View File

@@ -3,12 +3,14 @@ import { Message } from "../structures/message.ts";
import { Guild } from "../structures/guild.ts";
import { Channel } from "../structures/channel.ts";
import { delay } from "https://deno.land/std@0.61.0/async/delay.ts";
import { PresenceUpdatePayload } from "../types/discord.ts";
export interface CacheData {
guilds: Collection<string, Guild>;
channels: Collection<string, Channel>;
messages: Collection<string, Message>;
unavailableGuilds: Collection<string, number>;
presences: Collection<string, PresenceUpdatePayload>;
}
export const cache: CacheData = {
@@ -16,6 +18,7 @@ export const cache: CacheData = {
channels: new Collection(),
messages: new Collection(),
unavailableGuilds: new Collection(),
presences: new Collection(),
};
async function cleanMessageCache() {