From 61c052a0da41ae73828a477712b3b37b3ece46b9 Mon Sep 17 00:00:00 2001 From: Lucas Webber Date: Sun, 29 May 2022 15:26:11 -0400 Subject: [PATCH] Channel & Role Variables --- Modules/Utils.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/Modules/Utils.js b/Modules/Utils.js index fcb026e..4f1f954 100644 --- a/Modules/Utils.js +++ b/Modules/Utils.js @@ -106,6 +106,75 @@ module.exports = { return returnObject; }, + /** + * + * @param {Discord.Channel} channel + * @param {String} prefix + * @returns {Array} + */ + channelVariables: (channel, prefix) => { + let returnObject = []; + + if (channel) returnObject = [{ + searchFor: new RegExp(`{${prefix || "channel"}-id}`, "g"), + replaceWith: channel.id, + }, { + searchFor: new RegExp(`{${prefix || "channel"}-name}`, "g"), + replaceWith: channel.name, + }, { + searchFor: new RegExp(`{${prefix || "channel"}-mention}`, "g"), + replaceWith: channel.toString(), + }, { + searchFor: new RegExp(`{${prefix || "channel"}-type}`, "g"), + replaceWith: channel.type, + }, { + searchFor: new RegExp(`{${prefix || "channel"}-createdate}`, "g"), + replaceWith: ``, + }] + + if (!channel) module.exports.logError(`[Utils] [channelVariables] Invalid input for ${chalk.bold("channel")}.`); + + return returnObject; + }, + /** + * + * @param {Discord.Role} role + * @param {String} prefix + * @returns + */ + roleVariables: (role, prefix) => { + let returnObject = []; + + if (role) returnObject = [{ + searchFor: new RegExp(`{${prefix || "role"}-id}`, "g"), + replaceWith: role.id, + }, { + searchFor: new RegExp(`{${prefix || "role"}-name}`, "g"), + replaceWith: role.name, + }, { + searchFor: new RegExp(`{${prefix || "role"}-mention}`, "g"), + replaceWith: role.toString(), + }, { + searchFor: new RegExp(`{${prefix || "role"}-createdate}`, "g"), + replaceWith: ``, + }, { + searchFor: new RegExp(`{${prefix || "role"}-color}`, "g"), + replaceWith: role.color, + }, { + searchFor: new RegExp(`{${prefix || "role"}-hexColor}`, "g"), + replaceWith: role.hexColor, + }, { + searchFor: new RegExp(`{${prefix || "role"}-position}`, "g"), + replaceWith: role.rawPosition, + }, { + searchFor: new RegExp(`{${prefix || "role"}-icon}`, "g"), + replaceWith: role.iconURL() || "https://cdn-icons-png.flaticon.com/512/2522/2522053.png", + }] + + if (!role) module.exports.logError(`[Utils] [roleVariables] Invalid input for ${chalk.bold("role")}.`); + + return returnObject; + }, /** * @param {Discord.Client} bot * @param {String} prefix