mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
Reorganise resolver
This commit is contained in:
@@ -99,23 +99,6 @@ class ClientDataResolver {
|
|||||||
return guild.members.get(user.id) || null;
|
return guild.members.get(user.id) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Data that resolves to give a Base64 string, typically for image uploading. This can be:
|
|
||||||
* * A Buffer
|
|
||||||
* * A Base64 string
|
|
||||||
* @typedef {Buffer|string} Base64Resolvable
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves a Base64Resolvable to a Base 64 image
|
|
||||||
* @param {Base64Resolvable} data The base 64 resolvable you want to resolve
|
|
||||||
* @returns {?string}
|
|
||||||
*/
|
|
||||||
resolveBase64(data) {
|
|
||||||
if (data instanceof Buffer) return `data:image/jpg;base64,${data.toString('base64')}`;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data that can be resolved to give a Channel. This can be:
|
* Data that can be resolved to give a Channel. This can be:
|
||||||
* * An instance of a Channel
|
* * An instance of a Channel
|
||||||
@@ -138,6 +121,26 @@ class ClientDataResolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 permission number. This can be:
|
* Data that can be resolved to give a permission number. This can be:
|
||||||
* * A string
|
* * A string
|
||||||
@@ -206,22 +209,19 @@ class ClientDataResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data that can be resolved to give an invite code. This can be:
|
* Data that resolves to give a Base64 string, typically for image uploading. This can be:
|
||||||
* * An invite code
|
* * A Buffer
|
||||||
* * An invite URL
|
* * A Base64 string
|
||||||
* @typedef {string} InviteResolvable
|
* @typedef {Buffer|string} Base64Resolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves InviteResolvable to an invite code
|
* Resolves a Base64Resolvable to a Base 64 image
|
||||||
* @param {InviteResolvable} data The invite resolvable to resolve
|
* @param {Base64Resolvable} data The base 64 resolvable you want to resolve
|
||||||
* @returns {string}
|
* @returns {?string}
|
||||||
*/
|
*/
|
||||||
resolveInviteCode(data) {
|
resolveBase64(data) {
|
||||||
const inviteRegex = /discord(?:app)?\.(?:gg|com\/invite)\/([a-z0-9]{5})/i;
|
if (data instanceof Buffer) return `data:image/jpg;base64,${data.toString('base64')}`;
|
||||||
const match = inviteRegex.exec(data);
|
|
||||||
|
|
||||||
if (match && match[1]) return match[1];
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user