discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.38k stars 3.97k forks source link

messageUpdated event new user object and old user object are same #142

Closed Lord-Ptolemy closed 8 years ago

Lord-Ptolemy commented 8 years ago

http://discordjs.readthedocs.org/en/stable/docs_client.html#messageupdated Discord.js: NPM 5.3.2 Node: LTS 4.2.3

bot.on('messageUpdated', function(newMSG, oldMSG) {
    console.log('[' + timestamp + '] ' + 'MESSAGE UPDATE: ' + newMSG.author.username + '[' + newMSG.author.id  + "] updated message. " + oldMSG.content  + ' --> ' + newMSG.content );
    if (newMSG.channel.server.id === '42463947818795009' || newMSG.channel.server.id === '97805743893270528' || newMSG.channel.server.id === '102588320181125120') {
        badWord(newMSG);
    }
});
WARNING! Inappropriate Word detected! by Lord Ptolemy [afk][102529479179509760] in Uskarian Servers[102588320181125120]/general[102588320181125120]: fuck

[Tue, 12 Jan 2016 03:08:17 GMT] MESSAGE UPDATE: Lord Ptolemy [afk][102529479179509760] updated message. fuck tub --> fuck tub

newMSG & oldMSG are the same.

Am I just missing something or is it really broken?

TehSeph commented 8 years ago

It looks like the event is passing a reference to the original Message object instead of a copy or entirely new Message object. So when the original cached object gets updated in the line before the event is fired, the reference is updated as well, and both messages being passed are the new message.

abalabahaha commented 8 years ago

can someone test latest indev

TehSeph commented 8 years ago

The problem I mentioned above is still in Indev. InternalClient.js - L1167, L1181, & L1182

abalabahaha commented 8 years ago

Check 76ab439... I may or may not have forgotten to push.

TehSeph commented 8 years ago

Oh, weird. That didn't show up for me like 5 mins ago when I made that comment linking the code. Okay, yeah, possibly fixed. Can test in just a few moments.

Edit: Nope still the same. The issue comes from msg being a reference, not the update to nmsg coming before or after the event is fired.

~~Edit 2: Helps if I update my discord.js to indev before testing... ¬_¬ It looks fixed to me. @Lord-Ptolemy confirm?~~

(final?) Edit: Nope. Initial testing was fine, but further testing shows it's still borked.

zaza7 commented 8 years ago

Running latest indev version, can confirm messageUpdated is now showing the old message and new message properly.

khionu commented 8 years ago

Confirmed fixed, indev

abalabahaha commented 8 years ago

This wasn't entirely fixed... Check in next time :P

khionu commented 8 years ago

< Will do..