AnonymousUser1233

Untitled

Oct 1st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. module.exports = {
  2. name: 'new',
  3. description: 'Raises a new ticket for the UniverseMC support team to handle.',
  4. aliases: ['ticket'],
  5. usage: '',
  6. cooldown: 0,
  7. guildOnly: true,
  8. execute(client, connection, config, message, args) {
  9. const emojiCharacters = require('../../helpers/emojiCharacters.js');
  10. const moment = require('moment');
  11. message.guild.createChannel(`${message.member.displayName}`, {type: 'text'}, {
  12. permissionOverwrites: [{
  13. id: message.author.id,
  14. allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES'],
  15. deny: ['ADD_REACTIONS']
  16. },
  17. {
  18. id: message.guild.defaultRole,
  19. deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY', 'ADD_REACTIONS']
  20. },
  21. {
  22. id: config.staffRoleId,
  23. allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY', 'ADD_REACTIONS']
  24. }
  25. ]
  26. })
  27. .then(ch => {
  28. connection.query(`INSERT INTO Tickets (creatorId, channelId, status) VALUES ("${message.author.id}", "${ch.id}", "NEW")`, (err, result) => {
  29. if (err) {
  30. ch.send("There was an error inserting data. Please check the console for the error.");
  31. return console.log(err);
  32. }
  33. })
  34. let initialQuestionEmbed = client.helpers.get('CreateEmptyEmbed').execute("Success", client, false).setTitle(`Please chose your ticket type!`).setDescription("Select the type of ticket you would like to create below\nYou can do this by selecting the appropriate reaction that corresponds with your inquiry below\nFailure to react in **5 minutes** will automatically close this ticket");
  35. for (let i = 0; i < config.tickets.types.length; i++) {
  36. const ticketType = config.tickets.types[i];
  37. initialQuestionEmbed.setDescription(initialQuestionEmbed.description + `\n:regional_indicator_${String.fromCharCode(97 + i)}: ${ticketType.name}`);
  38. }
  39. ch.send(initialQuestionEmbed)
  40. .then(m => {
  41. React(0, config.tickets.types.length, m);
  42.  
  43. function React(mini, maxi, message) {
  44. if (mini < maxi) {
  45. m.react(emojiCharacters[String.fromCharCode(97 + mini)])
  46. .then(r => {
  47. mini++;
  48. React(mini++, maxi, message)
  49. });
  50. }
  51. }
  52. const filter = (reaction, user) => {
  53. return user.id === message.author.id;
  54. };
  55. m.awaitReactions(filter, { max: 1, time: 300000, errors: ['time'] })
  56. .then(collected => {
  57. const reaction = collected.first();
  58. let question = config.tickets.types[emojiCharacters[reaction.emoji.name]];
  59. connection.query(`UPDATE Tickets SET ticketType = "${question.name}" WHERE channelId = "${ch.id}" AND creatorId = "${message.author.id}"`, (err, result) => {
  60. if (err) return console.log(err);
  61. if (question.adminOnly == true) {
  62. ch.overwritePermissions(ch.guild.roles.find(r => r.id == config.staffRoleId), {
  63. 'VIEW_CHANNEL': false,
  64. 'SEND_MESSAGES': false,
  65. 'READ_MESSAGE_HISTORY': false,
  66. 'ADD_REACTIONS': false
  67. });
  68. }
  69. ch.setName((`${message.member.displayName}-${question.name.replace(/ /g, '-')}`).toLowerCase());
  70. ch.send(client.helpers.get('CreateEmptyEmbed').execute("Success", client, false).setTitle("Please answer the following question").setDescription(question.questions[0]));
  71. })
  72. })
  73. .catch(collected => {
  74. connection.query(`UPDATE Tickets SET closedReason = "No option chosen", status = "CLOSED", closedDate = '${moment(new Date).format('YYYY-MM-DD HH:mm:ss')}' WHERE channelId = "${ch.id}" AND creatorId = "${message.author.id}"`, (err, result) => {
  75. ch.delete();
  76. if (err) {
  77. return console.log(err);
  78. }
  79. })
  80. });
  81. })
  82. .catch(console.error)
  83. ch.setParent(ch.guild.channels.find(cat => cat.id == config.tickets.category));
  84. ch.setTopic(`${config.prefix}close [reason] to close the ticket`);
  85. message.delete();
  86. let ticketCreatedEmbed = client.helpers.get('CreateEmptyEmbed').execute("Success", client, false).setTitle(`Ticket Created!`).setDescription(`Hello ${message.author.toString()}, Please select the type of ticket you would like to create under ${ch.toString()}! Staff will be with you as soon as possible!`);
  87. message.channel.send(ticketCreatedEmbed);
  88. ch.send(message.author.toString())
  89. .then(notification => {
  90. notification.delete();
  91. });
  92. })
  93. .catch(console.error)
  94. }
  95. };
Advertisement
Add Comment
Please, Sign In to add comment