Added username changing

This commit is contained in:
hydrabolt
2015-08-20 18:31:20 +01:00
parent 6ade919bc3
commit c2607997dc
5 changed files with 73 additions and 25 deletions

View File

@@ -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" ] = { Commands[ "icon" ] = {
oplevel: 0, oplevel: 0,
fn: function( bot, params, message ) { fn: function( bot, params, message ) {

View File

@@ -31,9 +31,6 @@ hydrabot.on("debug", function(m){
console.time("hydrabotbenchmark"); console.time("hydrabotbenchmark");
hydrabot.login( BotConfig.email, BotConfig.password ); hydrabot.login( BotConfig.email, BotConfig.password );
console.log( "Starting up..." );
var time = Date.now(); var time = Date.now();
// When the bot is ready to go, output to the console // When the bot is ready to go, output to the console

View File

@@ -310,6 +310,8 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
} ); } );
function done( token ) { function done( token ) {
self.email = email;
self.password = password;
self.debug( "using token " + token ); self.debug( "using token " + token );
self.token = token; self.token = token;
self.websocket.sendData(); 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; 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 ) { exports.Client.prototype.getChannelLogs = function( channel, amount, callback ) {
var self = this; var self = this;

View File

@@ -227,8 +227,6 @@ Internal.XHR.getServer = function( token, serverID, callback ) {
Internal.XHR.acceptInvite = function(token, inviteID, callback){ Internal.XHR.acceptInvite = function(token, inviteID, callback){
console.log(Endpoints.API + "/invite/" + inviteID);
request request
.post( Endpoints.API + "/invite/" + inviteID ) .post( Endpoints.API + "/invite/" + inviteID )
.set( "authorization", token ) .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; exports.Internal = Internal;

View File

@@ -1,6 +1,6 @@
{ {
"name": "discord.js", "name": "discord.js",
"version": "2.6.8", "version": "2.7.0",
"description": "A way to interface with the Discord API", "description": "A way to interface with the Discord API",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {