Added filter presets function to utils and code formatted
This commit is contained in:
@@ -23,7 +23,7 @@ exports.BufferToJson = (buffer) => {
|
|||||||
* @returns {string} The sanitized preset name to be used elsewhere
|
* @returns {string} The sanitized preset name to be used elsewhere
|
||||||
*/
|
*/
|
||||||
exports.SanitizePresetName = (presetName) => {
|
exports.SanitizePresetName = (presetName) => {
|
||||||
return String(presetName).toLowerCase().replace(/[\W_]+/g,"-")
|
return String(presetName).toLowerCase().replace(/[\W_]+/g, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,11 +32,11 @@ exports.SanitizePresetName = (presetName) => {
|
|||||||
* @param interaction Discord interaction object
|
* @param interaction Discord interaction object
|
||||||
* @param param0.roleName {OPTIONAL} The role name to check the members in; Defaults to 'Bots'
|
* @param param0.roleName {OPTIONAL} The role name to check the members in; Defaults to 'Bots'
|
||||||
*/
|
*/
|
||||||
exports.getMembersInRole = async (interaction, roleName = "Bots" ) => {
|
exports.getMembersInRole = async (interaction, roleName = "Bots") => {
|
||||||
log.DEBUG("Fetching all members");
|
log.DEBUG("Fetching all members");
|
||||||
var guild = await interaction.client.guilds.fetch({ guild: interaction.guild.id, cache: false }); //cache all members in the server
|
var guild = await interaction.client.guilds.fetch({ guild: interaction.guild.id, cache: false }); //cache all members in the server
|
||||||
await guild.members.fetch({cache: false});
|
await guild.members.fetch({ cache: false });
|
||||||
await guild.roles.fetch({cache: false});
|
await guild.roles.fetch({ cache: false });
|
||||||
log.VERBOSE("Guild: ", guild);
|
log.VERBOSE("Guild: ", guild);
|
||||||
const role = await guild.roles.cache.find(role => role.name === roleName); //the role to check
|
const role = await guild.roles.cache.find(role => role.name === roleName); //the role to check
|
||||||
log.DEBUG("Role to check members from: ", role);
|
log.DEBUG("Role to check members from: ", role);
|
||||||
@@ -66,7 +66,7 @@ exports.getKeyByArrayValue = (object, value) => {
|
|||||||
if (typeof value == "string") return Object.keys(object).find(key => object[key].includes(value));
|
if (typeof value == "string") return Object.keys(object).find(key => object[key].includes(value));
|
||||||
const valueKey = Object.keys(value)[0];
|
const valueKey = Object.keys(value)[0];
|
||||||
return Object.keys(object).find(key => (object[key][valueKey] == value[valueKey]));
|
return Object.keys(object).find(key => (object[key][valueKey] == value[valueKey]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if the input is a valid JSON string
|
* Check to see if the input is a valid JSON string
|
||||||
@@ -91,7 +91,7 @@ exports.isJsonString = (str) => {
|
|||||||
exports.getAllClientIds = () => {
|
exports.getAllClientIds = () => {
|
||||||
const jsonClientIds = JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json')));
|
const jsonClientIds = JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json')));
|
||||||
var clientObjects = [];
|
var clientObjects = [];
|
||||||
for (const jsonClientId of Object.keys(jsonClientIds)){
|
for (const jsonClientId of Object.keys(jsonClientIds)) {
|
||||||
clientObjects.push(new clientObject({
|
clientObjects.push(new clientObject({
|
||||||
_discord_id: jsonClientId,
|
_discord_id: jsonClientId,
|
||||||
_name: jsonClientIds[jsonClientId].name,
|
_name: jsonClientIds[jsonClientId].name,
|
||||||
@@ -110,7 +110,7 @@ exports.getAllClientIds = () => {
|
|||||||
exports.getClientObjectByClientID = (clientId) => {
|
exports.getClientObjectByClientID = (clientId) => {
|
||||||
const clientObjects = this.getAllClientIds();
|
const clientObjects = this.getAllClientIds();
|
||||||
log.DEBUG("All client IDs: ", clientObjects);
|
log.DEBUG("All client IDs: ", clientObjects);
|
||||||
for (const clientObject of clientObjects){
|
for (const clientObject of clientObjects) {
|
||||||
if (clientObject.clientId == clientId) {
|
if (clientObject.clientId == clientId) {
|
||||||
log.DEBUG("Found client ID from given ID: ", clientObject);
|
log.DEBUG("Found client ID from given ID: ", clientObject);
|
||||||
return clientObject
|
return clientObject
|
||||||
@@ -139,3 +139,25 @@ exports.filterAutocompleteValues = async (interaction, options) => {
|
|||||||
filtered.map(option => ({ name: option, value: option })),
|
filtered.map(option => ({ name: option, value: option })),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter an array of nodeObjects to get all unique presets within
|
||||||
|
*
|
||||||
|
* @param {Array} nodeObjects An array of nodeObjects to get the presets from
|
||||||
|
* @returns {Array} Presets available from given nodeObjects
|
||||||
|
*/
|
||||||
|
exports.filterPresetsAvailable = async (nodeObjects) => {
|
||||||
|
log.DEBUG("Node objects: ", nodeObjects);
|
||||||
|
var presetsAvailable = [];
|
||||||
|
for (const nodeObject of nodeObjects) {
|
||||||
|
log.DEBUG("Node object: ", nodeObject);
|
||||||
|
presetsAvailable.push.apply(presetsAvailable, nodeObject.presets);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.DEBUG("All Presets available: ", presetsAvailable);
|
||||||
|
|
||||||
|
// Remove duplicates
|
||||||
|
presetsAvailable = [...new Set(presetsAvailable)];
|
||||||
|
log.DEBUG("DeDuped Presets available: ", presetsAvailable);
|
||||||
|
return presetsAvailable;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user