comments
This commit is contained in:
2
dist/lang.js
vendored
2
dist/lang.js
vendored
@@ -99,7 +99,7 @@ function get(id, args = {}) {
|
|||||||
if (typeof found === 'string')
|
if (typeof found === 'string')
|
||||||
return (0, lang_1.template)(found, args);
|
return (0, lang_1.template)(found, args);
|
||||||
if (found.embed === true)
|
if (found.embed === true)
|
||||||
return (0, lang_1.embedObjStr)(found, id);
|
return (0, lang_1.embedObjStr)(found, args, id);
|
||||||
finding = found;
|
finding = found;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
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");
|
const main_1 = require("./main");
|
||||||
/**
|
/**
|
||||||
* get the GuildMember of an interaction
|
* get the GuildMember of an interaction
|
||||||
* @param interaction
|
|
||||||
* @throws errorMessage class if it cannot be read
|
* @throws errorMessage class if it cannot be read
|
||||||
* @returns member
|
|
||||||
*/
|
*/
|
||||||
function getMember(interaction) {
|
function getMember(interaction) {
|
||||||
const member = interaction.member;
|
const member = interaction.member;
|
||||||
@@ -18,9 +16,7 @@ function getMember(interaction) {
|
|||||||
exports.getMember = getMember;
|
exports.getMember = getMember;
|
||||||
/**
|
/**
|
||||||
* get the TextChannel of an interaction
|
* get the TextChannel of an interaction
|
||||||
* @param interaction
|
|
||||||
* @throws errorMessage class if it cannot be read
|
* @throws errorMessage class if it cannot be read
|
||||||
* @returns member
|
|
||||||
*/
|
*/
|
||||||
function getChannel(interaction) {
|
function getChannel(interaction) {
|
||||||
const channel = interaction.channel;
|
const channel = interaction.channel;
|
||||||
@@ -29,11 +25,19 @@ function getChannel(interaction) {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
exports.getChannel = getChannel;
|
exports.getChannel = getChannel;
|
||||||
|
/**
|
||||||
|
* get the TextChannel of an interaction
|
||||||
|
* @throws errorMessage class if the Member cannot be read
|
||||||
|
*/
|
||||||
function memberIsMod(interaction) {
|
function memberIsMod(interaction) {
|
||||||
const member = getMember(interaction);
|
const member = getMember(interaction);
|
||||||
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
||||||
}
|
}
|
||||||
exports.memberIsMod = memberIsMod;
|
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) {
|
function memberIsModThrow(interaction) {
|
||||||
if (!memberIsMod(interaction))
|
if (!memberIsMod(interaction))
|
||||||
throw (0, main_1.emsg)('discord.notMod');
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.embedObjEmbed = exports.embedObjStr = exports.resolveColor = exports.bigString = exports.template = void 0;
|
exports.embedObjEmbed = exports.embedObjStr = exports.resolveColor = exports.bigString = exports.template = void 0;
|
||||||
const discord_js_1 = require("discord.js");
|
const discord_js_1 = require("discord.js");
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* @param args
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
function template(str, args) {
|
function template(str, args) {
|
||||||
return str.replace(/{\w+}/g, str => {
|
return str.replace(/{\w+}/g, str => {
|
||||||
const key = str.substring(1, str.length - 1);
|
const key = str.substring(1, str.length - 1);
|
||||||
@@ -11,12 +17,18 @@ function template(str, args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.template = template;
|
exports.template = template;
|
||||||
function bigString(str) {
|
/**
|
||||||
if (typeof str === 'object')
|
* converts bigString to string
|
||||||
return str.join('\n');
|
*/
|
||||||
return str;
|
function bigString(bigStr) {
|
||||||
|
if (Array.isArray(bigStr))
|
||||||
|
return bigStr.join('\n');
|
||||||
|
return bigStr;
|
||||||
}
|
}
|
||||||
exports.bigString = bigString;
|
exports.bigString = bigString;
|
||||||
|
/**
|
||||||
|
* converts Hex Color string to an RGB array
|
||||||
|
*/
|
||||||
function resolveColor(color) {
|
function resolveColor(color) {
|
||||||
color = color.replace(/[^0-9a-f]/gi, '');
|
color = color.replace(/[^0-9a-f]/gi, '');
|
||||||
const colorNum = [0, 0, 0];
|
const colorNum = [0, 0, 0];
|
||||||
@@ -30,14 +42,21 @@ function resolveColor(color) {
|
|||||||
return colorNum;
|
return colorNum;
|
||||||
}
|
}
|
||||||
exports.resolveColor = resolveColor;
|
exports.resolveColor = resolveColor;
|
||||||
function embedObjStr(embedData, fallback = '') {
|
/**
|
||||||
if (embedData.content !== undefined)
|
* converts embedObj to a string if applicable
|
||||||
return bigString(embedData.content);
|
* @param fallback the string to use if no valid strings can be found
|
||||||
if (embedData.description !== undefined)
|
*/
|
||||||
return bigString(embedData.description);
|
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;
|
return fallback;
|
||||||
}
|
}
|
||||||
exports.embedObjStr = embedObjStr;
|
exports.embedObjStr = embedObjStr;
|
||||||
|
/**
|
||||||
|
* converts embedObj to Discord.MessageEmbed
|
||||||
|
*/
|
||||||
function embedObjEmbed(embedObj, args = {}) {
|
function embedObjEmbed(embedObj, args = {}) {
|
||||||
const embed = new discord_js_1.MessageEmbed(), { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
const embed = new discord_js_1.MessageEmbed(), { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
||||||
if (author !== undefined) {
|
if (author !== undefined) {
|
||||||
|
|||||||
3
dist/util/main.js
vendored
3
dist/util/main.js
vendored
@@ -43,6 +43,9 @@ function shuffle(array) {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
exports.shuffle = shuffle;
|
exports.shuffle = shuffle;
|
||||||
|
/**
|
||||||
|
* use the emsg() function instead
|
||||||
|
*/
|
||||||
class errorMessage {
|
class errorMessage {
|
||||||
constructor(msg, ephemeral = true) {
|
constructor(msg, ephemeral = true) {
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export function get(id: string, args: basicObjectStr = {}): string {
|
|||||||
return template(found, args);
|
return template(found, args);
|
||||||
|
|
||||||
if (found.embed === true)
|
if (found.embed === true)
|
||||||
return embedObjStr(found as embedObj, id);
|
return embedObjStr(found as embedObj, args, id);
|
||||||
|
|
||||||
finding = found as LangObj;
|
finding = found as LangObj;
|
||||||
|
|
||||||
|
|||||||
3
src/types/api.d.ts
vendored
3
src/types/api.d.ts
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* data taken from UniteAPI
|
||||||
|
*/
|
||||||
interface uniteApiData {
|
interface uniteApiData {
|
||||||
name: string,
|
name: string,
|
||||||
id: string,
|
id: string,
|
||||||
|
|||||||
49
src/types/lang.d.ts
vendored
49
src/types/lang.d.ts
vendored
@@ -1,28 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* any indexable object
|
||||||
|
*/
|
||||||
//this is a generic type, and needs 'any'
|
//this is a generic type, and needs 'any'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type basicObject = {[keys: string]: any};
|
type basicObject = {[keys: string]: any};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* any indexable object with string values
|
||||||
|
*/
|
||||||
type basicObjectStr = {[keys: string]: string};
|
type basicObjectStr = {[keys: string]: string};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* an abstract version of strings
|
||||||
|
*/
|
||||||
type bigString = string | string[];
|
type bigString = string | string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* an object that contains embeds and can be passed directly to methods like `Discord.TextChannel.send()`
|
||||||
|
*/
|
||||||
interface embedData {
|
interface embedData {
|
||||||
content?: string,
|
content?: string,
|
||||||
embeds: MessageEmbed[]
|
embeds: MessageEmbed[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a representation of an author in the LANG object
|
||||||
|
*
|
||||||
|
* `LANG > Language > Embed > Field`
|
||||||
|
*/
|
||||||
interface embedField {
|
interface embedField {
|
||||||
name: string,
|
name: string,
|
||||||
value: bigString,
|
value: bigString,
|
||||||
inline?: boolean
|
inline?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a representation of an author in the LANG object
|
||||||
|
*
|
||||||
|
* `LANG > Language > Embed > Author`
|
||||||
|
*/
|
||||||
interface authorData {
|
interface authorData {
|
||||||
name: string,
|
name: string,
|
||||||
url?: string,
|
url?: string,
|
||||||
icon?: string
|
icon?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a representation of a footer in the LANG object
|
||||||
|
*
|
||||||
|
* `LANG > Language > Embed > Footer`
|
||||||
|
*/
|
||||||
interface footerData {
|
interface footerData {
|
||||||
text: string,
|
text: string,
|
||||||
icon?: string
|
icon?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a representation of an embed in the LANG object
|
||||||
|
*
|
||||||
|
* `LANG > Language > Embed`
|
||||||
|
*/
|
||||||
interface embedObj {
|
interface embedObj {
|
||||||
embed: true,
|
embed: true,
|
||||||
|
|
||||||
@@ -51,5 +89,16 @@ interface embedObj {
|
|||||||
timestamp?: boolean | string | number
|
timestamp?: boolean | string | number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a specific language in the LANG object
|
||||||
|
*
|
||||||
|
* `LANG > Language`
|
||||||
|
*/
|
||||||
type LangObj = { [keys:string]: LangObj | embedObj | string }
|
type LangObj = { [keys:string]: LangObj | embedObj | string }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the entire LANG object
|
||||||
|
*
|
||||||
|
* `LANG`
|
||||||
|
*/
|
||||||
type LangObjWhole = { [langid:string]: LangObj }
|
type LangObjWhole = { [langid:string]: LangObj }
|
||||||
@@ -3,9 +3,7 @@ import { emsg } from './main';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the GuildMember of an interaction
|
* get the GuildMember of an interaction
|
||||||
* @param interaction
|
|
||||||
* @throws errorMessage class if it cannot be read
|
* @throws errorMessage class if it cannot be read
|
||||||
* @returns member
|
|
||||||
*/
|
*/
|
||||||
export function getMember(interaction: CommandInteraction): GuildMember {
|
export function getMember(interaction: CommandInteraction): GuildMember {
|
||||||
const member = interaction.member;
|
const member = interaction.member;
|
||||||
@@ -18,9 +16,7 @@ export function getMember(interaction: CommandInteraction): GuildMember {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the TextChannel of an interaction
|
* get the TextChannel of an interaction
|
||||||
* @param interaction
|
|
||||||
* @throws errorMessage class if it cannot be read
|
* @throws errorMessage class if it cannot be read
|
||||||
* @returns member
|
|
||||||
*/
|
*/
|
||||||
export function getChannel(interaction: CommandInteraction): TextChannel {
|
export function getChannel(interaction: CommandInteraction): TextChannel {
|
||||||
const channel = interaction.channel;
|
const channel = interaction.channel;
|
||||||
@@ -31,12 +27,19 @@ export function getChannel(interaction: CommandInteraction): TextChannel {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the TextChannel of an interaction
|
||||||
|
* @throws errorMessage class if the Member cannot be read
|
||||||
|
*/
|
||||||
export function memberIsMod(interaction: CommandInteraction): boolean {
|
export function memberIsMod(interaction: CommandInteraction): boolean {
|
||||||
const member = getMember(interaction);
|
const member = getMember(interaction);
|
||||||
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the TextChannel of an interaction
|
||||||
|
* @throws errorMessage class if the Member cannot be read or if Member is not a mod
|
||||||
|
*/
|
||||||
export function memberIsModThrow(interaction: CommandInteraction) {
|
export function memberIsModThrow(interaction: CommandInteraction) {
|
||||||
if (!memberIsMod(interaction))
|
if (!memberIsMod(interaction))
|
||||||
throw emsg('discord.notMod');
|
throw emsg('discord.notMod');
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { MessageEmbed } from 'discord.js';
|
import { MessageEmbed } from 'discord.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* @param args
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export function template(str: string, args: basicObject): string {
|
export function template(str: string, args: basicObject): string {
|
||||||
|
|
||||||
return str.replace(/{\w+}/g, str => {
|
return str.replace(/{\w+}/g, str => {
|
||||||
@@ -15,12 +21,19 @@ export function template(str: string, args: basicObject): string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bigString(str: bigString): string {
|
/**
|
||||||
if (typeof str === 'object')
|
* converts bigString to string
|
||||||
return str.join('\n');
|
*/
|
||||||
return str;
|
export function bigString(bigStr: bigString): string {
|
||||||
|
if (Array.isArray(bigStr))
|
||||||
|
return bigStr.join('\n');
|
||||||
|
return bigStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts Hex Color string to an RGB array
|
||||||
|
*/
|
||||||
export function resolveColor(color: string): [number, number, number] {
|
export function resolveColor(color: string): [number, number, number] {
|
||||||
color = color.replace(/[^0-9a-f]/gi, '');
|
color = color.replace(/[^0-9a-f]/gi, '');
|
||||||
|
|
||||||
@@ -41,17 +54,24 @@ export function resolveColor(color: string): [number, number, number] {
|
|||||||
return colorNum;
|
return colorNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function embedObjStr(embedData: embedObj, fallback = ''): string {
|
/**
|
||||||
|
* converts embedObj to a string if applicable
|
||||||
|
* @param fallback the string to use if no valid strings can be found
|
||||||
|
*/
|
||||||
|
export function embedObjStr(embedObj: embedObj, args: basicObjectStr = {}, fallback = ''): string {
|
||||||
|
|
||||||
if (embedData.content !== undefined)
|
if (embedObj.content !== undefined)
|
||||||
return bigString(embedData.content);
|
return template(bigString(embedObj.content), args);
|
||||||
|
|
||||||
if (embedData.description !== undefined)
|
if (embedObj.description !== undefined)
|
||||||
return bigString(embedData.description);
|
return template(bigString(embedObj.description), args);
|
||||||
|
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts embedObj to Discord.MessageEmbed
|
||||||
|
*/
|
||||||
export function embedObjEmbed(embedObj: embedObj, args: basicObjectStr = {}): MessageEmbed {
|
export function embedObjEmbed(embedObj: embedObj, args: basicObjectStr = {}): MessageEmbed {
|
||||||
const embed = new MessageEmbed(),
|
const embed = new MessageEmbed(),
|
||||||
{ author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
{ author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ export function shuffle(array: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* use the emsg() function instead
|
||||||
|
*/
|
||||||
export class errorMessage {
|
export class errorMessage {
|
||||||
public msg: string;
|
public msg: string;
|
||||||
public ephemeral: boolean;
|
public ephemeral: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user