diff --git a/commands/close.js b/commands/close.js new file mode 100644 index 0000000..6e90c86 --- /dev/null +++ b/commands/close.js @@ -0,0 +1,64 @@ +const discord = require('discord.js') +const bot = require('../index') +const client = bot.client +const config = bot.config + +module.exports = () => { + client.on("messageCreate",msg => { + if (!msg.content.startsWith(config.prefix+"close")) return + + + msg.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + msg.channel.send({content:"You are not in a ticket!"}) + return + } + + const closebutton = new discord.MessageActionRow() + .addComponents([ + new discord.MessageButton() + .setCustomId("closeTicketTrue1") + .setDisabled(false) + .setStyle("SECONDARY") + .setEmoji("🔒") + ]) + + msg.channel.send({content:"**Click on the button below to close this ticket!**",components:[closebutton]}) + + console.log("[system] closed a ticket via command") + + }) + + + }) + + client.on("interactionCreate",(interaction) => { + if (!interaction.isCommand()) return + if (interaction.commandName != "close") return + + interaction.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + interaction.reply({content:"You are not in a ticket!"}) + return + } + + const closebutton = new discord.MessageActionRow() + .addComponents([ + new discord.MessageButton() + .setCustomId("closeTicketTrue1") + .setDisabled(false) + .setStyle("SECONDARY") + .setEmoji("🔒") + ]) + + interaction.reply({content:"**Click on the button below to close this ticket!**",components:[closebutton]}) + + console.log("[system] closed a ticket via command") + + }) + }) +} \ No newline at end of file diff --git a/commands/delete.js b/commands/delete.js new file mode 100644 index 0000000..f0b7305 --- /dev/null +++ b/commands/delete.js @@ -0,0 +1,64 @@ +const discord = require('discord.js') +const bot = require('../index') +const client = bot.client +const config = bot.config + +module.exports = () => { + client.on("messageCreate",msg => { + if (!msg.content.startsWith(config.prefix+"delete")) return + + + msg.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + msg.channel.send({content:"You are not in a ticket!"}) + return + } + + const closebutton = new discord.MessageActionRow() + .addComponents([ + new discord.MessageButton() + .setCustomId("deleteTicketTrue") + .setDisabled(false) + .setStyle("SECONDARY") + .setEmoji("❌") + ]) + + msg.channel.send({content:"**Click on the button below to delete this ticket!**",components:[closebutton]}) + + console.log("[system] deleted a ticket via command") + + }) + + + }) + + client.on("interactionCreate",(interaction) => { + if (!interaction.isCommand()) return + if (interaction.commandName != "delete") return + + interaction.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + interaction.reply({content:"You are not in a ticket!"}) + return + } + + const closebutton = new discord.MessageActionRow() + .addComponents([ + new discord.MessageButton() + .setCustomId("deleteTicketTrue") + .setDisabled(false) + .setStyle("SECONDARY") + .setEmoji("❌") + ]) + + interaction.reply({content:"**Click on the button below to delete this ticket!**",components:[closebutton]}) + + console.log("[system] deleted a ticket via command") + + }) + }) +} \ No newline at end of file diff --git a/commands/extracmds.js b/commands/extracmds.js index 68060f1..119d850 100644 --- a/commands/extracmds.js +++ b/commands/extracmds.js @@ -8,33 +8,6 @@ const config = bot.config //============================= module.exports = () => { - client.on("messageCreate",msg => { - var args = msg.content.split(" ") - if (args[0] == config.prefix+"ticket" && args[1] == "close"){ - - msg.channel.messages.fetchPinned().then(msglist => { - var firstmsg = msglist.last() - - if (firstmsg == undefined){ - msg.channel.send({content:"I didn't find the close button!"}) - } - if (firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } - var CloseMsg = new discord.MessageEmbed() - .setColor(config.main_color) - .setDescription("Click [here]("+firstmsg.url+") to close this ticket.") - .setTitle("Close this ticket:") - - msg.channel.send({embeds:[CloseMsg]}) - if (config.logs){console.log("[command] "+config.prefix+"ticket close (user:"+msg.author.username+")")} - }) - - - } - }) - client.on("messageCreate",msg => { var args = msg.content.split(" ") if (args[0] == config.prefix+"ticket" && args[1] == "rename"){ diff --git a/commands/help.js b/commands/help.js index 38fd500..c3b0848 100644 --- a/commands/help.js +++ b/commands/help.js @@ -18,7 +18,7 @@ module.exports = () => { if (!msg.content.startsWith(config.prefix)) return var args = msg.content.split(config.prefix) - if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("msg")){ + if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("rename")){ msg.channel.send({embeds:[helpEmbed]}) if (config.logs){console.log("[command] "+config.prefix+"ticket help (user:"+msg.author.username+")")} diff --git a/commands/rename.js b/commands/rename.js new file mode 100644 index 0000000..e3333e4 --- /dev/null +++ b/commands/rename.js @@ -0,0 +1,81 @@ +const discord = require('discord.js') +const bot = require('../index') +const client = bot.client +const config = bot.config + +module.exports = () => { + client.on("messageCreate",msg => { + if (!msg.content.startsWith(config.prefix+"rename")) return + + msg.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + msg.channel.send({content:"You are not in a ticket!"}) + return + } + + + if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ + return msg.channel.send({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + var newname = msg.content.split(config.prefix+"rename")[1].substring(1) + var name = msg.channel.name + var prefix = "" + const tickets = config.options + tickets.forEach((ticket) => { + if (name.startsWith(ticket.channelprefix)){ + prefix = ticket.channelprefix + } + }) + + if (!prefix) prefix = "noprefix-" + + msg.channel.setName(prefix+newname) + msg.channel.send({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"}) + + console.log("[system] renamed a ticket via command") + + }) + + + }) + + client.on("interactionCreate",(interaction) => { + if (!interaction.isCommand()) return + if (interaction.commandName != "rename") return + + interaction.channel.messages.fetchPinned().then(msglist => { + var firstmsg = msglist.last() + + if (firstmsg == undefined || firstmsg.author.id != client.user.id){ + interaction.reply({content:"You are not in a ticket!"}) + return + } + + const member = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) + if (!member.permissions.has("MANAGE_CHANNELS") && !member.permissions.has("ADMINISTRATOR")){ + return interaction.reply({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + var newname = interaction.options.getString("name") + var name = interaction.channel.name + var prefix = "" + const tickets = config.options + tickets.forEach((ticket) => { + if (name.startsWith(ticket.channelprefix)){ + prefix = ticket.channelprefix + } + }) + + if (!prefix) prefix = "noprefix-" + + interaction.channel.setName(prefix+newname) + interaction.reply({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"}) + + console.log("[system] renamed a ticket via command") + + }) + }) +} \ No newline at end of file diff --git a/core/closebuttons.js b/core/closebuttons.js index a771278..43b9f3b 100644 --- a/core/closebuttons.js +++ b/core/closebuttons.js @@ -126,6 +126,36 @@ module.exports = () => { require("./ticketCloser").closeTicket(interaction,prefix,"close") }) + client.on("interactionCreate",interaction => { + if (!interaction.isButton()) return + if (interaction.customId != "closeTicketTrue1") return + + interaction.deferUpdate() + const closedButtonDisabled = new discord.MessageActionRow() + .addComponents([ + new discord.MessageButton() + .setCustomId("closeTicketTrue1") + .setDisabled(true) + .setStyle("SECONDARY") + .setEmoji("🔒") + ]) + interaction.message.edit({components:[closedButtonDisabled]}) + + /** + * @type {String} + */ + const name = interaction.channel.name + var prefix = "" + const tickets = config.options + tickets.forEach((ticket) => { + if (name.startsWith(ticket.channelprefix)){ + prefix = ticket.channelprefix + } + }) + + require("./ticketCloser").closeTicket(interaction,prefix,"close") + }) + //NORMAL DELETE client.on("interactionCreate",interaction => { diff --git a/core/slashSystem/slashEnable.js b/core/slashSystem/slashEnable.js index e91d5c0..df9e2c5 100644 --- a/core/slashSystem/slashEnable.js +++ b/core/slashSystem/slashEnable.js @@ -13,7 +13,6 @@ module.exports = async () => { var choices = [] ids.forEach((id) => { const option = getoptions.getOptionsById(id) - console.log(option.id) choices.push({name:option.name,value:option.id}) }) @@ -26,8 +25,8 @@ module.exports = async () => { var readystats = 0 setInterval(() => { - console.log("[status] there are "+chalk.blue(readystats+" out of 8")+" commands ready! (this can take some time)") - if (readystats >= 8){ + console.log("[status] there are "+chalk.blue(readystats+" out of 9")+" commands ready! (this can take some time)") + if (readystats >= 9){ console.log(chalk.green("ready!")) console.log(chalk.blue("you can now start the bot with 'npm start'!")) process.exit(1) @@ -160,4 +159,22 @@ module.exports = async () => { readystats++ }) + //rename + client.application.commands.create({ + name:"rename", + description:"Rename this ticket.", + defaultPermission:true, + type:"CHAT_INPUT", + options:[ + { + type:"STRING", + name:"name", + description:"The new name (without prefix).", + required:true + } + ] + },sid).then(() => { + readystats++ + }) + } \ No newline at end of file diff --git a/index.js b/index.js index c7bc453..87d49f2 100644 --- a/index.js +++ b/index.js @@ -51,6 +51,9 @@ if (process.argv[2] != "slash"){ //commands require('./commands/ticket')() require("./commands/help")() + require("./commands/close")() + require("./commands/delete")() + require("./commands/rename")() //core require('./core/ticketOpener')()