mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Changing the clients username will trigger a userupdate
This commit is contained in:
@@ -251,7 +251,7 @@ Commands[ "avatar" ] = {
|
||||
}
|
||||
|
||||
Commands["setusername"] = {
|
||||
oplevel : 2,
|
||||
oplevel : 3,
|
||||
fn : function( bot, params, message ){
|
||||
|
||||
var name = getKey( params, "name", "Boris Johnson" );
|
||||
|
||||
@@ -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
|
||||
|
||||
5
index.js
5
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10
lib/list.js
10
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 ];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user