|
| 1 | +const Command = require("../base/Command"); |
| 2 | +const Discord = require("discord.js"); |
| 3 | +const Thread = require("../models/thread.js"); |
| 4 | + |
| 5 | +class Start extends Command { |
| 6 | + constructor (client) { |
| 7 | + super(client, { |
| 8 | + name: "start", |
| 9 | + description: "Starts a new ticket via private messages.", |
| 10 | + category: "", |
| 11 | + usage: "Modmail", |
| 12 | + enabled: true, |
| 13 | + guildOnly: false, |
| 14 | + aliases: [], |
| 15 | + permLevel: "User", |
| 16 | + cooldown: 5, |
| 17 | + args: false, |
| 18 | + DMonly: true |
| 19 | + }); |
| 20 | + } |
| 21 | + |
| 22 | + async run (message, args, level, reply) { // eslint-disable-line no-unused-vars |
| 23 | + const haveThread = await Thread.findOne({ recipient: message.author.id, closed: false }); |
| 24 | + if (haveThread) return reply("You already have an ongoing thread."); |
| 25 | + |
| 26 | + const issueEmbed = new Discord.MessageEmbed() |
| 27 | + .setAuthor(message.author.tag, message.author.displayAvatarURL()) |
| 28 | + .setDescription("Hello, please describe your issue briefly, the more details, the faster it will be for the staff team to help you. Type `cancel` to cancel.") |
| 29 | + .setColor("ORANGE"); |
| 30 | + const issue = await this.client.awaitReply(message, issueEmbed, 900000); |
| 31 | + if (issue === false) return reply(`${this.client.config.emojis.redTick} Your request has timed out. If you wish to submit a request please use \`${this.client.config.prefix}start\`.`); |
| 32 | + if (issue.toLowerCase() === "cancel") return reply(this.client.config.emojis.greenTick + " Aborted."); |
| 33 | + |
| 34 | + const channel = await this.client.staffGuild.channels.create(message.author.tag.replace("#", "-"), { |
| 35 | + type: "text", |
| 36 | + topic: `User: ${message.author.tag} (ID: ${message.author.id})\n\nIssue: ${issue}`, |
| 37 | + nsfw: false, |
| 38 | + parent: this.client.config.parent, |
| 39 | + permissionOverwrites: [{ |
| 40 | + id: this.client.staffGuild.id, |
| 41 | + deny: ["VIEW_CHANNEL"], |
| 42 | + type: "role" |
| 43 | + }, |
| 44 | + { |
| 45 | + id: this.client.config.supportRole, |
| 46 | + allow: ["VIEW_CHANNEL"], |
| 47 | + type: "role" |
| 48 | + }] |
| 49 | + }); |
| 50 | + |
| 51 | + const infoEmbed = new Discord.MessageEmbed() |
| 52 | + .setAuthor(message.author.tag, message.author.displayAvatarURL()) |
| 53 | + .setDescription(`**${message.author.tag}** (ID: ${message.author.id}) has opened a ticket.\nAccount was created ${fetchTime(Date.now() - message.author.createdTimestamp)} ago.`) |
| 54 | + .addField("Issue:", issue) |
| 55 | + .setColor("ORANGE") |
| 56 | + .setTimestamp(); |
| 57 | + await channel.send(infoEmbed); |
| 58 | + |
| 59 | + var threadID = await Thread.countDocuments(); |
| 60 | + threadID += 1; |
| 61 | + |
| 62 | + await (new Thread({ |
| 63 | + id: threadID, |
| 64 | + recipient: message.author.id, |
| 65 | + channel: channel.id, |
| 66 | + guild: channel.guild.id, |
| 67 | + issue: issue, |
| 68 | + timestamp: Date.now() |
| 69 | + }).save()); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +module.exports = Start; |
| 74 | + |
| 75 | +function fetchTime (ms, object = false) { |
| 76 | + var totalSeconds = (ms / 1000); |
| 77 | + var days = Math.floor(totalSeconds / 86400); |
| 78 | + totalSeconds %= 86400; |
| 79 | + var hours = Math.floor(totalSeconds / 3600); |
| 80 | + totalSeconds %= 3600; |
| 81 | + var minutes = Math.floor(totalSeconds / 60); |
| 82 | + var seconds = totalSeconds % 60; |
| 83 | + seconds = Math.floor(seconds); |
| 84 | + if (object === true) return { days, hours, minutes, seconds }; |
| 85 | + |
| 86 | + return `${days} Days, ${hours} Hours, ${minutes} Minutes and ${seconds} Seconds`; |
| 87 | +} |
0 commit comments