diff --git a/discord-bot/commands/ticket.js b/discord-bot/commands/ticket.js new file mode 100644 index 0000000..e90ee07 --- /dev/null +++ b/discord-bot/commands/ticket.js @@ -0,0 +1,121 @@ +const { SlashCommandBuilder, PermissionsBitField, ChannelType, ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('ticket') + .setDescription('Create a ticket!') + .addStringOption(option => option + .setName('category') + .setDescription('The category of the ticket') + .setRequired(true) + .addChoices( + { name: 'Technical Problem', value: 'tech-problem' }, + { name: 'Griefing or Harm', value: 'grief-or-harm' }, + { name: 'Suggestion', value: 'suggestion' }, + { name: 'Other', value: 'other' }, + )), + + async execute({ interaction, createEmbed }) { + await interaction.reply({ embeds: [createEmbed.basic('Creating ticket channel...')], fetchReply: true, ephemeral: true }); + + const category = interaction.options.getString('category'); + + let ticketChannel; + + if (category === 'grief-or-harm') { + ticketChannel = await interaction.member.guild.channels.create({ + name: `ticket-${interaction.user.username}`, + type: ChannelType.GuildText, + parent: process.env.TICKET_CATEGORY_ID, + permissionOverwrites: [ + { + id: interaction.guild.id, + deny: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: process.env.MODERATOR_ROLE_ID, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: interaction.user.id, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + ], + + }); + } else if (category === 'tech-problem') { + ticketChannel = await interaction.member.guild.channels.create({ + name: `ticket-${interaction.user.username}`, + type: ChannelType.GuildText, + parent: process.env.TICKET_CATEGORY_ID, + permissionOverwrites: [ + { + id: interaction.guild.id, + deny: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: process.env.CONTRIBUTER_ROLE_ID, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: interaction.user.id, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + ], + }); + } else { + ticketChannel = await interaction.member.guild.channels.create({ + name: `ticket-${interaction.user.username}`, + type: ChannelType.GuildText, + parent: process.env.TICKET_CATEGORY_ID, + permissionOverwrites: [ + { + id: interaction.guild.id, + deny: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: interaction.user.id, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + ], + }); + } + + const closeRow = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('close') + .setLabel('Close Ticket') + .setStyle(ButtonStyle.Danger), + ); + + const cancelRow = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('cancel') + .setLabel('Cancel') + .setStyle(ButtonStyle.Danger), + ); + + const ticketMessage = await ticketChannel.send({ embeds: [createEmbed.basic(`${interaction.user} created a ticket with the category **${category}**`)], components: [closeRow] }); + + const collector = ticketMessage.createMessageComponentCollector(); + + let ticketCancelMessage; + let timeout; + collector.on('collect', async i => { + if (i.customId === 'close') { + ticketCancelMessage = await ticketChannel.send({ embeds: [createEmbed.basic('Closing ticket in 10 seconds...')] }); + await ticketMessage.createMessageComponentCollector(); + await i.update({ components: [cancelRow] }); + timeout = setTimeout(() => ticketChannel.delete(), 10000); + } else { + clearTimeout(timeout); + await ticketCancelMessage.edit({ embeds: [createEmbed.basic('Ticket closing has been stopped')] }); + await i.update({ components: [closeRow] }); + } + }); + + interaction.editReply({ embeds: [createEmbed.basic(`${ticketChannel} has been created`)], emphemeral: true }); + }, +}; diff --git a/discord-bot/events/guildMemberAdd.js b/discord-bot/events/guildMemberAdd.js index bd4e6bc..4f312af 100644 --- a/discord-bot/events/guildMemberAdd.js +++ b/discord-bot/events/guildMemberAdd.js @@ -8,6 +8,7 @@ module.exports = { const newMemberEmbed = new EmbedBuilder() .setTitle(`${member.user.username} has joined!`) .setDescription(`Welcome ${member} to the **Polarcraft** Discord server!`) + .setColor(process.env.EMBED_COLOR) .setThumbnail(member.user.avatarURL()); const channel = await client.channels.cache.get(process.env.LOG_CHANNEL_ID); diff --git a/discord-bot/events/guildMemberRemove.js b/discord-bot/events/guildMemberRemove.js new file mode 100644 index 0000000..f59ced1 --- /dev/null +++ b/discord-bot/events/guildMemberRemove.js @@ -0,0 +1,15 @@ +const { Events, EmbedBuilder } = require('discord.js'); + +module.exports = { + name: Events.GuildMemberRemove, + async execute({ client, log }, member) { + log.Info(`${member.user.username} has left`); + + const newMemberEmbed = new EmbedBuilder() + .setTitle(`${member.user.username} has left!`) + .setColor(process.env.EMBED_COLOR); + + const channel = await client.channels.cache.get(process.env.LOG_CHANNEL_ID); + channel.send({ embeds: [newMemberEmbed] }); + }, +}; diff --git a/discord-bot/package-lock.json b/discord-bot/package-lock.json index c0987e7..f4d4e79 100644 --- a/discord-bot/package-lock.json +++ b/discord-bot/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@discord-player/downloader": "^3.0.1", "@discord-player/extractor": "^3.0.2", "@discordjs/opus": "^0.8.0", "chalk": "^4.1.2", @@ -20,14 +19,6 @@ "eslint": "^8.29.0" } }, - "node_modules/@discord-player/downloader": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@discord-player/downloader/-/downloader-3.0.1.tgz", - "integrity": "sha512-7A+gyfkqAl2u1j3FHjfujgubVxKgIFO7LuFrBujdfG/G82LLxshd7/+BcVbQTPvIk46kdAoqNp+g59cjJj8P0w==", - "dependencies": { - "youtube-dl-exec": "^1.2.4" - } - }, "node_modules/@discord-player/extractor": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@discord-player/extractor/-/extractor-3.0.2.tgz", @@ -652,14 +643,6 @@ "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==" }, - "node_modules/dargs": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", - "integrity": "sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==", - "engines": { - "node": ">=8" - } - }, "node_modules/data-urls": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-2.0.0.tgz", @@ -1232,28 +1215,6 @@ "node": ">=0.10.0" } }, - "node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -1404,17 +1365,6 @@ "undici": "^5.8.2" } }, - "node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -1537,14 +1487,6 @@ "node": ">= 6" } }, - "node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "engines": { - "node": ">=10.17.0" - } - }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -1660,25 +1602,6 @@ "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==" }, - "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-unix": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/is-unix/-/is-unix-2.0.7.tgz", - "integrity": "sha512-5aio7Qef7QKjQxdb52cXAmim9Bh3+y3yc9IA2IsXWwZVlc1rRsJHWtBxNwGBu9KqW7PJCbhepNIkfFdilRkHpQ==", - "engines": { - "node": ">= 12" - } - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1915,11 +1838,6 @@ "semver": "bin/semver.js" } }, - "node_modules/merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -1939,14 +1857,6 @@ "node": ">= 0.6" } }, - "node_modules/mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "engines": { - "node": ">=6" - } - }, "node_modules/miniget": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.2.tgz", @@ -2059,17 +1969,6 @@ "node": ">=6" } }, - "node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dependencies": { - "path-key": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/npmlog": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", @@ -2113,20 +2012,6 @@ "wrappy": "1" } }, - "node_modules/onetime": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", - "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", - "dependencies": { - "mimic-fn": "^2.1.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/optionator": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", @@ -2581,14 +2466,6 @@ "node": ">=8" } }, - "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "engines": { - "node": ">=6" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -2894,22 +2771,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/youtube-dl-exec": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/youtube-dl-exec/-/youtube-dl-exec-1.3.4.tgz", - "integrity": "sha512-jrQ6Dilpcm7CX8SJA9IT5mOcYRISAIMQyaAIV+Hpi4CcY7omnqa2I1OXk/sIpS0czJ2YucJcJXHr4Se5wq54aA==", - "hasInstallScript": true, - "dependencies": { - "dargs": "~7.0.0", - "execa": "~5.1.0", - "is-unix": "~2.0.1", - "mkdirp": "~1.0.4", - "node-fetch": "~2.6.5" - }, - "engines": { - "node": ">= 12" - } - }, "node_modules/youtube-sr": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.3.4.tgz", diff --git a/discord-bot/package.json b/discord-bot/package.json index d89e9a4..b5b3d74 100644 --- a/discord-bot/package.json +++ b/discord-bot/package.json @@ -10,7 +10,6 @@ "author": "", "license": "ISC", "dependencies": { - "@discord-player/downloader": "^3.0.1", "@discord-player/extractor": "^3.0.2", "@discordjs/opus": "^0.8.0", "chalk": "^4.1.2",