sdfksdjfk

This commit is contained in:
cirroskais 2024-03-18 17:04:56 -04:00
parent a2fc1a3957
commit 6dcf62b016
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
3 changed files with 32 additions and 55 deletions

View file

@ -1,33 +1,10 @@
<script lang="ts">
import { authorize, discordSdk } from "./lib/discord";
let logs = [{ type: "Init", content: "Begin logs" }];
import { authorize, setActivity } from "./lib/discord";
import { logs } from "./lib/stores";
async function main() {
const auth = await authorize();
logs = [...logs, { type: "Auth", content: JSON.stringify(auth.user, null, 4) }];
const activity = await discordSdk.commands.setActivity({
activity: {
type: 3,
details: "garf",
state: "garfing rn",
timestamps: {
start: Date.now(),
},
party: {
size: [4, 5],
},
assets: {
large_image: "embedded_cover",
large_text: "garf",
small_image: "embedded_cover",
small_text: "garf",
},
},
});
logs = [...logs, { type: "Activity", content: JSON.stringify(activity, null, 4) }];
$logs = [...$logs, { type: "Auth", content: JSON.stringify(auth.user) }];
}
main();
@ -35,7 +12,7 @@
<main>
<p>garf 2: eletric boogaloo</p>
{#each logs as log}
{#each $logs as log}
<p><strong>{log.type}</strong></p>
<tt>{log.content}</tt>
<br />

View file

@ -3,6 +3,15 @@ const CLIENT_ID = "869016244613951539";
import { DiscordSDK } from "@discord/embedded-app-sdk";
export const discordSdk = new DiscordSDK(CLIENT_ID);
import { logs } from "./stores";
async function updateActivity() {
const peers = await discordSdk.commands.getInstanceConnectedParticipants();
logs.update((value) => {
return [...value, { type: "Peers", content: JSON.stringify(peers) }];
});
}
export async function authorize() {
await discordSdk.ready();
@ -11,42 +20,31 @@ export async function authorize() {
response_type: "code",
state: "",
prompt: "none",
scope: [
// "applications.builds.upload",
// "applications.builds.read",
// "applications.store.update",
// "applications.entitlements",
// "bot",
"identify",
// "connections",
// "email",
// "gdm.join",
"guilds",
// "guilds.join",
// "guilds.members.read",
// "messages.read",
// "relationships.read",
"rpc.activities.write",
// "rpc.notifications.read",
// "rpc.voice.write",
"rpc.voice.read",
// "webhook.incoming",
],
scope: ["identify", "guilds", "rpc.activities.write"],
});
const response = await fetch("/api/token", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
code,
}),
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code }),
});
const { access_token } = await response.json();
const auth = await discordSdk.commands.authenticate({ access_token });
setInterval(updateActivity, 10 * 1000);
return auth;
}
/**
* @param {any} activity
*/
export async function setActivity(activity) {
const result = await discordSdk.commands.setActivity({ activity });
logs.update((value) => {
return [...value, { type: "Activity", content: JSON.stringify(result) }];
});
return result;
}

View file

@ -1,3 +1,5 @@
import { writable } from "svelte/store";
export const user = writable({});
export const logs = writable([{ type: "Init", content: "Begin logs" }]);