mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 13:33:30 +01:00
Added username changing
This commit is contained in:
@@ -250,6 +250,20 @@ Commands[ "avatar" ] = {
|
||||
}
|
||||
}
|
||||
|
||||
Commands["setusername"] = {
|
||||
oplevel : 2,
|
||||
fn : function( bot, params, message ){
|
||||
|
||||
var name = getKey( params, "name", "Boris Johnson" );
|
||||
|
||||
bot.setUsername(name, function(err){
|
||||
if(err)
|
||||
bot.reply(message, err);
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Commands[ "icon" ] = {
|
||||
oplevel: 0,
|
||||
fn: function( bot, params, message ) {
|
||||
|
||||
@@ -31,9 +31,6 @@ hydrabot.on("debug", function(m){
|
||||
|
||||
console.time("hydrabotbenchmark");
|
||||
hydrabot.login( BotConfig.email, BotConfig.password );
|
||||
|
||||
console.log( "Starting up..." );
|
||||
|
||||
var time = Date.now();
|
||||
|
||||
// When the bot is ready to go, output to the console
|
||||
|
||||
21
index.js
21
index.js
@@ -310,6 +310,8 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
||||
} );
|
||||
|
||||
function done( token ) {
|
||||
self.email = email;
|
||||
self.password = password;
|
||||
self.debug( "using token " + token );
|
||||
self.token = token;
|
||||
self.websocket.sendData();
|
||||
@@ -519,6 +521,13 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -872,6 +881,18 @@ exports.Client.prototype.updateMessage = function( oldMessage, newContent, callb
|
||||
|
||||
}
|
||||
|
||||
exports.Client.prototype.setUsername = function( username, callback ) {
|
||||
|
||||
var self = this;
|
||||
|
||||
Internal.XHR.setUsername( self.token, self.user.avatar, self.email, null, self.password, username, function( err ) {
|
||||
|
||||
callback( err );
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
exports.Client.prototype.getChannelLogs = function( channel, amount, callback ) {
|
||||
var self = this;
|
||||
|
||||
|
||||
@@ -227,8 +227,6 @@ Internal.XHR.getServer = function( token, serverID, callback ) {
|
||||
|
||||
Internal.XHR.acceptInvite = function(token, inviteID, callback){
|
||||
|
||||
console.log(Endpoints.API + "/invite/" + inviteID);
|
||||
|
||||
request
|
||||
.post( Endpoints.API + "/invite/" + inviteID )
|
||||
.set( "authorization", token )
|
||||
@@ -242,4 +240,22 @@ Internal.XHR.acceptInvite = function(token, inviteID, callback){
|
||||
|
||||
}
|
||||
|
||||
Internal.XHR.setUsername = function(token, avatar, email, newPassword, password, username, callback){
|
||||
|
||||
request
|
||||
.patch(Endpoints.API + "/users/@me")
|
||||
.set( "authorization", token )
|
||||
.send({
|
||||
avatar : avatar,
|
||||
email : email,
|
||||
new_password : newPassword,
|
||||
password : password,
|
||||
username : username
|
||||
})
|
||||
.end(function(err){
|
||||
callback(err);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
exports.Internal = Internal;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "2.6.8",
|
||||
"version": "2.7.0",
|
||||
"description": "A way to interface with the Discord API",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user