Add User typing methods

This commit is contained in:
Schuyler Cebulskie
2016-09-09 14:11:30 -04:00
parent 4278a37e3c
commit c405d67e09
2 changed files with 31 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -84,6 +84,36 @@ class User {
return Constants.Endpoints.avatar(this.id, this.avatar);
}
/**
* Check whether the user is typing in a channel.
* @param {ChannelResolvable} channel The channel to check in
* @returns {boolean}
*/
isTyping(channel) {
channel = this.client.resolver.resolveChannel(channel);
return channel._typing.has(this.id);
}
/**
* Get the time that the user started typing.
* @param {ChannelResolvable} channel The channel to get the time in
* @returns {?Date}
*/
typingSince(channel) {
channel = this.client.resolver.resolveChannel(channel);
return channel._typing.has(this.id) ? new Date(channel._typing.get(this.id).since) : null;
}
/**
* Get the amount of time the user has been typing in a channel for (in milliseconds), or -1 if they're not typing.
* @param {ChannelResolvable} channel The channel to get the time in
* @returns {number}
*/
typingDuration(channel) {
channel = this.client.resolver.resolveChannel(channel);
return channel._typing.has(this.id) ? channel._typing.get(this.id).elapsedTime : -1;
}
/**
* Deletes a DM Channel (if one exists) between the Client and the User. Resolves with the Channel if successful.
* @returns {Promise<DMChannel>}