sdfksdjfk
This commit is contained in:
parent
a2fc1a3957
commit
6dcf62b016
3 changed files with 32 additions and 55 deletions
|
@ -1,33 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { authorize, discordSdk } from "./lib/discord";
|
import { authorize, setActivity } from "./lib/discord";
|
||||||
|
import { logs } from "./lib/stores";
|
||||||
let logs = [{ type: "Init", content: "Begin logs" }];
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const auth = await authorize();
|
const auth = await authorize();
|
||||||
logs = [...logs, { type: "Auth", content: JSON.stringify(auth.user, null, 4) }];
|
$logs = [...$logs, { type: "Auth", content: JSON.stringify(auth.user) }];
|
||||||
|
|
||||||
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) }];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -35,7 +12,7 @@
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<p>garf 2: eletric boogaloo</p>
|
<p>garf 2: eletric boogaloo</p>
|
||||||
{#each logs as log}
|
{#each $logs as log}
|
||||||
<p><strong>{log.type}</strong></p>
|
<p><strong>{log.type}</strong></p>
|
||||||
<tt>{log.content}</tt>
|
<tt>{log.content}</tt>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -3,6 +3,15 @@ const CLIENT_ID = "869016244613951539";
|
||||||
import { DiscordSDK } from "@discord/embedded-app-sdk";
|
import { DiscordSDK } from "@discord/embedded-app-sdk";
|
||||||
export const discordSdk = new DiscordSDK(CLIENT_ID);
|
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() {
|
export async function authorize() {
|
||||||
await discordSdk.ready();
|
await discordSdk.ready();
|
||||||
|
|
||||||
|
@ -11,42 +20,31 @@ export async function authorize() {
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
state: "",
|
state: "",
|
||||||
prompt: "none",
|
prompt: "none",
|
||||||
scope: [
|
scope: ["identify", "guilds", "rpc.activities.write"],
|
||||||
// "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",
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch("/api/token", {
|
const response = await fetch("/api/token", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ code }),
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
code,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { access_token } = await response.json();
|
const { access_token } = await response.json();
|
||||||
|
|
||||||
const auth = await discordSdk.commands.authenticate({ access_token });
|
const auth = await discordSdk.commands.authenticate({ access_token });
|
||||||
|
|
||||||
|
setInterval(updateActivity, 10 * 1000);
|
||||||
|
|
||||||
return auth;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
export const user = writable({});
|
export const user = writable({});
|
||||||
|
|
||||||
|
export const logs = writable([{ type: "Init", content: "Begin logs" }]);
|
||||||
|
|
Loading…
Reference in a new issue