mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
Fixed typing and added createChannel
This commit is contained in:
@@ -251,6 +251,8 @@ var Client = (function (_EventEmitter) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// def leaveServer
|
||||||
|
|
||||||
Client.prototype.leaveServer = function leaveServer(server) {
|
Client.prototype.leaveServer = function leaveServer(server) {
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||||
|
|
||||||
@@ -265,6 +267,26 @@ var Client = (function (_EventEmitter) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// def createChannel
|
||||||
|
|
||||||
|
Client.prototype.createChannel = function createChannel(server, name) {
|
||||||
|
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||||
|
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, channel) {} : arguments[3];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
if (typeof type === "function") {
|
||||||
|
// options is the callback
|
||||||
|
callback = type;
|
||||||
|
}
|
||||||
|
self.internal.createChannel(server, name, type).then(function (channel) {
|
||||||
|
callback(channel);resolve(channel);
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return Client;
|
return Client;
|
||||||
})(EventEmitter);
|
})(EventEmitter);
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,35 @@ var InternalClient = (function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// def createChannel
|
||||||
|
|
||||||
|
InternalClient.prototype.createChannel = function createChannel(server, name) {
|
||||||
|
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
server = self.resolver.resolveServer(server);
|
||||||
|
|
||||||
|
request.post(Endpoints.SERVER_CHANNELS(server.id)).set("authorization", self.token).send({
|
||||||
|
name: name, type: type
|
||||||
|
}).end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
var channel;
|
||||||
|
if (res.body.type === "text") {
|
||||||
|
channel = new TextChannel(res.body, self.client, server);
|
||||||
|
} else {
|
||||||
|
channel = new VoiceChannel(res.body, self.client, server);
|
||||||
|
}
|
||||||
|
resolve(server.channels.add(self.channels.add(channel)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
InternalClient.prototype.sendWS = function sendWS(object) {
|
InternalClient.prototype.sendWS = function sendWS(object) {
|
||||||
if (this.websocket) this.websocket.send(JSON.stringify(object));
|
if (this.websocket) this.websocket.send(JSON.stringify(object));
|
||||||
};
|
};
|
||||||
@@ -760,11 +789,14 @@ var InternalClient = (function () {
|
|||||||
var channel = self.channels.get("id", data.channel_id);
|
var channel = self.channels.get("id", data.channel_id);
|
||||||
|
|
||||||
if (user && channel) {
|
if (user && channel) {
|
||||||
|
if (user.typing.since) {
|
||||||
|
user.typing.since = Date.now();
|
||||||
|
user.typing.channel = channel;
|
||||||
|
} else {
|
||||||
user.typing.since = Date.now();
|
user.typing.since = Date.now();
|
||||||
user.typing.channel = channel;
|
user.typing.channel = channel;
|
||||||
client.emit("userTypingStart", user, channel);
|
client.emit("userTypingStart", user, channel);
|
||||||
|
}
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (Date.now() - user.typing.since > 5990) {
|
if (Date.now() - user.typing.since > 5990) {
|
||||||
// they haven't typed since
|
// they haven't typed since
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ a.on("warn", function (m) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
a.on("message", function (m) {
|
a.on("message", function (m) {
|
||||||
if (m.content === "$$$") a.reply(m, "I have you cached as being " + m.author.status);
|
if (m.content === "$$$") a.createChannel(m.channel.server, "quackducks").then(function (c) {
|
||||||
|
|
||||||
|
a.sendMessage(c, "I'm alive!");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
a.on("userTypingStart", function (user, chan) {
|
a.on("userTypingStart", function (user, chan) {
|
||||||
console.log(user.username + " typing");
|
console.log(user.username + " typing");
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ class Client extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// def leaveServer
|
||||||
leaveServer(server, callback=function(err){}){
|
leaveServer(server, callback=function(err){}){
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -241,6 +242,25 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// def createChannel
|
||||||
|
createChannel(server, name, type="text", callback=function(err,channel){}){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof type === "function") {
|
||||||
|
// options is the callback
|
||||||
|
callback = type;
|
||||||
|
}
|
||||||
|
self.internal.createChannel(server, name, type)
|
||||||
|
.then((channel) => {
|
||||||
|
callback(channel); resolve(channel);
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
callback(e); reject(e);
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
@@ -414,6 +414,38 @@ class InternalClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// def createChannel
|
||||||
|
createChannel(server, name, type = "text") {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
server = self.resolver.resolveServer(server);
|
||||||
|
|
||||||
|
request
|
||||||
|
.post(Endpoints.SERVER_CHANNELS(server.id))
|
||||||
|
.set("authorization", self.token)
|
||||||
|
.send({
|
||||||
|
name, type
|
||||||
|
})
|
||||||
|
.end((err, res) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
var channel;
|
||||||
|
if (res.body.type === "text") {
|
||||||
|
channel = new TextChannel(res.body, self.client, server);
|
||||||
|
} else {
|
||||||
|
channel = new VoiceChannel(res.body, self.client, server);
|
||||||
|
}
|
||||||
|
resolve(server.channels.add(self.channels.add(channel)));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sendWS(object) {
|
sendWS(object) {
|
||||||
if (this.websocket)
|
if (this.websocket)
|
||||||
this.websocket.send(JSON.stringify(object));
|
this.websocket.send(JSON.stringify(object));
|
||||||
@@ -788,11 +820,14 @@ class InternalClient {
|
|||||||
var channel = self.channels.get("id", data.channel_id);
|
var channel = self.channels.get("id", data.channel_id);
|
||||||
|
|
||||||
if (user && channel) {
|
if (user && channel) {
|
||||||
|
if (user.typing.since) {
|
||||||
|
user.typing.since = Date.now();
|
||||||
|
user.typing.channel = channel;
|
||||||
|
} else {
|
||||||
user.typing.since = Date.now();
|
user.typing.since = Date.now();
|
||||||
user.typing.channel = channel;
|
user.typing.channel = channel;
|
||||||
client.emit("userTypingStart", user, channel);
|
client.emit("userTypingStart", user, channel);
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (Date.now() - user.typing.since > 5990) {
|
if (Date.now() - user.typing.since > 5990) {
|
||||||
// they haven't typed since
|
// they haven't typed since
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ a.on("warn", (m) => console.log("[warn]", m));
|
|||||||
|
|
||||||
a.on("message", m => {
|
a.on("message", m => {
|
||||||
if(m.content === "$$$")
|
if(m.content === "$$$")
|
||||||
a.reply(m, "I have you cached as being " + m.author.status);
|
a.createChannel(m.channel.server, "quackducks").then( c => {
|
||||||
|
|
||||||
|
a.sendMessage(c, "I'm alive!");
|
||||||
|
|
||||||
|
} );
|
||||||
});
|
});
|
||||||
a.on("userTypingStart", (user, chan) => {
|
a.on("userTypingStart", (user, chan) => {
|
||||||
console.log(user.username + " typing");
|
console.log(user.username + " typing");
|
||||||
|
|||||||
Reference in New Issue
Block a user