UNPKG

djs-systems

Version:

The simplest way to build complex Discord bots.

145 lines (144 loc) 6.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ticketSetup = void 0; const discord_js_1 = require("discord.js"); const SimplyError_1 = require("./error/SimplyError"); const misc_1 = require("./misc"); // ------------------------------ // ------ F U N C T I O N ------- // ------------------------------ /** * A Flexible yet Powerful Ticket System | *Requires: [**manageTicket()**](https://simplyd.js.org/docs/handler/manageTicket)* * * @param msgOrint * @param options * @link `Documentation:` https://simplyd.js.org/docs/systems/ticketSetup * @example simplydjs.ticketSetup(interaction, { channelId: '0123456789012' }) */ async function ticketSetup(msgOrint, options = { strict: false }) { return new Promise(async () => { try { const { client } = msgOrint; let channel; let interaction; if (msgOrint.commandId) { interaction = msgOrint; channel = client.channels.cache.get(options?.channelId) || interaction.options.get('channel').channel; if (!interaction.deferred) await interaction.deferReply({ fetchReply: true }); } else if (!msgOrint.commandId && msgOrint.content) { channel = client.channels.cache.get(options?.channelId) || msgOrint.mentions.channels.first(); } const extInteraction = msgOrint; const extMessage = msgOrint; if (!channel || !channel.id) { if (options?.strict) throw new SimplyError_1.SimplyError({ function: 'ticketSetup', title: 'Provide an channel id to send the system panel.', tip: `Expected channelId as string in options.. | Received ${options.channelId || 'undefined'}` }); else console.log(`SimplyError - ticketSetup | Provide an channel id to send the system panel.\n\n` + `Expected channelId as string in options.. | Received ${options.channelId || 'undefined'}`); } channel = channel; if (!channel) { if (options?.strict) throw new SimplyError_1.SimplyError({ function: 'ticketSetup', title: `Invalid Channel (or) No VIEW_CHANNEL permission`, tip: `Check the permissions (or) Try using another Channel ID.\nReceived ${options.channelId || 'undefined'}` }); else console.log(`SimplyError - ticketSetup | Invalid Channel (or) No VIEW_CHANNEL permission\n\nCheck the permissions (or) Try using another Channel ID.\n Received ${options.channelId || 'undefined'}`); } if (!msgOrint.member.permissions.has(discord_js_1.PermissionFlagsBits.Administrator)) { if (interaction) { return await extInteraction.followUp({ content: 'You are not an admin to create a Ticket Panel', ephemeral: true }); } else if (!interaction) { return await extMessage.reply({ content: 'You are not an admin to create a Ticket Panel' }); } } if (options?.button?.style) options.button.style = (0, misc_1.toButtonStyle)(options?.button?.style); const ticketbtn = new discord_js_1.ButtonBuilder() .setStyle(options?.button?.style || discord_js_1.ButtonStyle.Primary) .setEmoji(options?.button?.emoji || '🎫') .setLabel(options?.button?.label || 'Open a Ticket') .setCustomId('create_ticket'); if (!options.embed) { options.embed = { footer: { text: '©️ Rahuletto. npm i simply-djs', iconURL: 'https://i.imgur.com/XFUIwPh.png' }, color: (0, misc_1.toRgb)('#406DBC'), title: 'Ticket Support' }; } const row = new discord_js_1.ActionRowBuilder().addComponents([ ticketbtn ]); const embed = new discord_js_1.EmbedBuilder() .setTitle(options.embed?.title || 'Ticket Support') .setColor(options.embed?.color || (0, misc_1.toRgb)('#406DBC')) .setDescription(options.embed?.description || '🎫 Open a ticket by interacting with the button 🎫') .setThumbnail(msgOrint.guild.iconURL()) .setTimestamp() .setFooter(options.embed?.footer ? options.embed?.footer : { text: '©️ Rahuletto. npm i simply-djs', iconURL: 'https://i.imgur.com/XFUIwPh.png' }); if (options?.embed?.fields) embed.setFields(options.embed?.fields); if (options?.embed?.author) embed.setAuthor(options.embed?.author); if (options?.embed?.image) embed.setImage(options.embed?.image); if (options?.embed?.thumbnail) embed.setThumbnail(options.embed?.thumbnail); if (options?.embed?.timestamp) embed.setTimestamp(options.embed?.timestamp); if (options?.embed?.title) embed.setTitle(options.embed?.title); if (options?.embed?.url) embed.setURL(options.embed?.url); if (interaction) { extInteraction.followUp({ content: 'Done. Setting Ticket to that channel' }); channel.send({ embeds: [embed], components: [row] }); } else if (!interaction) { extMessage.reply({ content: 'Done. Setting Ticket to that channel' }); channel.send({ embeds: [embed], components: [row] }); } } catch (err) { if (options?.strict) throw new SimplyError_1.SimplyError({ function: 'ticketSetup', title: 'An Error occured when running the function', tip: err.stack }); else console.log(`SimplyError - ticketSetup | Error: ${err.stack}`); } }); } exports.ticketSetup = ticketSetup;