mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
Added message.edit(content)
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -4,7 +4,7 @@
|
|||||||
- [ ] sending files
|
- [ ] sending files
|
||||||
- [ ] updating user details
|
- [ ] updating user details
|
||||||
- [x] deleting messages
|
- [x] deleting messages
|
||||||
- [ ] updating messages
|
- [x] updating messages
|
||||||
- [ ] leaving guilds
|
- [ ] leaving guilds
|
||||||
- [ ] deleting guilds
|
- [ ] deleting guilds
|
||||||
- [ ] _joining guilds_
|
- [ ] _joining guilds_
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class ActionsManager {
|
|||||||
|
|
||||||
this.register('MessageCreate');
|
this.register('MessageCreate');
|
||||||
this.register('MessageDelete');
|
this.register('MessageDelete');
|
||||||
|
this.register('MessageUpdate');
|
||||||
}
|
}
|
||||||
|
|
||||||
register(name) {
|
register(name) {
|
||||||
|
|||||||
38
src/client/actions/MessageUpdate.js
Normal file
38
src/client/actions/MessageUpdate.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Action = require('./Action');
|
||||||
|
const Constants = require('../../util/Constants');
|
||||||
|
const CloneObject = require('../../util/CloneObject');
|
||||||
|
const Message = require('../../structures/Message');
|
||||||
|
|
||||||
|
class MessageUpdateAction extends Action {
|
||||||
|
|
||||||
|
constructor(client) {
|
||||||
|
super(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle(data) {
|
||||||
|
|
||||||
|
let client = this.client;
|
||||||
|
let channel = client.store.get('channels', data.channel_id);
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
let message = channel.store.get('messages', data.id);
|
||||||
|
if (message && !message.equals(data, true)) {
|
||||||
|
let oldMessage = CloneObject(message);
|
||||||
|
message.patch(data);
|
||||||
|
return {
|
||||||
|
old: oldMessage,
|
||||||
|
updated: message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
old: null,
|
||||||
|
updated: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = MessageUpdateAction;
|
||||||
@@ -60,6 +60,18 @@ class RESTMethods{
|
|||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateMessage(message, content) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true, {
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
resolve(this.rest.client.actions.MessageUpdate.handle(data).updated);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RESTMethods;
|
module.exports = RESTMethods;
|
||||||
|
|||||||
@@ -17,15 +17,11 @@ class MessageUpdateHandler extends AbstractHandler {
|
|||||||
handle(packet) {
|
handle(packet) {
|
||||||
let data = packet.d;
|
let data = packet.d;
|
||||||
let client = this.packetManager.client;
|
let client = this.packetManager.client;
|
||||||
let channel = client.store.get('channels', data.channel_id);
|
|
||||||
|
|
||||||
if (channel) {
|
let response = client.actions.MessageUpdate.handle(data);
|
||||||
let message = channel.store.get('messages', data.id);
|
|
||||||
if (message) {
|
if (response.old) {
|
||||||
let oldMessage = CloneObject(message);
|
client.emit(Constants.Events.MESSAGE_UPDATE, response.old, response.updated);
|
||||||
message.patch(data);
|
|
||||||
client.emit(Constants.Events.MESSAGE_UPDATE, oldMessage, message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,9 +72,40 @@ class Message {
|
|||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equals(message, rawData) {
|
||||||
|
|
||||||
|
let embedUpdate = !message.author && !message.attachments;
|
||||||
|
|
||||||
|
if (embedUpdate) {
|
||||||
|
let base = this.id === message.id &&
|
||||||
|
this.embeds.length === message.embeds.length;
|
||||||
|
return base;
|
||||||
|
} else {
|
||||||
|
let base = this.id === message.id &&
|
||||||
|
this.author.id === message.author.id &&
|
||||||
|
this.content === message.content &&
|
||||||
|
this.tts === message.tts &&
|
||||||
|
this.nonce === message.nonce &&
|
||||||
|
this.embeds.length === message.embeds.length &&
|
||||||
|
this.attachments.length === message.attachments.length;
|
||||||
|
|
||||||
|
if (base && rawData) {
|
||||||
|
base = this.mentionEveryone === message.mentionEveryone &&
|
||||||
|
this.timestamp.getTime() === new Date(data.timestamp).getTime() &&
|
||||||
|
this.editedTimestamp === new Date(data.edited_timestamp).getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete() {
|
delete() {
|
||||||
return this.client.rest.methods.DeleteMessage(this);
|
return this.client.rest.methods.DeleteMessage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit(content) {
|
||||||
|
return this.client.rest.methods.UpdateMessage(this, content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Message;
|
module.exports = Message;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ client.on('typingStop.', (channel, user, data) => {
|
|||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
if (message.author.username === 'hydrabolt') {
|
if (message.author.username === 'hydrabolt') {
|
||||||
message.channel.sendMessage('test').then(msg => {
|
message.channel.sendMessage('test').then(msg => {
|
||||||
msg.delete().catch(console.log);
|
msg.edit('woah!');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user