Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
🚀 Terminado de implementar comandos (no botones)
Browse files Browse the repository at this point in the history
Implementado también try/catch por las dudas
  • Loading branch information
imkuroneko committed Mar 11, 2022
1 parent 8b21518 commit ab1262d
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 77 deletions.
26 changes: 15 additions & 11 deletions commands/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
66 changes: 63 additions & 3 deletions commands/close.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
43 changes: 39 additions & 4 deletions commands/delete.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
46 changes: 24 additions & 22 deletions commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
90 changes: 88 additions & 2 deletions commands/info.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
65 changes: 62 additions & 3 deletions commands/reopen.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit ab1262d

Please sign in to comment.