Skip to content

Commit cd4e56f

Browse files
committed
add better presence option types
1 parent 51ea1ca commit cd4e56f

File tree

3 files changed

+78
-40
lines changed

3 files changed

+78
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "detritus-client-socket",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"description": "A TypeScript NodeJS library to interact with Discord's Gateway",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const Package = Object.freeze({
22
URL: 'https://github.com/detritusjs/client-socket',
3-
VERSION: '0.3.6',
3+
VERSION: '0.3.7',
44
});
55

66
function normalize(object: {[key: string]: any}) {

src/gateway.ts

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface SocketOptions {
7474
guildSubscriptions?: boolean,
7575
identifyProperties?: IdentifyDataProperties,
7676
largeThreshold?: number,
77-
presence?: any,
77+
presence?: PresenceOptions,
7878
reconnectDelay?: number,
7979
reconnectMax?: number,
8080
shardCount?: number,
@@ -222,48 +222,44 @@ export class Socket extends EventEmitter {
222222
}
223223
}
224224

225-
makePresence(
226-
options?: PresenceOptions,
227-
): PresenceData {
225+
makePresence(options?: PresenceOptions): RawPresence {
228226
options = this.presence = Object.assign({}, defaultPresence, this.presence, options);
229-
const activities: Array<PresenceActivity> = [...(options.activities || [])];
230227

231-
const data: PresenceData = {
228+
const data: RawPresence = {
229+
activities: [],
232230
afk: options.afk,
233231
since: options.since,
234232
status: options.status,
235233
};
236234

237-
if (options.activity || options.game) {
238-
if (options.activity) {
239-
activities.unshift(options.activity);
240-
}
241-
if (options.game) {
242-
activities.unshift(options.game);
243-
}
235+
const activities: Array<PresenceActivityOptions> = [...(options.activities || [])];
236+
if (options.activity) {
237+
activities.unshift(options.activity);
238+
}
239+
if (options.game) {
240+
activities.unshift(options.game);
244241
}
245242

246243
if (activities.length) {
247-
data.activities = [];
248244
for (let activity of activities) {
249-
const raw: any = {
245+
const raw: RawPresenceActivity = {
250246
application_id: activity.applicationId,
251-
assets: activity.assets,
252-
created_at: activity.createdAt,
247+
assets: undefined,
253248
details: activity.details,
254-
emoji: activity.emoji,
249+
emoji: undefined,
255250
flags: activity.flags,
256251
metadata: activity.metadata,
257252
name: activity.name,
258-
party: activity.party,
259-
secrets: activity.secrets,
253+
party: undefined,
254+
secrets: undefined,
260255
session_id: activity.sessionId,
261256
state: activity.state,
262257
sync_id: activity.syncId,
263-
timestamps: activity.timestamps,
258+
timestamps: undefined,
264259
type: activity.type,
265260
url: activity.url,
266261
};
262+
267263
if (activity.assets) {
268264
raw.assets = {
269265
large_image: activity.assets.largeImage,
@@ -984,7 +980,7 @@ export interface IdentifyData {
984980
compress?: boolean,
985981
guild_subscriptions?: boolean,
986982
large_threshold?: number,
987-
presence?: PresenceData,
983+
presence?: RawPresence,
988984
properties: IdentifyDataProperties,
989985
shard?: Array<number>,
990986
token: string,
@@ -1008,15 +1004,67 @@ export interface IdentifyDataProperties {
10081004
window_manager?: string,
10091005
}
10101006

1011-
export interface PresenceActivity {
1007+
export interface RawPresenceActivity {
1008+
application_id?: string,
1009+
assets?: {
1010+
large_image?: string,
1011+
large_text?: string,
1012+
small_image?: string,
1013+
small_text?: string,
1014+
},
1015+
details?: string,
1016+
emoji?: {
1017+
animated: boolean,
1018+
id: null | string,
1019+
name: string,
1020+
},
1021+
flags?: number,
1022+
id?: string,
1023+
instance?: boolean,
1024+
metadata?: {[key: string]: any},
1025+
name: string,
1026+
party?: {
1027+
id?: string,
1028+
size?: Array<[number, number]>,
1029+
},
1030+
secrets?: {
1031+
join?: string,
1032+
match?: string,
1033+
spectate?: string,
1034+
},
1035+
session_id?: string,
1036+
state?: string,
1037+
sync_id?: string,
1038+
timestamps?: {
1039+
end?: number,
1040+
start?: number,
1041+
},
1042+
type: number,
1043+
url?: string,
1044+
}
1045+
1046+
export interface RawPresence {
1047+
activities: Array<RawPresenceActivity>,
1048+
afk: boolean,
1049+
since: number,
1050+
status: string,
1051+
}
1052+
1053+
export interface ResumeData {
1054+
seq?: null | number,
1055+
session_id: null | string,
1056+
token: string,
1057+
}
1058+
1059+
1060+
export interface PresenceActivityOptions {
10121061
applicationId?: string,
10131062
assets?: {
10141063
largeImage?: string,
10151064
largeText?: string,
10161065
smallImage?: string,
10171066
smallText?: string,
10181067
},
1019-
createdAt?: number,
10201068
details?: string,
10211069
emoji?: {
10221070
animated: boolean,
@@ -1046,21 +1094,11 @@ export interface PresenceActivity {
10461094
url?: string,
10471095
}
10481096

1049-
export interface PresenceData {
1050-
activities?: Array<PresenceActivity>,
1097+
export interface PresenceOptions {
1098+
activities?: Array<PresenceActivityOptions>,
1099+
activity?: PresenceActivityOptions,
10511100
afk: boolean,
1052-
game?: PresenceActivity,
1101+
game?: PresenceActivityOptions,
10531102
since: number,
10541103
status: string,
10551104
}
1056-
1057-
export interface PresenceOptions extends PresenceData {
1058-
activity?: PresenceActivity,
1059-
game?: PresenceActivity,
1060-
}
1061-
1062-
export interface ResumeData {
1063-
seq?: null | number,
1064-
session_id: null | string,
1065-
token: string,
1066-
}

0 commit comments

Comments
 (0)