diff --git a/src/client/ClientManager.js b/src/client/ClientManager.js
index 7b1d58a05..4959c7691 100644
--- a/src/client/ClientManager.js
+++ b/src/client/ClientManager.js
@@ -49,7 +49,8 @@ class ClientManager {
* @param {number} time The interval in milliseconds at which heartbeat packets should be sent
*/
setupKeepAlive(time) {
- this.heartbeatInterval = this.client.setInterval(() => this.client.ws.heartbeat(true), time);
+ this.heartbeatInterval = time;
+ this.client.setInterval(() => this.client.ws.heartbeat(true), time);
}
destroy() {
diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js
index 9467e7944..6cba91018 100644
--- a/src/client/rest/RESTMethods.js
+++ b/src/client/rest/RESTMethods.js
@@ -876,6 +876,10 @@ class RESTMethods {
})
);
}
+
+ patchUserSettings(data) {
+ return this.rest.makeRequest('patch', Constants.Endpoints.User('@me').settings, true, data);
+ }
}
module.exports = RESTMethods;
diff --git a/src/client/websocket/packets/WebSocketPacketManager.js b/src/client/websocket/packets/WebSocketPacketManager.js
index 53a4f9c3c..34a608f62 100644
--- a/src/client/websocket/packets/WebSocketPacketManager.js
+++ b/src/client/websocket/packets/WebSocketPacketManager.js
@@ -36,6 +36,7 @@ class WebSocketPacketManager {
this.register(Constants.WSEvents.PRESENCE_UPDATE, require('./handlers/PresenceUpdate'));
this.register(Constants.WSEvents.USER_UPDATE, require('./handlers/UserUpdate'));
this.register(Constants.WSEvents.USER_NOTE_UPDATE, require('./handlers/UserNoteUpdate'));
+ this.register(Constants.WSEvents.USER_SETTINGS_UPDATE, require('./handlers/UserSettingsUpdate'));
this.register(Constants.WSEvents.VOICE_STATE_UPDATE, require('./handlers/VoiceStateUpdate'));
this.register(Constants.WSEvents.TYPING_START, require('./handlers/TypingStart'));
this.register(Constants.WSEvents.MESSAGE_CREATE, require('./handlers/MessageCreate'));
diff --git a/src/client/websocket/packets/handlers/Ready.js b/src/client/websocket/packets/handlers/Ready.js
index 6a644ea17..077d17f29 100644
--- a/src/client/websocket/packets/handlers/Ready.js
+++ b/src/client/websocket/packets/handlers/Ready.js
@@ -9,8 +9,9 @@ class ReadyHandler extends AbstractHandler {
client.ws.heartbeat();
+ data.user.user_settings = data.user_settings;
+
const clientUser = new ClientUser(client, data.user);
- clientUser.settings = data.user_settings;
client.user = clientUser;
client.readyAt = new Date();
client.users.set(clientUser.id, clientUser);
diff --git a/src/client/websocket/packets/handlers/UserSettingsUpdate.js b/src/client/websocket/packets/handlers/UserSettingsUpdate.js
new file mode 100644
index 000000000..24085cf4d
--- /dev/null
+++ b/src/client/websocket/packets/handlers/UserSettingsUpdate.js
@@ -0,0 +1,18 @@
+const AbstractHandler = require('./AbstractHandler');
+const Constants = require('../../../../util/Constants');
+
+class UserSettingsUpdateHandler extends AbstractHandler {
+ handle(packet) {
+ const client = this.packetManager.client;
+ client.user.settings.patch(packet.d);
+ client.emit(Constants.Events.USER_SETTINGS_UPDATE, client.user.settings);
+ }
+}
+
+/**
+ * Emitted when the client user's settings update
+ * @event Client#clientUserSettingsUpdate
+ * @param {ClientUserSettings} clientUserSettings The new client user settings
+ */
+
+module.exports = UserSettingsUpdateHandler;
diff --git a/src/index.js b/src/index.js
index 3abc36a13..b5135973e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -27,6 +27,7 @@ module.exports = {
// Structures
Channel: require('./structures/Channel'),
ClientUser: require('./structures/ClientUser'),
+ ClientUserSettings: require('./structures/ClientUserSettings'),
DMChannel: require('./structures/DMChannel'),
Emoji: require('./structures/Emoji'),
Game: require('./structures/Presence').Game,
diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js
index 15bdb6368..bd54f2390 100644
--- a/src/structures/ClientUser.js
+++ b/src/structures/ClientUser.js
@@ -1,6 +1,6 @@
const User = require('./User');
const Collection = require('../util/Collection');
-
+const ClientUserSettings = require('./ClientUserSettings');
/**
* Represents the logged in client's Discord user
* @extends {User}
@@ -44,13 +44,6 @@ class ClientUser extends User {
*/
this.notes = new Collection();
- /**
- * Discord client settings, such as guild positions
- * This is only filled when using a user account.
- * @type {Object}
- */
- this.settings = {};
-
/**
* If the user has discord premium (nitro)
* This is only filled when using a user account.
@@ -71,6 +64,13 @@ class ClientUser extends User {
* @type {?boolean}
*/
this.mobile = typeof data.mobile === 'boolean' ? data.mobile : null;
+
+ /**
+ * Various settings for this user
+ * @type {?ClientUserSettings}
+ * This is only filled when using a user account
+ */
+ if (data.user_settings) this.settings = new ClientUserSettings(this, data.user_settings);
}
edit(data) {
diff --git a/src/structures/ClientUserSettings.js b/src/structures/ClientUserSettings.js
new file mode 100644
index 000000000..07b23fbca
--- /dev/null
+++ b/src/structures/ClientUserSettings.js
@@ -0,0 +1,77 @@
+const Constants = require('../util/Constants');
+const Util = require('../util/Util');
+
+/**
+ * A wrapper around the ClientUser's settings
+ */
+class ClientUserSettings {
+ constructor(user, data) {
+ this.user = user;
+ this.patch(data);
+ }
+
+ /**
+ * Patch the data contained in this class with new partial data
+ * @param {Object} data Data to patch this with
+ */
+ patch(data) {
+ for (const key of Object.keys(Constants.UserSettingsMap)) {
+ const value = Constants.UserSettingsMap[key];
+ if (!data.hasOwnProperty(key)) continue;
+ if (typeof value === 'function') {
+ this[value.name] = value(data[key]);
+ } else {
+ this[value] = data[key];
+ }
+ }
+ }
+
+ /**
+ * Update a specific property of of user settings
+ * @param {string} name Name of property
+ * @param {value} value Value to patch
+ * @returns {Promise