mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Deleted examples, beginning to write in EC6.
Examples and Hydrabot will soon live in a separate repo which is better suited to learning - this is so the main package isn't bloated.
This commit is contained in:
69
src/Client.js
Normal file
69
src/Client.js
Normal file
@@ -0,0 +1,69 @@
|
||||
//discord.js modules
|
||||
var Endpoints = require("./Endpoints.js");
|
||||
|
||||
//node modules
|
||||
var request = require("superagent");
|
||||
|
||||
var defaultOptions = {
|
||||
cache_tokens: false
|
||||
}
|
||||
|
||||
class Client {
|
||||
|
||||
constructor(options = defaultOptions, token = undefined) {
|
||||
/*
|
||||
When created, if a token is specified the Client will
|
||||
try connecting with it. If the token is incorrect, no
|
||||
further efforts will be made to connect.
|
||||
*/
|
||||
this.options = options;
|
||||
this.token = token;
|
||||
this.state = 0;
|
||||
this.websocket = null;
|
||||
this.events = new Map();
|
||||
this.user = null;
|
||||
/*
|
||||
State values:
|
||||
0 - idle
|
||||
1 - logging in
|
||||
2 - logged in
|
||||
3 - ready
|
||||
4 - disconnected
|
||||
*/
|
||||
}
|
||||
|
||||
get ready() {
|
||||
return this.state === 3;
|
||||
}
|
||||
|
||||
//def login
|
||||
login(email = "foo@bar.com", password = "pass1234s", callback = function(){}) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (this.state === 0 || this.state === 4) {
|
||||
|
||||
this.state = 1; //set the state to logging in
|
||||
|
||||
request
|
||||
.post(Endpoints.LOGIN)
|
||||
.send({
|
||||
email : email,
|
||||
password : password
|
||||
}).end(function(err, res){
|
||||
|
||||
if(err){
|
||||
self.state = 4; //set state to disconnected
|
||||
callback(err);
|
||||
}else{
|
||||
self.state = 2; //set state to logged in (not yet ready)
|
||||
self.token = res.body.token;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user