mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19: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"] = {
|
Commands["setusername"] = {
|
||||||
oplevel : 2,
|
oplevel : 3,
|
||||||
fn : function( bot, params, message ){
|
fn : function( bot, params, message ){
|
||||||
|
|
||||||
var name = getKey( params, "name", "Boris Johnson" );
|
var name = getKey( params, "name", "Boris Johnson" );
|
||||||
|
|||||||
@@ -38,6 +38,23 @@ hydrabot.on( "ready", function() {
|
|||||||
console.timeEnd("hydrabotbenchmark");
|
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.
|
// When the bot gets disconnected, exit.
|
||||||
hydrabot.on( "disconnected", function( obj ) {
|
hydrabot.on( "disconnected", function( obj ) {
|
||||||
// Say we couldn't connect and then exit
|
// 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" ) {
|
} else if ( dat.t === "USER_UPDATE" ) {
|
||||||
|
|
||||||
if ( dat.d.id === self.user.id ) {
|
if ( dat.d.id === self.user.id ) {
|
||||||
self.user.username = dat.d.username;
|
var newUsr = new User(dat.d);
|
||||||
self.user.avatar = dat.d.avatar;
|
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;
|
var buffer = child;
|
||||||
|
|
||||||
for ( key of keys ) {
|
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 ];
|
buffer = buffer[ key ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user