Skip to content

Commit 7f9d0ce

Browse files
authored
Merge pull request #64 from xcraftman52/dev/v1.4.0
Channel & Role Variables
2 parents 9559030 + 61c052a commit 7f9d0ce

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Modules/Utils.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,75 @@ module.exports = {
106106

107107
return returnObject;
108108
},
109+
/**
110+
*
111+
* @param {Discord.Channel} channel
112+
* @param {String} prefix
113+
* @returns {Array<Object>}
114+
*/
115+
channelVariables: (channel, prefix) => {
116+
let returnObject = [];
117+
118+
if (channel) returnObject = [{
119+
searchFor: new RegExp(`{${prefix || "channel"}-id}`, "g"),
120+
replaceWith: channel.id,
121+
}, {
122+
searchFor: new RegExp(`{${prefix || "channel"}-name}`, "g"),
123+
replaceWith: channel.name,
124+
}, {
125+
searchFor: new RegExp(`{${prefix || "channel"}-mention}`, "g"),
126+
replaceWith: channel.toString(),
127+
}, {
128+
searchFor: new RegExp(`{${prefix || "channel"}-type}`, "g"),
129+
replaceWith: channel.type,
130+
}, {
131+
searchFor: new RegExp(`{${prefix || "channel"}-createdate}`, "g"),
132+
replaceWith: `<t:${Math.floor(channel.createdTimestamp / 1000)}:D>`,
133+
}]
134+
135+
if (!channel) module.exports.logError(`[Utils] [channelVariables] Invalid input for ${chalk.bold("channel")}.`);
136+
137+
return returnObject;
138+
},
139+
/**
140+
*
141+
* @param {Discord.Role} role
142+
* @param {String} prefix
143+
* @returns
144+
*/
145+
roleVariables: (role, prefix) => {
146+
let returnObject = [];
147+
148+
if (role) returnObject = [{
149+
searchFor: new RegExp(`{${prefix || "role"}-id}`, "g"),
150+
replaceWith: role.id,
151+
}, {
152+
searchFor: new RegExp(`{${prefix || "role"}-name}`, "g"),
153+
replaceWith: role.name,
154+
}, {
155+
searchFor: new RegExp(`{${prefix || "role"}-mention}`, "g"),
156+
replaceWith: role.toString(),
157+
}, {
158+
searchFor: new RegExp(`{${prefix || "role"}-createdate}`, "g"),
159+
replaceWith: `<t:${Math.floor(role.createdTimestamp / 1000)}:D>`,
160+
}, {
161+
searchFor: new RegExp(`{${prefix || "role"}-color}`, "g"),
162+
replaceWith: role.color,
163+
}, {
164+
searchFor: new RegExp(`{${prefix || "role"}-hexColor}`, "g"),
165+
replaceWith: role.hexColor,
166+
}, {
167+
searchFor: new RegExp(`{${prefix || "role"}-position}`, "g"),
168+
replaceWith: role.rawPosition,
169+
}, {
170+
searchFor: new RegExp(`{${prefix || "role"}-icon}`, "g"),
171+
replaceWith: role.iconURL() || "https://cdn-icons-png.flaticon.com/512/2522/2522053.png",
172+
}]
173+
174+
if (!role) module.exports.logError(`[Utils] [roleVariables] Invalid input for ${chalk.bold("role")}.`);
175+
176+
return returnObject;
177+
},
109178
/**
110179
* @param {Discord.Client} bot
111180
* @param {String} prefix

0 commit comments

Comments
 (0)