Advertisement
Guest User

here

a guest
Jan 25th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. const { Command } = require("../Structures/Command");
  2. const Bot = require("../index");
  3. const Discord = require("discord.js")
  4. module.exports = class MODMAILCOMMAND extends Command {
  5.  
  6. constructor(bot) {
  7. super(bot)
  8. this.name = "modmail",
  9. this.description = "Modmail!",
  10. this.usage = "<prefix>create / stop",
  11. this.ownerOnly = false,
  12. this.aliases = ["create"],
  13. this.bot = bot;
  14. }
  15.  
  16. async exec(message , member) {
  17.  
  18. let messageArray = message.content.split(" ")
  19. let cmd = messageArray[0].toLowerCase();
  20. let args = messageArray.slice(1)
  21. let db = await this.bot.db.findOne({ where: { guild_id: message.guild.id } })
  22. if (db === null) {
  23. await this.bot.db.create({ guild_id: message.guild.id })
  24. }
  25.  
  26. if (message.author.bot) return;
  27.  
  28. if (cmd.toLowerCase() === `!create`) {
  29.  
  30. message.guild.createChannel("modmail", "category")
  31.  
  32. }
  33.  
  34. let category = message.guild.channels.find(c => c.name == "modmail" && c.type == "category")
  35.  
  36. if (message.channel.type !== `text`) {
  37.  
  38. let active = await db.fetch(`support_${message.author.id}`);
  39. let guild = bot.guilds.get(`${category.id}`);
  40. let channel, found = true;
  41.  
  42. try {
  43. if (active) bot.channels.get(active.channelID).guild;
  44. } catch (e) {
  45. found = false;
  46. }
  47.  
  48. if (!active || !found) {
  49.  
  50. active = {};
  51.  
  52. channel = await guild.createChannel(`${message.author.username}-${message.author.discriminator}`, {
  53. parent: `662836369059479563`,
  54. topic: `!close to close the ticket | Support for ${message.author.tag} | ID: ${message.author.id}`,
  55. type: `text`
  56. });
  57.  
  58. let author = message.author;
  59.  
  60. const newChannel = new Discord.RichEmbed()
  61. .setColor(0xff6b6b)
  62. .setTitle(`__**New Modmail thread**__`)
  63. .addField(`User`, `${message.author}`)
  64. .addField(`ID`, `${message.author.id}`)
  65. .setFooter(`!close to close the thread!`, `${channel.guild.iconURL}`)
  66. .setTimestamp()
  67. .setThumbnail(`${message.author.displayAvatarURL}`)
  68. await channel.send(`@here`)
  69. await channel.send(newChannel)
  70. await author.send(`Thank you for your message! Our modmail team will reply to you here as soon as possible.`)
  71.  
  72. active.channelID = channel.id;
  73. active.targetID = author.id;
  74.  
  75.  
  76. }
  77.  
  78. channel = bot.channels.get(active.channelID);
  79.  
  80. if (message.attachments.size !== 0) { // Attachments are present.
  81. const firstAttachment = message.attachments.first();
  82.  
  83.  
  84. const embed = new Discord.RichEmbed()
  85. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  86. .setDescription(`${message.content}`)
  87. .setColor(0xff6b6b)
  88. .setTimestamp()
  89. .setImage(`${firstAttachment.url}`)
  90. .setFooter(`!help`)
  91.  
  92. await channel.send(embed)
  93.  
  94. }
  95.  
  96.  
  97. if (message.attachments.size === 0) { // Attachments are present.
  98.  
  99. const embed = new Discord.RichEmbed()
  100. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  101. .setDescription(`${message.content}`)
  102. .setColor(0xff6b6b)
  103. .setTimestamp()
  104. .setFooter(`!help`)
  105.  
  106. await channel.send(embed)
  107.  
  108. }
  109.  
  110. db.set(`support_${message.author.id}`, active);
  111. db.set(`supportChannel_${channel.id}`, message.author.id);
  112. }
  113.  
  114. let support = await db.get(`supportChannel_${message.channel.id}`);
  115.  
  116. if (support) {
  117.  
  118. support = await db.fetch(`support_${support}`);
  119.  
  120. let supportUser = bot.users.get(support.targetID);
  121. if (!supportUser) return message.channel.delete();
  122.  
  123. if (cmd.toLowerCase() === `!help`) {
  124.  
  125. const help = new Discord.RichEmbed()
  126. .setAuthor(`${bot.user.username} commands!`, `${bot.user.displayAvatarURL}`)
  127. .setColor(0xff0000)
  128. .addField(`!help`, `Shows this message`)
  129. .addField(`!reply | !r`, `Replies to the modmail thread`)
  130. .addField(`!close | !end`, `Ends the modmail thread`)
  131. .setTimestamp()
  132.  
  133. message.author.send(help)
  134.  
  135. }
  136.  
  137. if (cmd.toLowerCase() === `!close`) {
  138.  
  139. supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
  140.  
  141. message.channel.delete();
  142.  
  143. db.delete(`support_${support.targetID}`);
  144.  
  145. }
  146.  
  147. if (cmd.toLowerCase() === `!end`) {
  148.  
  149. supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
  150.  
  151. message.channel.delete();
  152.  
  153. db.delete(`support_${support.targetID}`);
  154.  
  155. }
  156.  
  157. if (cmd === `!r`) {
  158.  
  159. let suggestion = args.slice(0).join(" ");
  160.  
  161. if (message.attachments.size !== 0) { // Attachments are present.
  162. const firstAttachment = message.attachments.first();
  163.  
  164. const embed = new Discord.RichEmbed()
  165. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  166. .setDescription(`${suggestion}`)
  167. .setColor(0xff0000)
  168. .setImage(`${firstAttachment.url}`)
  169. .setTimestamp()
  170. .setFooter(`!help`)
  171. message.channel.send(embed)
  172. }
  173.  
  174. if (message.attachments.size === 0) { // Attachments are present.
  175.  
  176. const embed1 = new Discord.RichEmbed()
  177. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  178. .setDescription(`${suggestion}`)
  179. .setColor(0xff0000)
  180. .setTimestamp()
  181. .setFooter(`!help`)
  182. message.channel.send(embed1)
  183. }
  184.  
  185. if (message.attachments.size === 0) { // Attachments are present.
  186. bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  187. message.delete({ timeout: 1000 });
  188. }
  189.  
  190. if (message.attachments.size !== 0) { // Attachments are present.
  191. const firstAttachment = message.attachments.first();
  192. bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  193.  
  194. const embed3 = new Discord.RichEmbed()
  195. .setImage(`${firstAttachment.url}`)
  196. await bot.users.get(support.targetID).send(embed3)
  197.  
  198. message.delete({ timeout: 1000 });
  199. }
  200.  
  201. }
  202.  
  203. if (cmd === `!reply`) {
  204.  
  205. let suggestion = args.slice(0).join(" ");
  206.  
  207.  
  208. if (message.attachments.size !== 0) { // Attachments are present.
  209. const firstAttachment = message.attachments.first();
  210.  
  211. const embed = new Discord.RichEmbed()
  212. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  213. .setDescription(`${suggestion}`)
  214. .setColor(0xff0000)
  215. .setImage(`${firstAttachment.url}`)
  216. .setTimestamp()
  217. .setFooter(`!help`)
  218. message.channel.send(embed)
  219. }
  220.  
  221. if (message.attachments.size === 0) { // Attachments are present.
  222.  
  223. const embed1 = new Discord.RichEmbed()
  224. .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  225. .setDescription(`${suggestion}`)
  226. .setColor(0xff0000)
  227. .setTimestamp()
  228. .setFooter(`!help`)
  229. message.channel.send(embed1)
  230. }
  231.  
  232. if (message.attachments.size === 0) { // Attachments are present.
  233. bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  234. message.delete({ timeout: 1000 });
  235. }
  236.  
  237. if (message.attachments.size !== 0) { // Attachments are present.
  238. const firstAttachment = message.attachments.first();
  239. bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  240.  
  241. const embed3 = new Discord.RichEmbed()
  242. .setImage(`${firstAttachment.url}`)
  243. await bot.users.get(support.targetID).send(embed3)
  244.  
  245. message.delete({ timeout: 1000 })
  246.  
  247. }
  248.  
  249. }
  250.  
  251. }
  252.  
  253. }
  254.  
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement