mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Added startTyping stopTyping and added serverchannel.mention()
This commit is contained in:
@@ -641,6 +641,42 @@ class Client extends EventEmitter {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//def startTyping
|
||||
startTyping(channel, callback = function (err) { }) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
self.internal.startTyping(channel)
|
||||
.then(() => {
|
||||
callback(null);
|
||||
resolve();
|
||||
})
|
||||
.catch(e => {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//def stopTyping
|
||||
stopTyping(channel, callback = function (err) { }) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
self.internal.stopTyping(channel)
|
||||
.then(() => {
|
||||
callback(null);
|
||||
resolve();
|
||||
})
|
||||
.catch(e => {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//def joinVoiceChannel
|
||||
joinVoiceChannel(channel, callback=function(err){}){
|
||||
|
||||
@@ -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 = "") {
|
||||
|
||||
@@ -60,9 +60,13 @@ class ServerChannel extends Channel{
|
||||
permsOf(user){
|
||||
return this.permissionsOf(user);
|
||||
}
|
||||
|
||||
mention(){
|
||||
return `<#${this.id}>`;
|
||||
}
|
||||
|
||||
toString(){
|
||||
return `<#${this.id}>`;
|
||||
return this.mention();
|
||||
}
|
||||
|
||||
setName(){
|
||||
|
||||
Reference in New Issue
Block a user