Add TextBasedChannel.setTyping(bool)

This commit is contained in:
Amish Shah
2016-08-27 21:43:58 +01:00
parent 6faa409e96
commit 6a1a36813f
7 changed files with 46 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -376,6 +376,14 @@ class RESTMethods {
});
}
sendTyping(channelID) {
return new Promise((resolve, reject) => {
this.rest.makeRequest('post', `${Constants.Endpoints.channel(channelID)}/typing`, true)
.then(resolve)
.catch(reject);
});
}
updateGuildRole(role, _data) {
return new Promise((resolve, reject) => {
/*

View File

@@ -17,6 +17,8 @@ class ClientUser extends User {
* @type {String}
*/
this.email = data.email;
this._typing = new Map();
}
/**

View File

@@ -58,6 +58,10 @@ class DMChannel extends Channel {
bulkDelete() {
return;
}
setTyping() {
return;
}
}
TextBasedChannel.applyToClass(DMChannel, true);

View File

@@ -135,6 +135,10 @@ class GroupDMChannel extends Channel {
bulkDelete() {
return;
}
setTyping() {
return;
}
}
TextBasedChannel.applyToClass(GroupDMChannel, true);

View File

@@ -43,6 +43,10 @@ class TextChannel extends GuildChannel {
bulkDelete() {
return;
}
setTyping() {
return;
}
}
TextBasedChannel.applyToClass(TextChannel, true);

View File

@@ -98,6 +98,28 @@ class TextBasedChannel {
});
}
/**
* Starts or stops a typing indicator in the channel.
* <info>It can take a few seconds for the Client User to stop typing.</info>
* @param {Boolean} typing whether or not the client user should be typing
* @returns {null}
* @example
* // start typing in a channel
* channel.setTyping(true);
* @example
* // stop typing in a channel
* channel.setTyping(false);
*/
setTyping(typing) {
clearInterval(this.client.user._typing.get(this.id));
if (typing) {
this.client.user._typing.set(this.id, setInterval(() => {
this.client.rest.methods.sendTyping(this.id);
}, 4000));
this.client.rest.methods.sendTyping(this.id);
}
}
_cacheMessage(message) {
const maxSize = this.client.options.max_message_cache;
if (maxSize === 0) {
@@ -125,6 +147,7 @@ exports.applyToClass = (structure, full = false) => {
props.push('_cacheMessage');
props.push('getMessages');
props.push('bulkDelete');
props.push('setTyping');
}
for (const prop of props) {
applyProp(structure, prop);