Skip to content

Commit

Permalink
feat: new features and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Nov 19, 2023
1 parent 3b738e8 commit 8b0d4cc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_oauth.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_oauth.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_status.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_status.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
78 changes: 69 additions & 9 deletions src/structures/ClientUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GatewayActivityButton>;
// 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 = {
Expand Down Expand Up @@ -112,9 +167,7 @@ export class ClientUser extends User {
* @returns the client's current voice channel, `null` if none
*/
async getSelectedVoiceChannel(): Promise<Channel | null> {
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;
Expand Down Expand Up @@ -178,9 +231,7 @@ export class ClientUser extends User {
): Promise<VoiceSettings> {
return new VoiceSettings(
this.client,
(
await this.client.request("SET_VOICE_SETTINGS", voiceSettings)
).data,
(await this.client.request("SET_VOICE_SETTINGS", voiceSettings)).data,
);
}

Expand Down Expand Up @@ -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];
}
Expand All @@ -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"];
}
Expand All @@ -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;
Expand Down

0 comments on commit 8b0d4cc

Please sign in to comment.