From e4d23c193b8f427dc5c90a8de360ff3bc755bffe Mon Sep 17 00:00:00 2001 From: cirroskais Date: Mon, 18 Mar 2024 17:45:44 -0400 Subject: [PATCH] sdfksdjfk --- src/App.svelte | 18 ++++++------- src/lib/discord.js | 63 ---------------------------------------------- src/lib/discord.ts | 48 +++++++++++++++++++++++++++++++++++ src/lib/stores.js | 5 ---- src/lib/stores.ts | 14 +++++++++++ 5 files changed, 71 insertions(+), 77 deletions(-) delete mode 100644 src/lib/discord.js create mode 100644 src/lib/discord.ts delete mode 100644 src/lib/stores.js create mode 100644 src/lib/stores.ts diff --git a/src/App.svelte b/src/App.svelte index 0a140d7..8abbfd4 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,20 +1,20 @@
-

garf 2: eletric boogaloo

- {#each $logs as log} -

{log.type}

- {log.content} -
- {/each} + {#if $user.avatar} + + {:else} + > 22) % 6}.png`} alt="" /> + {/if} +

Hello, {$user.username}

diff --git a/src/lib/discord.js b/src/lib/discord.js deleted file mode 100644 index e0ced34..0000000 --- a/src/lib/discord.js +++ /dev/null @@ -1,63 +0,0 @@ -const CLIENT_ID = "869016244613951539"; -import { DiscordSDK } from "@discord/embedded-app-sdk"; -export const discordSdk = new DiscordSDK(CLIENT_ID); - -import { logs } from "./stores"; - -export const ACTIVITY_STARTED = Date.now(); - -/** - * @param {any} activity - */ -async function setActivity(activity) { - const result = await discordSdk.commands.setActivity({ activity }); - logs.update((value) => { - return [...value, { type: "Activity", content: JSON.stringify(result) }]; - }); - - return result; -} - -async function activityUpdateLoop() { - const { participants } = await discordSdk.commands.getInstanceConnectedParticipants(); - logs.update((value) => { - return [...value, { type: "Peers", content: JSON.stringify(participants) }]; - }); - - setActivity({ - type: 3, - details: "garf", - state: "garfing rn", - assets: { - large_image: "embedded_cover", - }, - party: { - size: [participants.length, 5], - }, - }); -} - -export async function authorize() { - await discordSdk.ready(); - - const { code } = await discordSdk.commands.authorize({ - client_id: CLIENT_ID, - response_type: "code", - state: "", - prompt: "none", - scope: ["identify", "guilds", "rpc.activities.write"], - }); - - const response = await fetch("/api/token", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ code }), - }); - - const { access_token } = await response.json(); - const auth = await discordSdk.commands.authenticate({ access_token }); - - setInterval(activityUpdateLoop, 10 * 1000); - - return auth; -} diff --git a/src/lib/discord.ts b/src/lib/discord.ts new file mode 100644 index 0000000..a2f69c7 --- /dev/null +++ b/src/lib/discord.ts @@ -0,0 +1,48 @@ +const CLIENT_ID = "869016244613951539"; +import { DiscordSDK, Events, type Types } from "@discord/embedded-app-sdk"; +export const discordSdk = new DiscordSDK(CLIENT_ID); +import { participants as partz } from "./stores"; + +export const ACTIVITY_STARTED = Date.now(); + +export async function authorize() { + await discordSdk.ready(); + + const { code } = await discordSdk.commands.authorize({ + client_id: CLIENT_ID, + response_type: "code", + state: "", + prompt: "none", + scope: ["identify", "guilds", "rpc.activities.write", "guilds.members.read"], + }); + + const response = await fetch("/api/token", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ code }), + }); + + const { access_token } = await response.json(); + const auth = await discordSdk.commands.authenticate({ access_token }); + + return auth; +} + +discordSdk.subscribe(Events.ACTIVITY_INSTANCE_PARTICIPANTS_UPDATE, (data) => { + partz.set(data); + + discordSdk.commands.setActivity({ + activity: { + type: 3, + details: "garf", + state: "garfmaxxing", + assets: { + large_image: "embedded_cover", + large_text: "garf", + }, + party: { + size: [data.participants.length, 5], + }, + }, + }); +}); diff --git a/src/lib/stores.js b/src/lib/stores.js deleted file mode 100644 index d568c3d..0000000 --- a/src/lib/stores.js +++ /dev/null @@ -1,5 +0,0 @@ -import { writable } from "svelte/store"; - -export const user = writable({}); - -export const logs = writable([{ type: "Init", content: "Begin logs" }]); diff --git a/src/lib/stores.ts b/src/lib/stores.ts new file mode 100644 index 0000000..cf2817d --- /dev/null +++ b/src/lib/stores.ts @@ -0,0 +1,14 @@ +import type { Types } from "@discord/embedded-app-sdk"; +import { writable, type Writable } from "svelte/store"; + +interface AuthenticatedUser { + username: string; + discriminator: string; + id: string; + public_flags: number; + avatar?: string | null | undefined; + global_name?: string | null | undefined; +} + +export const user: Writable = writable(); +export const participants: Writable = writable();