Advertisement
Guest User

Untitled

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