Add InviteResolvable (#766)

* Add InviteResolvable

Add InviteResolvable

* Return data as fallback instead

* Rename resolver method
This commit is contained in:
Programmix
2016-10-02 16:21:08 -07:00
committed by Schuyler Cebulskie
parent 77e37b62ef
commit c4e1e4f50f
2 changed files with 23 additions and 2 deletions

View File

@@ -265,10 +265,11 @@ class Client extends EventEmitter {
/**
* Fetches an invite object from an invite code.
* @param {string} code the invite code.
* @param {InviteResolvable} invite An invite code or URL
* @returns {Promise<Invite>}
*/
fetchInvite(code) {
fetchInvite(invite) {
const code = this.resolver.resolveInviteCode(invite);
return this.rest.methods.getInvite(code);
}

View File

@@ -205,6 +205,26 @@ class ClientDataResolver {
return String(data);
}
/**
* Data that can be resolved to give an invite code. This can be:
* * An invite code
* * An invite URL
* @typedef {string} InviteResolvable
*/
/**
* Resolves InviteResolvable to an invite code
* @param {InviteResolvable} data The invite resolvable to resolve
* @returns {string}
*/
resolveInviteCode(data) {
const inviteRegex = /discord(?:app)?\.(?:gg|com\/invite)\/([a-z0-9]{5})/i;
const match = inviteRegex.exec(data);
if (match && match[1]) return match[1];
return data;
}
/**
* Data that can be resolved to give a Buffer. This can be:
* * A Buffer