diff --git a/hydrabot/commands.js b/hydrabot/commands.js index 9f9418207..9b16381ee 100644 --- a/hydrabot/commands.js +++ b/hydrabot/commands.js @@ -251,7 +251,7 @@ Commands[ "avatar" ] = { } Commands["setusername"] = { - oplevel : 2, + oplevel : 3, fn : function( bot, params, message ){ var name = getKey( params, "name", "Boris Johnson" ); diff --git a/hydrabot/hydrabot.js b/hydrabot/hydrabot.js index cfc3ea386..4732de3e8 100644 --- a/hydrabot/hydrabot.js +++ b/hydrabot/hydrabot.js @@ -38,6 +38,23 @@ hydrabot.on( "ready", function() { console.timeEnd("hydrabotbenchmark"); } ); +hydrabot.on("userupdate", function(ol, ne){ + + var serversInvolved = hydrabot.getServers().deepFilter(["members", "id"], ol.id); + + console.log(serversInvolved); + + for(server of serversInvolved.contents){ + console.log("gra", server); + hydrabot.sendMessage(server.getDefaultChannel(), "Just sayin', "+ol.username+" changed their name to "+ne.username+". I know. Disgraceful.", function(err){ + console.log(err); + }, { + selfDestruct: 5000 + }); + } + +}); + // When the bot gets disconnected, exit. hydrabot.on( "disconnected", function( obj ) { // Say we couldn't connect and then exit diff --git a/index.js b/index.js index 42376402c..dcd31eea3 100644 --- a/index.js +++ b/index.js @@ -535,8 +535,9 @@ exports.Client.prototype.connectWebsocket = function( cb ) { } else if ( dat.t === "USER_UPDATE" ) { if ( dat.d.id === self.user.id ) { - self.user.username = dat.d.username; - self.user.avatar = dat.d.avatar; + var newUsr = new User(dat.d); + self.triggerEvent("userupdate", [self.user, newUsr]); + self.user = newUsr; } } diff --git a/lib/list.js b/lib/list.js index d804e4c68..5ad268523 100644 --- a/lib/list.js +++ b/lib/list.js @@ -208,6 +208,16 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne, caseInsen ) var buffer = child; for ( key of keys ) { + if(buffer instanceof exports.List){ + buffer = buffer.contents; + } + if(buffer instanceof Array){ + for(elem of buffer){ + if( change(elem[key]) == value ){ + buffer = elem; + } + } + } buffer = buffer[ key ]; }