Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 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. for(var i = 0; 2 > i; i++) {
  57. console.log("i = " + i)
  58. const filter = response => {
  59. return products.some(answer => answer.toLowerCase() === response.content.toLowerCase());
  60. };
  61.  
  62. const product = new Discord.RichEmbed()
  63. .setDescription("Hello " + message.author.username + ",\nWhat product would you like to order?")
  64.  
  65. await QChannel.send(product).then(() => {
  66. QChannel.awaitMessages(filter, { max: 1, time: 30000, errors: ['time'] })
  67. return QChannel.awaitMessages
  68. .then(collected => {
  69. i = 3
  70. QChannel.send(`${collected.first().author} got the correct answer!`);
  71. })
  72. .catch(collected => {
  73. i = 0
  74. const productIssue = new Discord.RichEmbed()
  75. .setDescription("Invalid Product, Please try again!")
  76. QChannel.send(productIssue);
  77. });
  78. });
  79. }
  80. }
  81.  
  82.  
  83. message.guild.createChannel(`ticket-${message.author.username}`, {type:"text"}).then(async c => {
  84. c.setParent(configchannels.ticketscategory);
  85. c.overwritePermissions(message.guild.defaultRole, {
  86. VIEW_CHANNEL: false
  87. })
  88. c.overwritePermissions(message.member, {
  89. VIEW_CHANNEL: true
  90. })
  91. c.overwritePermissions(ticketrole, {
  92. VIEW_CHANNEL: true,
  93. SEND_MESSAGES: true
  94. })
  95.  
  96.  
  97. let log = `-\n` +
  98. `Client ID: ${message.author.id}\n` +
  99. `-\n`;
  100. fs.writeFile(`tickets/${c.id}.txt`, log, (err) => {
  101. if (err) throw err;
  102. });
  103.  
  104.  
  105. const ticketcreated = new Discord.RichEmbed()
  106. .setDescription(`Your ticket has been created! Visit your ticket at ${c}`)
  107. message.channel.send(ticketcreated).then(msg => msg.delete(5000));
  108.  
  109. //let tagger = await c.send(`<@${ticketrole}>`)
  110. //tagger.delete()
  111. //c.send(ticketmessage)
  112.  
  113. ticketChannel = c
  114.  
  115. let tickets = JSON.parse(fs.readFileSync("./data/tickets.json", "utf8"));
  116. tickets[c.id] = {
  117. "owner": message.author.id
  118.  
  119. };
  120.  
  121. fs.writeFile("./data/tickets.json", JSON.stringify(tickets, null, 2), (err) => {
  122. if (err) console.log(err)
  123. });
  124.  
  125. }).then(m => {
  126.  
  127. Question(ticketChannel);
  128.  
  129. })
  130.  
  131. }
  132. }
  133. module.exports.config = {
  134. name: "new",
  135. aliases: ["ticket"]
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement