Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. const Discord = require ("discord.js");
  2. const fs = require("fs");
  3.  
  4. module.exports.run = async (bot, message, args) => {
  5.  
  6. const products = JSON.parse(fs.readFileSync("./data/products.json", "utf8"));
  7.  
  8. const configcolours = require("../config/colours.json");
  9. const configperms = require("../config/permissions.json");
  10. const configmessages = require("../config/messages.json");
  11. const configchannels = require("../config/channels.json");
  12.  
  13. const ticketrole = message.guild.roles.find(x => x.name === configperms.ticketaccess)
  14. //console.log(message.guild.roles.map(r => r.name))
  15.  
  16. let description = args.slice(0).join(' ')
  17.  
  18. if(!description) {
  19.  
  20. message.delete();
  21. let usage = new Discord.RichEmbed()
  22. .setColor(configcolours.general)
  23. .setDescription(configmessages.ticketusage)
  24. .setTimestamp()
  25.  
  26. message.channel.send(usage).then(msg => msg.delete(5000));
  27.  
  28. }
  29.  
  30. else if(!ticketrole) {
  31. console.log('\x1b[31m\x1b[1m', '\n[ERROR] Could not find role named ' + configperms.ticketaccess + ". (-new)\n" + '\x1b[0m')
  32. message.channel.send("**[ERROR]** Could not find role named " + configperms.ticketaccess + ".")
  33. return;
  34. }
  35.  
  36. else if(!configchannels.ticketscategory) {
  37. console.log('\x1b[31m\x1b[1m', '\n[ERROR] Could not find category with the id ' + configchannels.ticketscategory + ". (-new)\n" + '\x1b[0m')
  38. message.channel.send("**[ERROR]** Could not find category with the id " + configchannels.ticketscategory + ".")
  39. return;
  40. }
  41.  
  42. else {
  43.  
  44. message.delete();
  45.  
  46. let ticketmessage = new Discord.RichEmbed()
  47. .setColor(configcolours.general)
  48. .setTitle(message.author.username + " - " + message.author.id)
  49. .setDescription(' ')
  50. .addField("Description", description)
  51. .setThumbnail(message.author.avatarURL)
  52. .setTimestamp()
  53.  
  54. message.guild.createChannel(`ticket-${message.author.username}`, {type:"text"}).then(async c => {
  55. c.setParent(configchannels.ticketscategory);
  56. c.overwritePermissions(message.guild.defaultRole, {
  57. VIEW_CHANNEL: false
  58. })
  59. c.overwritePermissions(message.member, {
  60. VIEW_CHANNEL: true
  61. })
  62. c.overwritePermissions(ticketrole, {
  63. VIEW_CHANNEL: true,
  64. SEND_MESSAGES: true
  65. })
  66.  
  67.  
  68. let log = `-\n` +
  69. `Client ID: ${message.author.id}\n` +
  70. `-\n`;
  71. fs.writeFile(`tickets/${c.id}.txt`, log, (err) => {
  72. if (err) throw err;
  73. });
  74.  
  75.  
  76. const ticketcreated = new Discord.RichEmbed()
  77. .setDescription(`Your ticket has been created! Visit your ticket at ${c}`)
  78. message.channel.send(ticketcreated).then(msg => msg.delete(5000));
  79.  
  80. //First Question (Product)
  81. Q1 = "notDone"
  82. while (Q1 != "done") {
  83. const filter = m => m.author.id === message.author.id;
  84. const Question1 = new Discord.RichEmbed()
  85. .setDescription(`Please select a product`)
  86. c.send(Question1).then(daMessage => {
  87. c.awaitMessages(filter, { max: 1, time: ms('1d') }).then(names => {
  88. product = names.first().content;
  89. }).then(msg => {
  90. for(var i; products.length; i++) {
  91. if(msg.toLowerCase() == product[i]) {
  92. Q1 = "done"
  93. }
  94. }
  95. })
  96. })
  97. }
  98.  
  99.  
  100. let tagger = await c.send(`<@${ticketrole}>`)
  101. tagger.delete()
  102. //c.send(ticketmessage)
  103.  
  104. let tickets = JSON.parse(fs.readFileSync("./data/tickets.json", "utf8"));
  105. tickets[c.id] = {
  106. "owner": message.author.id
  107.  
  108. };
  109.  
  110. fs.writeFile("./data/tickets.json", JSON.stringify(tickets, null, 2), (err) => {
  111. if (err) console.log(err)
  112. });
  113.  
  114. })
  115.  
  116. }
  117. }
  118. module.exports.config = {
  119. name: "new",
  120. aliases: ["ticket"]
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement