mirror of
https://github.com/danbulant/discord.js
synced 2026-05-24 20:42:27 +00:00
Changing the clients username will trigger a userupdate
This commit is contained in:
parent
be787e0951
commit
68db1f6ac0
4 changed files with 31 additions and 3 deletions
|
|
@ -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 ];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue