diff --git a/commands/about.js b/commands/about.js index fe9ec14..dd5c1ad 100644 --- a/commands/about.js +++ b/commands/about.js @@ -2,15 +2,19 @@ const config = require('../data/config.json'); const emb = require('../data/embeds.json'); exports.run = (client, message, args) => { - const prefix = config.bot.prefix; - message.delete(); - - const embed_content = [{ - color: 0xcc3366, - title: '馃帿 RemTicketHelper 馃尭', - description: 'Este proyecto naci贸 en una fase de aburrimiento, donde me propuse poder crear de forma f谩cil y lo mas 贸ptimo posible (con mis conocimientos b谩sicos de JavaScript, el crear un bot que cubra un sistema de tickets.\n\n馃懓馃徎 Desarrollado y mantenido por: [@KuroNeko](https://github.com/imkuroneko) bajo el proyecto [馃 Unicodesoft](https://github.com/UnicodeSoft).\n馃 Repositorio: [clic aqu铆](https://github.com/UnicodeSoft/RemTicketHelper)', - footer: emb.footer - }]; - - message.channel.send({ embeds: embed_content }); + try { + const prefix = config.bot.prefix; + message.delete(); + + const embed_content = [{ + color: 0xcc3366, + title: '馃帿 RemTicketHelper 馃尭', + description: 'Este proyecto naci贸 en una fase de aburrimiento, donde me propuse poder crear de forma f谩cil y lo mas 贸ptimo posible (con mis conocimientos b谩sicos de JavaScript, el crear un bot que cubra un sistema de tickets.\n\n馃懓馃徎 Desarrollado y mantenido por: [@KuroNeko](https://github.com/imkuroneko) bajo el proyecto [馃 Unicodesoft](https://github.com/UnicodeSoft).\n馃 Repositorio: [clic aqu铆](https://github.com/UnicodeSoft/RemTicketHelper)', + footer: emb.footer + }]; + + message.channel.send({ embeds: embed_content }); + } catch(error) { + console.log(error); + } } diff --git a/commands/close.js b/commands/close.js index be31e88..33569f8 100644 --- a/commands/close.js +++ b/commands/close.js @@ -1,4 +1,64 @@ -exports.run = (client, message, args) => { - // 馃 Content of the command - message.reply("**Give us nuggots for the confederatiowon!** <:nuggots:864676232737718292><:theiStonks:905161849459314789>"); +// Data +const config = require('../data/config.json'); +const { template, footer } = require('../data/embeds.json'); +const { isTicket, getUserCreator, updateToClosed, getCurTicketId, getTicketCategory } = require('../functions.js'); + +// DiscordJs +const { MessageActionRow, MessageButton } = require('discord.js'); + +// This thing... +const wait = require('node:timers/promises').setTimeout; + +exports.run = async (client, message, args) => { + try { + const guildId = message.guildId; + const channelId = message.channelId; + + if(!isTicket(channelId, guildId)) { + return; + } + + const embed_closed = [{ + color: 0xcc3366, + title: template.closed.title, + description: template.closed.description.replaceAll('{prefix_mention}', config.bot.prefix), + footer: footer + }]; + + const btns_ticket_closed = new MessageActionRow() + .addComponents( + new MessageButton().setCustomId('reopen').setLabel('Reabrir Ticket').setStyle('SUCCESS'), + new MessageButton().setCustomId('delete').setLabel('Eliminar Ticket').setStyle('DANGER') + ); + message.reply({ embeds: embed_closed, components: [ btns_ticket_closed ] }); + + updateToClosed(guildId, channelId); + + message.guild.channels.fetch(channelId).then( (channelEdit) => { + var userCreator = getUserCreator(guildId, channelId); + var menu_id = getTicketCategory(guildId, channelId); + var category_info = Object.values(config.guilds[guildId]).flat().find(r => r.id === menu_id); + + if(category_info.allowed_staff.length > 0) { + var allowed_staff = [ + { id: message.guild.roles.everyone.id, deny: [ 'VIEW_CHANNEL' ] }, + { id: message.guild.members.cache.get(userCreator), deny: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] }, + { id: category_info.allowed_staff, allow: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] } + ]; + } else { + var allowed_staff = [ + { id: message.guild.roles.everyone.id, deny: [ 'VIEW_CHANNEL' ] }, + { id: message.guild.members.cache.get(userCreator), deny: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] } + ]; + } + + console.log(channelEdit); + + channelEdit.edit({ + permissionOverwrites: allowed_staff + }); + }); + } catch(error) { + console.log(error); + } } \ No newline at end of file diff --git a/commands/delete.js b/commands/delete.js index 1dc8abf..8be07f3 100644 --- a/commands/delete.js +++ b/commands/delete.js @@ -1,6 +1,41 @@ -exports.run = (client, message, args) => { - // 馃 Content of the command - message.reply("**Give us nuggots for the confederatiowon!** <:nuggots:864676232737718292><:theiStonks:905161849459314789>"); +// Data +const config = require('../data/config.json'); +const { template, footer } = require('../data/embeds.json'); +const { isTicket, updateToDeleted } = require('../functions.js'); - // message.channel.delete(); +// DiscordJs +const { MessageActionRow, MessageButton } = require('discord.js'); + +// This thing... +const wait = require('node:timers/promises').setTimeout; + +exports.run = async (client, message, args) => { + try { + const guildId = message.guildId; + const channelId = message.channelId; + + if(!isTicket(channelId, guildId)) { + return; + } + + const sec = config.bot.secDelTicket; + + const embed_delete = [{ + color: 0xcc3366, + title: template.delete.title, + description: template.delete.description.replaceAll('{seconds}', sec), + footer: footer + }]; + message.reply({ embeds: embed_delete }); + + await wait(sec * 1000); + + const toDelete = message.guild.channels.cache.get(channelId); + + updateToDeleted(toDelete.guildId, toDelete.id); + + toDelete.delete(); + } catch(error) { + console.log(error); + } } \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 77afeca..5e127df 100644 --- a/commands/help.js +++ b/commands/help.js @@ -2,26 +2,28 @@ const config = require('../data/config.json'); const emb = require('../data/embeds.json'); exports.run = (client, message, args) => { - const prefix = config.bot.prefix; - message.delete(); - - const embed_content = [{ - color: 0xcc3366, - title: '馃搵 Comandos del Bot', - description: 'Aqu铆 tienes la lista de todos los comandos con los que cuenta el bot!', - fields : [ - { inline: false, name: `${prefix} about`, value: 'Acerca del proyecto.' }, - { inline: false, name: `${prefix} help`, value: 'Obtener esta lista de comandos disponibles.' }, - { inline: false, name: `${prefix} sendembed`, value: 'Enviar el mensaje con el men煤 de categor铆as de tickets.' }, - { inline: false, name: `${prefix} delete`, value: 'Borrar un ticket.' }, - { inline: false, name: `${prefix} info`, value: 'Ver el estado de bot (uptime & recursos).' }, - { inline: false, name: `${prefix} close`, value: 'Cerrar un ticket. (Inhabilita la lectura al usuario que abri贸 el ticket).' }, - { inline: false, name: `${prefix} reopen`, value: 'Reabrir un ticket. (Rehabilita la lectura al usuario que abri贸 el ticket).' }, - { inline: false, name: `${prefix} ban <@user>`, value: 'Banear a un usuario para que no utilice el sistema de tickets. (Baneo persistente, en caso de salir y volver al servidor, esta prohibici贸n persistir谩).' }, - { inline: false, name: `${prefix} unban <@user>`, value: 'Desbanear a un usuario para que pueda utilizar nuevamente el sistema de tickets.' }, - ], - footer: emb.footer - }]; - - message.channel.send({ embeds: embed_content }); + try { + const prefix = config.bot.prefix; + message.delete(); + + const embed_content = [{ + color: 0xcc3366, + title: '馃搵 Comandos del Bot', + description: 'Aqu铆 tienes la lista de todos los comandos con los que cuenta el bot!', + fields : [ + { inline: false, name: `${prefix} about`, value: 'Acerca del proyecto.' }, + { inline: false, name: `${prefix} help`, value: 'Obtener esta lista de comandos disponibles.' }, + { inline: false, name: `${prefix} sendembed`, value: 'Enviar el mensaje con el men煤 de categor铆as de tickets.' }, + { inline: false, name: `${prefix} delete`, value: 'Borrar un ticket.' }, + { inline: false, name: `${prefix} info`, value: 'Ver el estado de bot (uptime & recursos).' }, + { inline: false, name: `${prefix} close`, value: 'Cerrar un ticket.' }, + { inline: false, name: `${prefix} reopen`, value: 'Reabrir un ticket.' }, + ], + footer: emb.footer + }]; + + message.channel.send({ embeds: embed_content }); + } catch(error) { + console.log(error); + } } \ No newline at end of file diff --git a/commands/info.js b/commands/info.js index be31e88..e53ac37 100644 --- a/commands/info.js +++ b/commands/info.js @@ -1,4 +1,90 @@ +const config = require('../data/config.json'); +const embed = require('../data/embeds.json'); + +const { Client, Intents } = require("discord.js"); +const Discord = require("discord.js"); +const cpuStat = require("cpu-stat"); +const os = require("os"); + +const cli = new Client({ intents: [Intents.FLAGS.GUILDS] }); +cli.login(config.bot.token); +cli.once('ready', () => {}); + exports.run = (client, message, args) => { - // 馃 Content of the command - message.reply("**Give us nuggots for the confederatiowon!** <:nuggots:864676232737718292><:theiStonks:905161849459314789>"); + try { + cpuStat.usagePercent(function (e, percent, seconds) { + try { + if(e) { return console.log(e.stack); } + message.reply({ embeds: [{ + color: 0x62d1f0, + title: '馃捇 Informaci贸n del bot y estado del servidor', + fields: [ + { name: '馃 NodeJS', value: "```"+process.version+"```" }, + { name: '馃懢 Discord.JS', value: "```v"+Discord.version+"```" }, + { name: '馃徃 API Latency', value: "```"+cli.ws.ping+"ms```" }, + { name: '鈱氾笍 Uptime', value: "```"+duration(cli.uptime).map(i=>i).join(", ")+"```" }, + { name: '馃М Consumo Memoria', value: "```"+(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)+" de "+(os.totalmem() / 1024 / 1024).toFixed(2)+"Mb```" }, + { name: '馃 Consumo CPU', value: "```"+percent.toFixed(2)+"%```" }, + { name: '馃捇 Sistema Operativo', value: "```"+os.platform()+" ("+os.arch()+")```" }, + ], + thumbnail: embed.footer + }] }); + } catch (e) { + console.log(e); + message.reply({ embeds: [{ + color: 0x62d1f0, + title: '馃捇 Informaci贸n del bot y estado del servidor', + fields: [ + { name: '馃 NodeJS', value: "```"+process.version+"```" }, + { name: '馃懢 Discord.JS', value: "```v"+Discord.version+"```" }, + { name: '馃徃 API Latency', value: "```"+cli.ws.ping+"ms```" }, + { name: '鈱氾笍 Uptime', value: "```"+duration(cli.uptime).map(i=>i).join(", ")+"```" }, + { name: '馃М Consumo Memoria', value: "```"+(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)+" de "+(os.totalmem() / 1024 / 1024).toFixed(2)+"Mb```" }, + { name: '馃 Consumo CPU', value: "```"+percent.toFixed(2)+"%```" }, + { name: '馃捇 Sistema Operativo', value: "```"+os.platform()+" ("+os.arch()+")```" }, + ], + thumbnail: embed.footer + }] }); + } + }); + + function duration(duration, useMilli = false) { + let remain = duration; + let days = Math.floor(remain / (1000 * 60 * 60 * 24)); + remain = remain % (1000 * 60 * 60 * 24); + let hours = Math.floor(remain / (1000 * 60 * 60)); + remain = remain % (1000 * 60 * 60); + let minutes = Math.floor(remain / (1000 * 60)); + remain = remain % (1000 * 60); + let seconds = Math.floor(remain / (1000)); + remain = remain % (1000); + let milliseconds = remain; + let time = { days, hours, minutes, seconds, milliseconds }; + let parts = [] + + if(time.days) { + parts.push(time.days + ' D铆a'+(time.days !== 1 ? 's' : '')); + } + if(time.hours) { + parts.push(time.hours + ' H'+(time.hours !== 1 ? 's' : '')); + } + if(time.minutes) { + parts.push(time.minutes + ' Min'+(time.minutes !== 1 ? 's' : '')); + } + if(time.seconds) { + parts.push(time.seconds + ' Seg'+(time.seconds !== 1 ? 's' : '')); + } + if(useMilli && time.milliseconds) { + parts.push(time.milliseconds + ' ms'); + } + + if(parts.length === 0) { + return ['instantly'] + } else { + return parts + } + } + } catch(error) { + console.log(error); + } } \ No newline at end of file diff --git a/commands/reopen.js b/commands/reopen.js index be31e88..adf8c67 100644 --- a/commands/reopen.js +++ b/commands/reopen.js @@ -1,4 +1,63 @@ -exports.run = (client, message, args) => { - // 馃 Content of the command - message.reply("**Give us nuggots for the confederatiowon!** <:nuggots:864676232737718292><:theiStonks:905161849459314789>"); +// Data +const config = require('../data/config.json'); +const { template, footer } = require('../data/embeds.json'); +const { isTicket, getUserCreator, updateToOpen, getCurTicketId, getTicketCategory } = require('../functions.js'); + +// DiscordJs +const { MessageActionRow, MessageButton } = require('discord.js'); + +// This thing... +const wait = require('node:timers/promises').setTimeout; + +exports.run = async (client, message, args) => { + try { + const guildId = message.guildId; + const channelId = message.channelId; + + if(!isTicket(channelId, guildId)) { + return; + } + + const embed_reopen = [{ + color: 0xcc3366, + title: template.reopened.title, + description: template.reopened.description, + footer: footer + }]; + + const btns_ticket_reopen = new MessageActionRow() + .addComponents( + new MessageButton().setCustomId('close').setLabel('Cerrar Ticket').setStyle('DANGER') + ); + message.reply({ embeds: embed_reopen, components: [ btns_ticket_reopen ] }); + + updateToOpen(guildId, channelId); + + await wait(750); + + message.guild.channels.fetch(channelId).then( (channelEdit) => { + var userCreator = getUserCreator(guildId, channelId); + var menu_id = getTicketCategory(guildId, channelId); + var category_info = Object.values(config.guilds[guildId]).flat().find(r => r.id === menu_id); + + if(category_info.allowed_staff.length > 0) { + var allowed_staff = [ + { id: message.guild.roles.everyone.id, deny: [ 'VIEW_CHANNEL' ] }, + { id: message.guild.members.cache.get(userCreator), allow: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] }, + { id: category_info.allowed_staff, allow: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] } + ]; + } else { + var allowed_staff = [ + { id: message.guild.roles.everyone.id, deny: [ 'VIEW_CHANNEL' ] }, + { id: message.guild.members.cache.get(userCreator), allow: [ 'VIEW_CHANNEL', 'SEND_MESSAGES' ] } + ]; + } + + message.guild.channels.fetch(channelId).edit({ + permissionOverwrites: allowed_staff + }); + }); + } catch(error) { + console.log(error); + } } \ No newline at end of file diff --git a/commands/sendembed.js b/commands/sendembed.js index 274b704..dd91c04 100644 --- a/commands/sendembed.js +++ b/commands/sendembed.js @@ -4,37 +4,39 @@ const emb = require('../data/embeds.json'); const { MessageActionRow, MessageSelectMenu } = require('discord.js'); exports.run = (client, message, args) => { - - message.delete(); - - const guild_id = message.guildId; - var categorias = []; - - for(let index = 0; index < config.guilds[guild_id].length; index++) { - var data = config.guilds[guild_id][index]; - - categorias.push({ - label: data.name, - description: data.desc, - value: data.id, - emoji: { name: data.emoji.name, id: data.emoji.id } - }); + try { + message.delete(); + + const guild_id = message.guildId; + var categorias = []; + + for(let index = 0; index < config.guilds[guild_id].length; index++) { + var data = config.guilds[guild_id][index]; + + categorias.push({ + label: data.name, + description: data.desc, + value: data.id, + emoji: { name: data.emoji.name, id: data.emoji.id } + }); + } + + const row = new MessageActionRow().addComponents( + new MessageSelectMenu() + .setCustomId('select') + .setPlaceholder('Selecciona una categor铆a') + .addOptions(categorias), + ); + + const embed_content = [{ + color: 0xcc3366, + title: emb.template.main_embed.title, + description: emb.template.main_embed.description, + footer: emb.footer + }]; + + message.channel.send({ embeds: embed_content, components: [row] }); + } catch(error) { + console.log(error); } - - const row = new MessageActionRow().addComponents( - new MessageSelectMenu() - .setCustomId('select') - .setPlaceholder('Selecciona una categor铆a') - .addOptions(categorias), - ); - - const embed_content = [{ - color: 0xcc3366, - title: emb.template.main_embed.title, - description: emb.template.main_embed.description, - footer: emb.footer - }]; - - - message.channel.send({ embeds: embed_content, components: [row] }); } \ No newline at end of file