mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
Reformat code
This commit is contained in:
252
src/Client.js
252
src/Client.js
@@ -56,7 +56,7 @@ class Client {
|
|||||||
this.checkingQueue = {};
|
this.checkingQueue = {};
|
||||||
this.userTypingListener = {};
|
this.userTypingListener = {};
|
||||||
this.queue = {};
|
this.queue = {};
|
||||||
|
|
||||||
this.__idleTime = null;
|
this.__idleTime = null;
|
||||||
this.__gameId = null;
|
this.__gameId = null;
|
||||||
}
|
}
|
||||||
@@ -399,15 +399,15 @@ class Client {
|
|||||||
|
|
||||||
function remove() {
|
function remove() {
|
||||||
request
|
request
|
||||||
.del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
.del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if(err){
|
if (err) {
|
||||||
bad();
|
bad();
|
||||||
}else{
|
} else {
|
||||||
good();
|
good();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function good() {
|
function good() {
|
||||||
@@ -420,7 +420,7 @@ class Client {
|
|||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMessage(message, content, callback = function (err, msg) { }) {
|
updateMessage(message, content, callback = function (err, msg) { }) {
|
||||||
@@ -757,7 +757,7 @@ class Client {
|
|||||||
self.trigger("error", err, e);
|
self.trigger("error", err, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.trigger("raw", dat);
|
self.trigger("raw", dat);
|
||||||
|
|
||||||
//valid message
|
//valid message
|
||||||
@@ -1007,46 +1007,46 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "CHANNEL_UPDATE":
|
case "CHANNEL_UPDATE":
|
||||||
|
|
||||||
var channelInCache = self.getChannel("id", data.id),
|
var channelInCache = self.getChannel("id", data.id),
|
||||||
serverInCache = self.getServer("id", data.guild_id);
|
serverInCache = self.getServer("id", data.guild_id);
|
||||||
|
|
||||||
if(channelInCache && serverInCache){
|
if (channelInCache && serverInCache) {
|
||||||
|
|
||||||
var newChann = new Channel(data, serverInCache);
|
var newChann = new Channel(data, serverInCache);
|
||||||
newChann.messages = channelInCache.messages;
|
newChann.messages = channelInCache.messages;
|
||||||
|
|
||||||
self.trigger("channelUpdate", channelInCache, newChann);
|
self.trigger("channelUpdate", channelInCache, newChann);
|
||||||
|
|
||||||
self.channelCache[ self.channelCache.indexOf(channelInCache) ] = newChann;
|
self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "TYPING_START":
|
case "TYPING_START":
|
||||||
|
|
||||||
var userInCache = self.getUser("id", data.user_id);
|
var userInCache = self.getUser("id", data.user_id);
|
||||||
var channelInCache = self.getChannel("id", data.channel_id);
|
var channelInCache = self.getChannel("id", data.channel_id);
|
||||||
|
|
||||||
if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){
|
if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) {
|
||||||
self.trigger("startTyping", userInCache, channelInCache);
|
self.trigger("startTyping", userInCache, channelInCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.userTypingListener[data.user_id] = Date.now();
|
self.userTypingListener[data.user_id] = Date.now();
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function () {
|
||||||
if(self.userTypingListener[data.user_id] === -1){
|
if (self.userTypingListener[data.user_id] === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( Date.now() - self.userTypingListener[data.user_id] > 6000 ){
|
if (Date.now() - self.userTypingListener[data.user_id] > 6000) {
|
||||||
// stopped typing
|
// stopped typing
|
||||||
self.trigger("stopTyping", userInCache, channelInCache);
|
self.trigger("stopTyping", userInCache, channelInCache);
|
||||||
self.userTypingListener[data.user_id] = -1;
|
self.userTypingListener[data.user_id] = -1;
|
||||||
}
|
}
|
||||||
}, 6000);
|
}, 6000);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1082,45 +1082,45 @@ class Client {
|
|||||||
}
|
}
|
||||||
return this.getPMChannel("id", data.id);
|
return this.getPMChannel("id", data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTopic(channel, topic, callback = function(err){}){
|
setTopic(channel, topic, callback = function (err) { }) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
self.resolveDestination(channel).then(next).catch(error);
|
self.resolveDestination(channel).then(next).catch(error);
|
||||||
|
|
||||||
function error(e){
|
function error(e) {
|
||||||
callback(e);
|
callback(e);
|
||||||
reject(e);
|
reject(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
function next(destination){
|
function next(destination) {
|
||||||
|
|
||||||
var asChan = self.getChannel("id", destination);
|
var asChan = self.getChannel("id", destination);
|
||||||
|
|
||||||
request
|
request
|
||||||
.patch(`${Endpoints.CHANNELS}/${destination}`)
|
.patch(`${Endpoints.CHANNELS}/${destination}`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.send({
|
.send({
|
||||||
name : asChan.name,
|
name: asChan.name,
|
||||||
position : 0,
|
position: 0,
|
||||||
topic : topic
|
topic: topic
|
||||||
})
|
})
|
||||||
.end(function(err, res){
|
.end(function (err, res) {
|
||||||
if(err){
|
if (err) {
|
||||||
error(err);
|
error(err);
|
||||||
}else{
|
} else {
|
||||||
asChan.topic = res.body.topic;
|
asChan.topic = res.body.topic;
|
||||||
resolve();
|
resolve();
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//def addServer
|
//def addServer
|
||||||
@@ -1129,7 +1129,7 @@ class Client {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var server = this.getServer("id", data.id);
|
var server = this.getServer("id", data.id);
|
||||||
|
|
||||||
if(data.unavailable){
|
if (data.unavailable) {
|
||||||
self.trigger("unavailable", data);
|
self.trigger("unavailable", data);
|
||||||
self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");
|
self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");
|
||||||
return;
|
return;
|
||||||
@@ -1144,8 +1144,8 @@ class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var presence of data.presences){
|
for (var presence of data.presences) {
|
||||||
self.getUser("id", presence.user.id).status = presence.status;
|
self.getUser("id", presence.user.id).status = presence.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1370,132 +1370,132 @@ class Client {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusIdle(){
|
setStatusIdle() {
|
||||||
this.setStatus("idle");
|
this.setStatus("idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusOnline(){
|
setStatusOnline() {
|
||||||
this.setStatus("online");
|
this.setStatus("online");
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusActive(){
|
setStatusActive() {
|
||||||
this.setStatusOnline();
|
this.setStatusOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusHere(){
|
setStatusHere() {
|
||||||
this.setStatusOnline();
|
this.setStatusOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusAway(){
|
setStatusAway() {
|
||||||
this.setStatusIdle();
|
this.setStatusIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
startTyping(chann, stopTypeTime){
|
startTyping(chann, stopTypeTime) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.resolveDestination(chann).then(next);
|
this.resolveDestination(chann).then(next);
|
||||||
|
|
||||||
function next(channel){
|
function next(channel) {
|
||||||
if(self.typingIntervals[channel]){
|
if (self.typingIntervals[channel]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fn = function(){
|
var fn = function () {
|
||||||
request
|
request
|
||||||
.post(`${Endpoints.CHANNELS}/${channel}/typing`)
|
.post(`${Endpoints.CHANNELS}/${channel}/typing`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.end();
|
.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
fn();
|
fn();
|
||||||
|
|
||||||
var interval = setInterval(fn, 3000);
|
var interval = setInterval(fn, 3000);
|
||||||
|
|
||||||
self.typingIntervals[channel] = interval;
|
self.typingIntervals[channel] = interval;
|
||||||
|
|
||||||
if(stopTypeTime){
|
if (stopTypeTime) {
|
||||||
setTimeout(function(){
|
setTimeout(function () {
|
||||||
self.stopTyping(channel);
|
self.stopTyping(channel);
|
||||||
}, stopTypeTime);
|
}, stopTypeTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopTyping(chann){
|
stopTyping(chann) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.resolveDestination(chann).then(next);
|
this.resolveDestination(chann).then(next);
|
||||||
|
|
||||||
function next(channel){
|
function next(channel) {
|
||||||
if(!self.typingIntervals[channel]){
|
if (!self.typingIntervals[channel]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(self.typingIntervals[channel]);
|
clearInterval(self.typingIntervals[channel]);
|
||||||
|
|
||||||
delete self.typingIntervals[channel];
|
delete self.typingIntervals[channel];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatus(stat){
|
setStatus(stat) {
|
||||||
|
|
||||||
var idleTime = (stat === "online" ? null : Date.now());
|
var idleTime = (stat === "online" ? null : Date.now());
|
||||||
|
|
||||||
this.__idleTime = idleTime;
|
this.__idleTime = idleTime;
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
op : 3,
|
op: 3,
|
||||||
d : {
|
d: {
|
||||||
idle_since : this.__idleTime,
|
idle_since: this.__idleTime,
|
||||||
game_id : this.__gameId
|
game_id: this.__gameId
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
setPlayingGame(id){
|
setPlayingGame(id) {
|
||||||
|
|
||||||
if( id instanceof String || typeof id === `string` ){
|
if (id instanceof String || typeof id === `string`) {
|
||||||
|
|
||||||
// working on names
|
// working on names
|
||||||
var gid = id.trim().toUpperCase();
|
var gid = id.trim().toUpperCase();
|
||||||
|
|
||||||
id = null;
|
id = null;
|
||||||
|
|
||||||
for( var game of gameMap ){
|
for (var game of gameMap) {
|
||||||
|
|
||||||
if(game.name.trim().toUpperCase() === gid){
|
if (game.name.trim().toUpperCase() === gid) {
|
||||||
|
|
||||||
id = game.id;
|
id = game.id;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.__gameId = id;
|
this.__gameId = id;
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
op : 3,
|
op: 3,
|
||||||
d : {
|
d: {
|
||||||
idle_since : this.__idleTime,
|
idle_since: this.__idleTime,
|
||||||
game_id : this.__gameId
|
game_id: this.__gameId
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
playGame(id){
|
playGame(id) {
|
||||||
this.setPlayingGame(id);
|
this.setPlayingGame(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
playingGame(id){
|
playingGame(id) {
|
||||||
|
|
||||||
this.setPlayingGame(id);
|
this.setPlayingGame(id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user