From f2deea4bc2c9d4db90ce55d11b0f0bb2d0506622 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Sun, 29 Oct 2023 15:26:51 +0000 Subject: [PATCH] ok time to work on client --- package-lock.json | 13 ++++++------ package.json | 1 + src/server/lib/DiscordAPI/index.ts | 32 +++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5aeb1c7..7d00638 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "@types/bytes": "^3.1.1", "@types/cookie-parser": "^1.4.3", "@types/range-parser": "^1.2.6", + "discord-api-types": "^0.37.61", "sass": "^1.57.1", "svelte": "^3.55.1", "vite": "^4.5.0" @@ -963,9 +964,9 @@ } }, "node_modules/discord-api-types": { - "version": "0.37.25", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.25.tgz", - "integrity": "sha512-aCwA2sWnL1zPQgTELkkMzQneuWyCXXUjZCUKswesiE6RDCfOfxAPXOHg6ZTlBA5layPSikGCBBRjyh8S3Wzd+A==" + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" }, "node_modules/discord.js": { "version": "14.7.1", @@ -2767,9 +2768,9 @@ "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, "discord-api-types": { - "version": "0.37.25", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.25.tgz", - "integrity": "sha512-aCwA2sWnL1zPQgTELkkMzQneuWyCXXUjZCUKswesiE6RDCfOfxAPXOHg6ZTlBA5layPSikGCBBRjyh8S3Wzd+A==" + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" }, "discord.js": { "version": "14.7.1", diff --git a/package.json b/package.json index af58dc0..2906996 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@types/bytes": "^3.1.1", "@types/cookie-parser": "^1.4.3", "@types/range-parser": "^1.2.6", + "discord-api-types": "^0.37.61", "sass": "^1.57.1", "svelte": "^3.55.1", "vite": "^4.5.0" diff --git a/src/server/lib/DiscordAPI/index.ts b/src/server/lib/DiscordAPI/index.ts index 775ec17..9f7f90f 100644 --- a/src/server/lib/DiscordAPI/index.ts +++ b/src/server/lib/DiscordAPI/index.ts @@ -1 +1,31 @@ -import { REST } from "./DiscordRequests" \ No newline at end of file +import { REST } from "./DiscordRequests" +import type { APIMessage } from "discord-api-types/v10" + +const EXPIRE_AFTER = 20 * 60 * 1000 + +interface MessageCacheObject { + expire: number, + object: APIMessage +} + +export class Client { + private readonly token : string + private readonly rest : REST + private readonly targetChannel : string + private messageCache : Map = new Map() + + constructor(token: string, targetChannel: string) { + this.token = token + this.rest = new REST(token) + this.targetChannel = targetChannel + } + + fetchMessage(id: string, cache: boolean = true) { + if (cache && this.messageCache.has(id)) { + let cachedMessage = this.messageCache.get(id)! + if (cachedMessage.expire >= Date.now()) { + return cachedMessage.object + } + } + } +} \ No newline at end of file