From 1b75753a3d7b5bf15fbcc787897bf4ed797bbfaf Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sat, 14 Apr 2018 15:15:03 +0100 Subject: [PATCH] Add user status/activity --- client/src/modules/discordapi.js | 1 + client/src/structs/discord/user.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/client/src/modules/discordapi.js b/client/src/modules/discordapi.js index a3f7c2a2..b1154aec 100644 --- a/client/src/modules/discordapi.js +++ b/client/src/modules/discordapi.js @@ -33,6 +33,7 @@ export const Modules = { get UserStore() { return this._getModule('UserStore'); }, get RelationshipStore() { return this._getModule('RelationshipStore'); }, get RelationshipManager() { return this._getModule('RelationshipManager'); }, + get UserStatusStore() { return this._getModule('UserStatusStore'); }, get DiscordPermissions() { return this.DiscordConstants.Permissions; } }; diff --git a/client/src/structs/discord/user.js b/client/src/structs/discord/user.js index 210c7066..5ab98c5b 100644 --- a/client/src/structs/discord/user.js +++ b/client/src/structs/discord/user.js @@ -47,6 +47,20 @@ export class User { return DiscordApi.guilds.filter(g => g.members.find(m => m.id === this.id)); } + get status() { + return Modules.UserStatusStore.getStatus(this.id); + } + + get activity() { + // type can be either 0 (normal/rich presence game), 1 (streaming) or 2 (listening to Spotify) + // (3 appears as watching but is undocumented) + return Modules.UserStatusStore.getActivity(this.id); + } + + get direct_messages() { + return DiscordApi.channels.find(c => c.type === 'DM' && c.recipient_id === this.id); + } + async ensurePrivateChannel() { if (DiscordApi.currentUser.id === this.id) throw new Error('Cannot create a direct message channel to the current user.');