diff --git a/commands/add.js b/commands/add.js new file mode 100644 index 0000000..404d198 --- /dev/null +++ b/commands/add.js @@ -0,0 +1,65 @@ +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+"add")) return + var user = msg.mentions.users.first() + if (!user){ + return msg.channel.send({content:"**There is no user to add:**\nuse: `"+config.prefix+"add `"}) + } + + if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ + return msg.channel.send({content:"You have no permissions to add someone to the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + 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 + } + + msg.channel.permissionOverwrites.create(user.id, { VIEW_CHANNEL:true, ADD_REACTIONS:true,ATTACH_FILES:true, EMBED_LINKS:true, SEND_MESSAGES:true}) + msg.channel.send({content:"Added "+user.tag+" to the ticket"}) + if (config.logs){console.log("[system] added user to ticket (name:"+user.username+",ticket:"+msg.channel.name+")")} + + var loguser = msg.mentions.users.first() + if (config.logs){console.log("[command] "+config.prefix+"add "+loguser.username+" (user:"+msg.author.username+")")} + }) + + }) + + client.on("interactionCreate",(interaction) => { + if (!interaction.isCommand()) return + if (interaction.commandName != "add") return + const user = interaction.options.getUser("user") + 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 add someone to the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + + 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 + } + + interaction.channel.permissionOverwrites.create(user.id, { VIEW_CHANNEL:true, ADD_REACTIONS:true,ATTACH_FILES:true, EMBED_LINKS:true, SEND_MESSAGES:true}) + interaction.reply({content:"Added "+user.tag+" to the ticket"}) + if (config.logs){console.log("[system] added user to ticket (name:"+user.username+",ticket:"+interaction.channel.name+")")} + + var loguser = user + if (config.logs){console.log("[command] "+config.prefix+"add "+loguser.username+" (user:"+interaction.user.username+")")} + }) + + + }) +} \ No newline at end of file diff --git a/commands/extracmds.js b/commands/extracmds.js index 119d850..0a63230 100644 --- a/commands/extracmds.js +++ b/commands/extracmds.js @@ -8,68 +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] == "rename"){ - - if (msg.member.roles.cache.has(config.botperms_role) == false && msg.author.id != "779742674932072469"){ - msg.channel.send({content:config.messages.general.nopermissions}) - return - } - - if (args[2] == null || args[2] == undefined || args[2] == "" || args[2] == false){ - msg.channel.send({content:"Not enough parameters!"}) - return - } - - var name = args[2] - var oldname = msg.channel.name - msg.channel.messages.fetchPinned().then(msglist => { - if (msglist.last().author.id == client.user.id){ - msg.channel.send({content:"The name from the ticket is changed!"}).then(rmsg => { - rmsg.channel.setName(name) - if (config.logs){console.log("[system] renamed a ticket (name:"+oldname+",newname:"+name+")")} - }) - }else{ - msg.channel.send({content:"You are not in a ticket!"}) - } - }) - if (config.logs){console.log("[command] "+config.prefix+"ticket rename (user:"+msg.author.username+")")} - } - }) - - client.on("messageCreate",msg => { - var args = msg.content.split(" ") - if (args[0] == config.prefix+"ticket" && args[1] == "add"){ - - if (msg.member.roles.cache.has(config.botperms_role) == false && msg.author.id != "779742674932072469"){ - msg.channel.send({content:config.messages.general.nopermissions}) - return - } - - msg.channel.messages.fetch().then(msglist => { - if (msglist.last().author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } - - if (args[2] == null || args[2] == undefined || args[2] == "" || args[2] == false){ - msg.channel.send({content:"Not enough parameters!"}) - return - } - var user = msg.mentions.users.first() - if (!user){ - return - } - - msg.channel.permissionOverwrites.create(user.id, { VIEW_CHANNEL:true, ADD_REACTIONS:true,ATTACH_FILES:true, EMBED_LINKS:true, SEND_MESSAGES:true}) - if (config.logs){console.log("[system] added user to ticket (name:"+user.username+",ticket:"+msg.channel.name+")")} - - }) - var loguser = msg.mentions.users.first() - if (config.logs){console.log("[command] "+config.prefix+"ticket add "+loguser.username+" (user:"+msg.author.username+")")} - } - }) client.on("messageCreate",msg => { var args = msg.content.split(" ") diff --git a/commands/remove.js b/commands/remove.js new file mode 100644 index 0000000..7f15655 --- /dev/null +++ b/commands/remove.js @@ -0,0 +1,65 @@ +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+"remove")) return + var user = msg.mentions.users.first() + if (!user){ + return msg.channel.send({content:"**There is no user to remove:**\nuse: `"+config.prefix+"remove `"}) + } + + if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ + return msg.channel.send({content:"You have no permissions to remove someone from the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + 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 + } + + msg.channel.permissionOverwrites.delete(user.id) + msg.channel.send({content:"Deleted "+user.tag+" from the ticket"}) + if (config.logs){console.log("[system] deleted user from ticket (name:"+user.username+",ticket:"+msg.channel.name+")")} + + var loguser = msg.mentions.users.first() + if (config.logs){console.log("[command] "+config.prefix+"remove "+loguser.username+" (user:"+msg.author.username+")")} + }) + + }) + + client.on("interactionCreate",(interaction) => { + if (!interaction.isCommand()) return + if (interaction.commandName != "remove") return + const user = interaction.options.getUser("user") + 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 remove someone from the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + } + + + 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 + } + + interaction.channel.permissionOverwrites.delete(user.id) + interaction.reply({content:"Deleted "+user.tag+" from the ticket"}) + if (config.logs){console.log("[system] removed user from ticket (name:"+user.username+",ticket:"+interaction.channel.name+")")} + + var loguser = user + if (config.logs){console.log("[command] "+config.prefix+"remove "+loguser.username+" (user:"+interaction.user.username+")")} + }) + + + }) +} \ No newline at end of file diff --git a/index.js b/index.js index d3013cb..8697d34 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,8 @@ if (process.argv[2] != "slash"){ require("./commands/close")() require("./commands/delete")() require("./commands/rename")() + require("./commands/add")() + require("./commands/remove")() //core require('./core/ticketOpener')() diff --git a/storage/tickets/779742674932072469 b/storage/tickets/779742674932072469 new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/storage/tickets/779742674932072469 @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/storage/userTickets/971449683379646526 b/storage/userTickets/971449683379646526 new file mode 100644 index 0000000..71d7104 --- /dev/null +++ b/storage/userTickets/971449683379646526 @@ -0,0 +1 @@ +779742674932072469 \ No newline at end of file