diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..bec3382 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,22 @@ +module.exports = { + name: 'help', + description: 'Displays help menu', + usage: 'help [command]', + execute(message, args, config, version) { + // command starts here + message.delete(); + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setColor("#2ECC71") + .setDescription(":white_check_mark: **Started succesfully**") + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + message.channel.send({embed}) + } else { + message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``) + } + + + // command ends here + }, +}; diff --git a/commands/new.js b/commands/new.js new file mode 100644 index 0000000..dbd76b9 --- /dev/null +++ b/commands/new.js @@ -0,0 +1,27 @@ +module.exports = { + name: 'new', + description: 'Create a new ticket', + usage: 'new [brief description]', + execute(message, args, config, version) { + // command starts here + message.delete(); + const ticketChannel = "channel"; + + // log + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setTitle("New Ticket") + .setColour + .addField("Username", message.author.tag, true) + .addField("Channel", ticketChannel, true) + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(`New ticket created by **${message.author.tag} (${message.author.id})**`); + } + + + // command ends here + }, +}; diff --git a/config.json b/config.json new file mode 100644 index 0000000..2b423b0 --- /dev/null +++ b/config.json @@ -0,0 +1,13 @@ +{ + "token": "NDc1MzcxMjg1NTMxMDY2MzY4.XMxz4Q.K8jRuTbte3rQUO3NP4B_3Q3_4i4", + "prefix": "!", + "name": "DiscordTickets", + "guildID": "451745464480432129", + "supportRole": "451745586564169728", + "ticketsCat": "573957872422092974", + "logChannel": "573957980152791080", + "colour": "#009999", + "playing": "with tickets (!help)", + "useEmbeds": true, + "logDMs": true +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..d043f8a --- /dev/null +++ b/index.js @@ -0,0 +1,169 @@ +/* +############################################################################################### + ____ _ _____ _ _ _ +| _ \ (_) ___ ___ ___ _ __ __| | |_ _| (_) ___ | | __ ___ | |_ ___ +| | | | | | / __| / __| / _ \ | '__| / _` | | | | | / __| | |/ / / _ \ | __| / __| +| |_| | | | \__ \ | (__ | (_) | | | | (_| | | | | | | (__ | < | __/ | |_ \__ \ +|____/ |_| |___/ \___| \___/ |_| \__,_| |_| |_| \___| |_|\_\ \___| \__| |___/ + +=============================================================================================== + +--------------------- + Discord Tickets +--------------------- + + A bot created by Eartharoid for the Discord (TM) platform. [GNU-GPLv3.0] + + > The bot manages user-created support tickets to allow your support team to provide quicker + and better assistance to your community members. + +--------------------- + Quick Start +--------------------- + + > For detailed instructions, visit the github repository and read the documentation. + + > Assuming you have created discord application, edit 'config.json' to allow the bot to + function correctly. + + > You will need your bot token (keep it a secret) and channel & role IDs from your server + + > It is recommended that you do not change much / anything in any of the .js files unless + you know what you are doing, to prevent critical errors from occuring. + +=============================================================================================== + + > For support, visit https://github.com/eartharoid/DiscordTickets/#readme + > My website: https://eartharoid.ml + +############################################################################################### +*/ +const fs = require('fs'); +const Discord = require('discord.js'); +const leeks = require('leeks.js'); +const config = require('./config.json'); +const { version, homepage } = require('./package.json'); +const client = new Discord.Client(); +client.commands = new Discord.Collection(); + + +const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); + +client.once('ready', () => { // after bot has logged in + console.log(leeks.colors.magentaBright(` +######## #### ###### ###### ####### ######## ######## +## ## ## ## ## ## ## ## ## ## ## ## ## +## ## ## ## ## ## ## ## ## ## ## +## ## ## ###### ## ## ## ######## ## ## +## ## ## ## ## ## ## ## ## ## ## +## ## ## ## ## ## ## ## ## ## ## ## ## +######## #### ###### ###### ####### ## ## ######## + +######## #### ###### ## ## ######## ######## ###### + ## ## ## ## ## ## ## ## ## ## + ## ## ## ## ## ## ## ## + ## ## ## ##### ###### ## ###### + ## ## ## ## ## ## ## ## + ## ## ## ## ## ## ## ## ## ## + ## #### ###### ## ## ######## ## ###### + + `)); // banner appears in console + console.log(leeks.colors.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`))); + console.log(leeks.colors.yellow(leeks.styles.bold(homepage))); + console.log(''); + console.log(`Starting up...`) + for (const file of commands) { + const command = require(`./commands/${file}`); + client.commands.set(command.name, command); + console.log(`> Loading '${config.prefix}${command.name}' command`); + } + console.log(leeks.colors.green(`Logged in as ${client.user.tag}`)) + client.user.setPresence({ game: { name: config.playing }, status: 'online' }) + // .then(console.log) + .catch(console.error); + // console.log(leeks.colors.green(`Set playing status as `) + leeks.colors.yellow(`'${config.playing}${config.prefix}help'`)); + + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setColor("#2ECC71") + .setDescription(":white_check_mark: **Started succesfully**") + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") + } + if(client.guilds.get(config.guildID).member(client.user).hasPermission("ADMINISTRATOR", false)){ + console.log(leeks.colors.green(`Required permissions have been granted`)) + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setColor("#2ECC71") + .setDescription(":white_check_mark: **Required permissions have been granted**") + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") + } + } else { + console.log(leeks.colors.red(`Required permissions have not been granted`)) + console.log(leeks.colors.red(`Please give the bot the 'ADMINISTRATOR' permission`)) + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setColor("#E74C3C") + .setDescription(":x: **Required permissions have not been granted**\nPlease give the bot the `ADMINISTRATOR` permission") + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**") + } + } + +}); + +client.on('message', message => { + // if (!message.content.startsWith(config.prefix) || message.author.bot) return; + if(message.author.bot) return; + if (message.channel.type === "dm") { + if (message.author.id === client.user.id) return; + if(config.useEmbeds) { + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL) + .setTitle("DM Logger") + .addField("Username", message.author.tag, true) + .addField("Message", message.content, true) + .setFooter(`${client.guilds.get(config.guildID).name} / Ticket Bot\nDiscordTickets by Eartharoid`); + client.channels.get(config.logChannel).send({embed}) + } else { + client.channels.get(config.logChannel).send(`DM received from **${message.author.tag} (${message.author.id})** : \n\n\`\`\`${message.content}\`\`\``); + } + + } + if (message.channel.bot) return; + + // const args = message.content.slice(config.prefix.length).split(/ +/); + + const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`); + if (!prefixRegex.test(message.content)) return; + + const [, matchedPrefix] = message.content.match(prefixRegex); + const args = message.content.slice(matchedPrefix.length).trim().split(/ +/); + const command = args.shift().toLowerCase(); + if (!client.commands.has(command)) return; + + try { + client.commands.get(command).execute(message, args, config, version); + } catch (error) { + console.error(error); + message.channel.send(`:x: **Oof!** An error occured whilst executing that command.`); + } + +}); + +process.on('unhandledRejection', error => { + console.log(leeks.colors.yellow(`[WARN] An error was not caught`)) + console.error(leeks.colors.red(`[ERROR] Uncaught Promise Error: \n${error.stack}`)); +}); + +client.login(config.token); diff --git a/package.json b/package.json new file mode 100644 index 0000000..14e0e13 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "DiscordTickets", + "version": "1.0.0", + "description": "A Discord ticket/support - an open-source & self-host alternative to TicketManager (name tbd)", + "main": "index.js", + "dependencies": { + "discord.js": "^11.4.2", + "leeks.js": "^0.0.1" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/eartharoid/DiscordTickets.git" + }, + "keywords": [ + "discord", + "bot", + "tickets" + ], + "author": "Eartharoid", + "license": "GPL-3.0", + "bugs": { + "url": "https://github.com/eartharoid/DiscordTickets/issues" + }, + "homepage": "https://github.com/eartharoid/DiscordTickets" +}