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

@@ -40,6 +40,7 @@ class InternalClient {
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;
@@ -997,6 +998,55 @@ class InternalClient {
});
}
//def startTyping
startTyping(channel){
var self = this;
return new Promise((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(
() => self.sendTyping(channel), 4000
);
}
});
}
//def stopTyping
stopTyping(channel){
var self = this;
return new Promise((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
setTopic(chann, topic = "") {