Added startTyping stopTyping and added serverchannel.mention()

This commit is contained in:
hydrabolt
2015-11-19 16:33:25 +00:00
parent 0fdcf827d0
commit c74b5dbd3f
7 changed files with 185 additions and 56 deletions

View File

@@ -46,6 +46,7 @@ var InternalClient = (function () {
this.channels = new Cache();
this.servers = new Cache();
this.private_channels = new Cache();
this.typingIntervals = [];
this.voiceConnection = null;
this.resolver = new Resolver(this);
this.readyTime = null;
@@ -934,6 +935,53 @@ var InternalClient = (function () {
});
};
//def startTyping
InternalClient.prototype.startTyping = function startTyping(channel) {
var self = this;
return new Promise(function (resolve, reject) {
self.resolver.resolveChannel(channel).then(next)["catch"](reject);
function next(channel) {
if (self.typingIntervals[channel.id]) {
// typing interval already exists, leave it alone
reject(new Error("Already typing in that channel"));
return;
}
self.sendTyping(channel);
self.typingIntervals[channel.id] = setInterval(function () {
return self.sendTyping(channel);
}, 4000);
}
});
};
//def stopTyping
InternalClient.prototype.stopTyping = function stopTyping(channel) {
var self = this;
return new Promise(function (resolve, reject) {
self.resolver.resolveChannel(channel).then(next)["catch"](reject);
function next(channel) {
if (!self.typingIntervals[channel.id]) {
// typing interval doesn't exist
reject(new Error("Not typing in that channel"));
return;
}
clearInterval(self.typingIntervals[channel.id]);
self.typingIntervals[channel.id] = false;
}
});
};
//def setTopic
InternalClient.prototype.setTopic = function setTopic(chann) {