1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 20:30:58 -05:00
Daggerbot-TS/src/helpers/MessageTool.ts
2023-10-08 08:01:16 +11:00

28 lines
1.3 KiB
TypeScript

import Discord from 'discord.js';
import {readFileSync} from 'node:fs';
import {Config} from 'src/typings/interfaces';
const config:Config = JSON.parse(readFileSync('src/config.json', 'utf8'));
type RoleKeys = keyof typeof config.mainServer.roles;
export default class MessageTool {
static embedStruct(color:Discord.ColorResolvable, title:string, description?:string|null, image?:string|null){
const embed = new Discord.EmbedBuilder().setColor(color).setTitle(title);
if (description) embed.setDescription(description);
if (image) embed.setImage(image);
return embed
}
static concatMessage(...messages:string[]){
return messages.join('\n')
}
static formatMention(mention:string, type:'user'|'channel'|'role'){
return `<@${type === 'role' ? '&' : type === 'channel' ? '#' : ''}${mention}>`
}
static isStaff(guildMember:Discord.GuildMember){
return config.mainServer.staffRoles.map((x:string)=>config.mainServer.roles[x]).some((x:string)=>guildMember.roles.cache.has(x));
}
static youNeedRole(interaction:Discord.CommandInteraction, role:RoleKeys){
return interaction.reply(`This command is restricted to ${this.formatMention(config.mainServer.roles[role], 'role')}`);
}
}
// I want to come up with better name instead of calling this file "MessageTool", but I am super bad at naming things.