From 8b0d4cca9e12cb0c63a574844015a4ad73f18951 Mon Sep 17 00:00:00 2001 From: xhayper Date: Sun, 19 Nov 2023 12:03:25 +0700 Subject: [PATCH] feat: new features and update dependencies --- README.md | 2 +- deps.ts | 10 ++--- examples/simple_oauth.js | 2 +- examples/simple_oauth.ts | 2 +- examples/simple_status.js | 2 +- examples/simple_status.ts | 2 +- src/structures/ClientUser.ts | 78 +++++++++++++++++++++++++++++++----- 7 files changed, 79 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 490a813..fe2d401 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ NOTE: Require `--unstable --allow-read --allow-env --allow-write --allow-net`! ## Example ```ts -import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.25/mod.ts"; +import { Client } from "https://deno.land/x/discord_rpc_deno@1.1.0/mod.ts"; const client = new Client({ clientId: "123456789012345678", diff --git a/deps.ts b/deps.ts index 4031087..5b42117 100644 --- a/deps.ts +++ b/deps.ts @@ -1,9 +1,9 @@ -export { grantOrThrow } from "https://deno.land/std@0.206.0/permissions/mod.ts"; -export { EventEmitter } from "https://deno.land/std@0.206.0/node/events.ts"; // TODO: Stop using node! -export { Buffer } from "https://deno.land/std@0.206.0/node/buffer.ts"; // TODO: Stop using node! +export { grantOrThrow } from "https://deno.land/std@0.207.0/permissions/mod.ts"; +export { EventEmitter } from "https://deno.land/std@0.207.0/node/events.ts"; // TODO: Stop using node! +export { Buffer } from "https://deno.land/std@0.207.0/node/buffer.ts"; // TODO: Stop using node! -export * as path from "https://deno.land/std@0.206.0/path/mod.ts"; -export * as net from "https://deno.land/std@0.206.0/node/net.ts"; // TODO: Stop using node! +export * as path from "https://deno.land/std@0.207.0/path/mod.ts"; +export * as net from "https://deno.land/std@0.207.0/node/net.ts"; // TODO: Stop using node! export type { ActivityType, diff --git a/examples/simple_oauth.js b/examples/simple_oauth.js index 11dd517..2ee59b3 100644 --- a/examples/simple_oauth.js +++ b/examples/simple_oauth.js @@ -1,4 +1,4 @@ -import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.25/mod.ts"; +import { Client } from "https://deno.land/x/discord_rpc_deno@1.1.0/mod.ts"; const client = new Client({ clientId: "123456789012345678", diff --git a/examples/simple_oauth.ts b/examples/simple_oauth.ts index 11dd517..2ee59b3 100644 --- a/examples/simple_oauth.ts +++ b/examples/simple_oauth.ts @@ -1,4 +1,4 @@ -import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.25/mod.ts"; +import { Client } from "https://deno.land/x/discord_rpc_deno@1.1.0/mod.ts"; const client = new Client({ clientId: "123456789012345678", diff --git a/examples/simple_status.js b/examples/simple_status.js index f19c39c..0ba0c93 100644 --- a/examples/simple_status.js +++ b/examples/simple_status.js @@ -1,4 +1,4 @@ -import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.25/mod.ts"; +import { Client } from "https://deno.land/x/discord_rpc_deno@1.1.0/mod.ts"; const client = new Client({ clientId: "123456789012345678", diff --git a/examples/simple_status.ts b/examples/simple_status.ts index f19c39c..0ba0c93 100644 --- a/examples/simple_status.ts +++ b/examples/simple_status.ts @@ -1,4 +1,4 @@ -import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.25/mod.ts"; +import { Client } from "https://deno.land/x/discord_rpc_deno@1.1.0/mod.ts"; const client = new Client({ clientId: "123456789012345678", diff --git a/src/structures/ClientUser.ts b/src/structures/ClientUser.ts index b2ce42e..33f0cf1 100644 --- a/src/structures/ClientUser.ts +++ b/src/structures/ClientUser.ts @@ -7,25 +7,80 @@ import { Channel } from "./Channel.ts"; import { Guild } from "./Guild.ts"; import { User } from "./User.ts"; +export enum ActivitySupportedPlatform { + IOS = "ios", + ANDROID = "android", + WEB = "web", +} + +export enum ActivityPartyPrivacy { + PRIVATE = 0, + PUBLIC = 1, +} + export type SetActivity = { + /** + * Minimum of 2 characters and maximum of 128 characters + */ state?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ details?: string; startTimestamp?: number | Date; endTimestamp?: number | Date; + /** + * Minimum of 1 characters and maximum of 128 characters + */ largeImageKey?: string; + /** + * Minimum of 1 characters and maximum of 128 characters + */ smallImageKey?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ largeImageText?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ smallImageText?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ partyId?: string; + /** + * Default: ActivityPartyPrivacy.PRIVATE + */ + partyPrivacy?: ActivityPartyPrivacy; partySize?: number; partyMax?: number; + /** + * Minimum of 2 characters and maximum of 128 characters + */ matchSecret?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ joinSecret?: string; + /** + * Minimum of 2 characters and maximum of 128 characters + */ spectateSecret?: string; instance?: boolean; buttons?: Array; - // Doesn't work, juse don't use it - type?: ActivityType.Playing | ActivityType.Watching | number; + supportedPlatforms?: ( + | ActivitySupportedPlatform + | `${ActivitySupportedPlatform}` + )[]; + /** + * Default: ActivityTypes.PLAYING + */ + type?: + | ActivityType.Playing + | ActivityType.Listening + | ActivityType.Watching + | number; }; export type SetActivityResponse = { @@ -112,9 +167,7 @@ export class ClientUser extends User { * @returns the client's current voice channel, `null` if none */ async getSelectedVoiceChannel(): Promise { - const response = await this.client.request( - "GET_SELECTED_VOICE_CHANNEL", - ); + const response = await this.client.request("GET_SELECTED_VOICE_CHANNEL"); return response.data !== null ? new Channel(this.client, response.data) : null; @@ -178,9 +231,7 @@ export class ClientUser extends User { ): Promise { return new VoiceSettings( this.client, - ( - await this.client.request("SET_VOICE_SETTINGS", voiceSettings) - ).data, + (await this.client.request("SET_VOICE_SETTINGS", voiceSettings)).data, ); } @@ -302,6 +353,9 @@ export class ClientUser extends User { } if (activity.partyId) formattedAcitivity.party.id = activity.partyId; + if (activity.partyPrivacy) { + formattedAcitivity.party.privacy = activity.partyPrivacy; + } if (activity.partySize && activity.partyMax) { formattedAcitivity.party.size = [activity.partySize, activity.partyMax]; } @@ -316,6 +370,10 @@ export class ClientUser extends User { formattedAcitivity.secrets.match = activity.matchSecret; } + if (activity.supportedPlatforms) { + formattedAcitivity.supported_platforms = activity.supportedPlatforms; + } + if (Object.keys(formattedAcitivity.assets).length === 0) { delete formattedAcitivity["assets"]; } @@ -339,15 +397,17 @@ export class ClientUser extends User { delete formattedAcitivity["largeImageText"]; delete formattedAcitivity["smallImageText"]; delete formattedAcitivity["partyId"]; + delete formattedAcitivity["partyPrivacy"]; delete formattedAcitivity["partySize"]; delete formattedAcitivity["partyMax"]; delete formattedAcitivity["joinSecret"]; delete formattedAcitivity["spectateSecret"]; delete formattedAcitivity["matchSecret"]; + delete formattedAcitivity["supportedPlatforms"]; return ( await this.client.request("SET_ACTIVITY", { - pid: pid ?? Deno.pid, + pid: pid ?? process ? process.pid ?? 0 : 0, activity: formattedAcitivity, }) ).data;