Advertisement
Guest User

Untitled

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