comments
This commit is contained in:
12
dist/util/discord.js
vendored
12
dist/util/discord.js
vendored
@@ -5,9 +5,7 @@ const discord_js_1 = require("discord.js");
|
||||
const main_1 = require("./main");
|
||||
/**
|
||||
* get the GuildMember of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be read
|
||||
* @returns member
|
||||
*/
|
||||
function getMember(interaction) {
|
||||
const member = interaction.member;
|
||||
@@ -18,9 +16,7 @@ function getMember(interaction) {
|
||||
exports.getMember = getMember;
|
||||
/**
|
||||
* get the TextChannel of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be read
|
||||
* @returns member
|
||||
*/
|
||||
function getChannel(interaction) {
|
||||
const channel = interaction.channel;
|
||||
@@ -29,11 +25,19 @@ function getChannel(interaction) {
|
||||
return channel;
|
||||
}
|
||||
exports.getChannel = getChannel;
|
||||
/**
|
||||
* get the TextChannel of an interaction
|
||||
* @throws errorMessage class if the Member cannot be read
|
||||
*/
|
||||
function memberIsMod(interaction) {
|
||||
const member = getMember(interaction);
|
||||
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
||||
}
|
||||
exports.memberIsMod = memberIsMod;
|
||||
/**
|
||||
* get the TextChannel of an interaction
|
||||
* @throws errorMessage class if the Member cannot be read or if Member is not a mod
|
||||
*/
|
||||
function memberIsModThrow(interaction) {
|
||||
if (!memberIsMod(interaction))
|
||||
throw (0, main_1.emsg)('discord.notMod');
|
||||
|
||||
37
dist/util/lang.js
vendored
37
dist/util/lang.js
vendored
@@ -2,6 +2,12 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.embedObjEmbed = exports.embedObjStr = exports.resolveColor = exports.bigString = exports.template = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
* @param args
|
||||
* @returns
|
||||
*/
|
||||
function template(str, args) {
|
||||
return str.replace(/{\w+}/g, str => {
|
||||
const key = str.substring(1, str.length - 1);
|
||||
@@ -11,12 +17,18 @@ function template(str, args) {
|
||||
});
|
||||
}
|
||||
exports.template = template;
|
||||
function bigString(str) {
|
||||
if (typeof str === 'object')
|
||||
return str.join('\n');
|
||||
return str;
|
||||
/**
|
||||
* converts bigString to string
|
||||
*/
|
||||
function bigString(bigStr) {
|
||||
if (Array.isArray(bigStr))
|
||||
return bigStr.join('\n');
|
||||
return bigStr;
|
||||
}
|
||||
exports.bigString = bigString;
|
||||
/**
|
||||
* converts Hex Color string to an RGB array
|
||||
*/
|
||||
function resolveColor(color) {
|
||||
color = color.replace(/[^0-9a-f]/gi, '');
|
||||
const colorNum = [0, 0, 0];
|
||||
@@ -30,14 +42,21 @@ function resolveColor(color) {
|
||||
return colorNum;
|
||||
}
|
||||
exports.resolveColor = resolveColor;
|
||||
function embedObjStr(embedData, fallback = '') {
|
||||
if (embedData.content !== undefined)
|
||||
return bigString(embedData.content);
|
||||
if (embedData.description !== undefined)
|
||||
return bigString(embedData.description);
|
||||
/**
|
||||
* converts embedObj to a string if applicable
|
||||
* @param fallback the string to use if no valid strings can be found
|
||||
*/
|
||||
function embedObjStr(embedObj, args = {}, fallback = '') {
|
||||
if (embedObj.content !== undefined)
|
||||
return template(bigString(embedObj.content), args);
|
||||
if (embedObj.description !== undefined)
|
||||
return template(bigString(embedObj.description), args);
|
||||
return fallback;
|
||||
}
|
||||
exports.embedObjStr = embedObjStr;
|
||||
/**
|
||||
* converts embedObj to Discord.MessageEmbed
|
||||
*/
|
||||
function embedObjEmbed(embedObj, args = {}) {
|
||||
const embed = new discord_js_1.MessageEmbed(), { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
||||
if (author !== undefined) {
|
||||
|
||||
3
dist/util/main.js
vendored
3
dist/util/main.js
vendored
@@ -43,6 +43,9 @@ function shuffle(array) {
|
||||
return array;
|
||||
}
|
||||
exports.shuffle = shuffle;
|
||||
/**
|
||||
* use the emsg() function instead
|
||||
*/
|
||||
class errorMessage {
|
||||
constructor(msg, ephemeral = true) {
|
||||
this.msg = msg;
|
||||
|
||||
Reference in New Issue
Block a user