mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Add support for notes (#860)
* Add support for notes * Ensure consistency with notes from ready payload * Add getter method for users * Minor tweaks * Update warning messages * More minor fixes
This commit is contained in:
committed by
Schuyler Cebulskie
parent
a673a97441
commit
6dc95cd084
@@ -21,6 +21,7 @@ class ActionsManager {
|
||||
this.register('GuildRoleUpdate');
|
||||
this.register('UserGet');
|
||||
this.register('UserUpdate');
|
||||
this.register('UserNoteUpdate');
|
||||
this.register('GuildSync');
|
||||
this.register('GuildEmojiCreate');
|
||||
this.register('GuildEmojiDelete');
|
||||
|
||||
30
src/client/actions/UserNoteUpdate.js
Normal file
30
src/client/actions/UserNoteUpdate.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
|
||||
class UserNoteUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const oldNote = client.user.notes.get(data.id);
|
||||
const note = data.note.length ? data.note : null;
|
||||
|
||||
client.user.notes.set(data.id, note);
|
||||
|
||||
client.emit(Constants.Events.USER_NOTE_UPDATE, data.id, oldNote, note);
|
||||
|
||||
return {
|
||||
old: oldNote,
|
||||
updated: note,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a note is updated.
|
||||
* @event Client#userNoteUpdate
|
||||
* @param {User} user The user the note belongs to
|
||||
* @param {string} oldNote The note content before the update
|
||||
* @param {string} newNote The note content after the update
|
||||
*/
|
||||
|
||||
module.exports = UserNoteUpdateAction;
|
||||
@@ -616,6 +616,11 @@ class RESTMethods {
|
||||
new ClientOAuth2Application(this.rest.client, app)
|
||||
);
|
||||
}
|
||||
|
||||
setNote(user, note) {
|
||||
return this.rest.makeRequest('put', Constants.Endpoints.note(user.id), true, { note })
|
||||
.then(() => user);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RESTMethods;
|
||||
|
||||
@@ -33,6 +33,7 @@ class WebSocketPacketManager {
|
||||
this.register(Constants.WSEvents.CHANNEL_UPDATE, 'ChannelUpdate');
|
||||
this.register(Constants.WSEvents.PRESENCE_UPDATE, 'PresenceUpdate');
|
||||
this.register(Constants.WSEvents.USER_UPDATE, 'UserUpdate');
|
||||
this.register(Constants.WSEvents.USER_NOTE_UPDATE, 'UserNoteUpdate');
|
||||
this.register(Constants.WSEvents.VOICE_STATE_UPDATE, 'VoiceStateUpdate');
|
||||
this.register(Constants.WSEvents.TYPING_START, 'TypingStart');
|
||||
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
|
||||
|
||||
@@ -31,6 +31,15 @@ class ReadyHandler extends AbstractHandler {
|
||||
client._setPresence(presence.user.id, presence);
|
||||
}
|
||||
|
||||
if (data.notes) {
|
||||
for (const user in data.notes) {
|
||||
let note = data.notes[user];
|
||||
if (!note.length) note = null;
|
||||
|
||||
client.user.notes.set(user, note);
|
||||
}
|
||||
}
|
||||
|
||||
if (!client.user.bot && client.options.sync) client.setInterval(client.syncGuilds.bind(client), 30000);
|
||||
client.once('ready', client.syncGuilds.bind(client));
|
||||
|
||||
|
||||
12
src/client/websocket/packets/handlers/UserNoteUpdate.js
Normal file
12
src/client/websocket/packets/handlers/UserNoteUpdate.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
|
||||
class UserNoteUpdateHandler extends AbstractHandler {
|
||||
handle(packet) {
|
||||
const client = this.packetManager.client;
|
||||
const data = packet.d;
|
||||
|
||||
client.actions.UserNoteUpdate.handle(data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserNoteUpdateHandler;
|
||||
Reference in New Issue
Block a user