Fyck-You

index.js

Aug 2nd, 2021
1,026
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client({ partials: ["MESSAGE", "USER", "REACTION"] });
  3.  
  4. let {
  5.     prefix,
  6.     settings,
  7.     CustomStatus,
  8.     CustomStatusType,
  9.     Status,
  10.     ticketCreationDates,
  11.     unknownCommandMessage,
  12.     unknownCommand,
  13.     updateTitle,
  14.     updateFooter,
  15.     updateReactionUp,
  16.     updateReactionDown,
  17.     closeTicketError,
  18.     ticketCreationTable,
  19.     title,
  20.     description,
  21.     footer,
  22.     color
  23. } = require('./config.js');
  24.  
  25. //
  26. // Ticket Setup Command
  27. //
  28.  
  29. const ticketTypes = ['minecraft', 'vps', 'discord', 'other'];
  30. const ids = {'minecraft': '870531441241489499','vps': '870535840193974293','discord': '870531646422650900', 'other': '871283533778391050'};
  31.  
  32. const token = process.env.TOKEN;
  33.  
  34. //
  35. // FOR REPL.IT
  36. //
  37.  
  38. // const token = process.env['TOKEN'];
  39. // const keepAlive = require('./server');
  40.  
  41. //
  42. // Is Ticket
  43. //
  44.  
  45. async function isTicket(name) {
  46.     if (name.includes("discord-")) { return true; }
  47.     if (name.includes("minecraft-")) { return true; }
  48.     if (name.includes("vps-")) {return true;}
  49.     if (name.includes("other-")) {return true;}
  50.     return false;
  51. }
  52.  
  53. //
  54. // Creation Dates
  55. //
  56.  
  57. async function deleteDateCreated(channelID) {
  58.     ticketCreationDates.delete(`ticket-${channelID}`);
  59. }
  60.  
  61. async function getDateCreated(channelID) {
  62.     return ticketCreationDates.get(`ticket-${channelID}`);
  63. }
  64.  
  65. async function setDateCreated(channelID, date) {
  66.     ticketCreationDates.set(`ticket-${channelID}`, date);
  67. }
  68.  
  69. //
  70. // Transcript
  71. //
  72.  
  73. async function createTranscript(message) {
  74.     let m = await message.channel.messages.fetch();
  75.     let id = await settings.get(`${message.guild.id}-tickettrans`);
  76.     let m2 = message.guild.channels.cache.find(c => c.id === id);
  77.     let m3 = [''];
  78.     m.forEach(element => { m3.push(`${element.author.username}: ${element.content}`); });
  79.     m3 = m3.reverse();
  80.     await m2.send(new Discord.MessageEmbed()
  81.         .setTitle(`**TICKET: ${message.channel.name}**`)
  82.         .setDescription(m3)
  83.         .setFooter("Timed Ticket Closed")
  84.         .setColor("#9700df")
  85.         .setTimestamp()
  86.     );
  87.     deleteDateCreated(message.channel.id);
  88. }
  89.  
  90. async function createTranscript2(channel) {
  91.     let m = await channel.messages.fetch();
  92.     let id = await settings.get(`${channel.guild.id}-tickettrans`);
  93.     let m2 = channel.guild.channels.cache.find(c => c.id === id);
  94.     let m3 = [''];
  95.     m.forEach(element => { m3.push(`${element.author.username}: ${element.content}`); });
  96.     m3 = m3.reverse();
  97.     await m2.send(new Discord.MessageEmbed()
  98.         .setTitle(`**TICKET: ${channel.name}**`)
  99.         .setDescription(m3)
  100.         .setFooter("Timed Ticket Closed")
  101.         .setColor("#9700df")
  102.         .setTimestamp()
  103.     );
  104.     deleteDateCreated(channel.id);
  105. }
  106.  
  107. //
  108. // Events
  109. //
  110.  
  111. async function closeTicketEvent(ticket, ticketType, user) {
  112.     console.log("Ticket Closed: " + ticket.name);
  113.     console.log("   " + ticketType);
  114.     console.log("   " + user.username);
  115.  
  116.     let logid = await settings.get(`ticket-log-channel-id`);
  117.     let logchannel = ticket.guild.channels.cache.find(c => c.id === logid);
  118.    
  119.     logchannel.send("Ticket Closed: " + ticket.name + "\n   " + ticketType + "\n   " + user.username);
  120.  
  121. }
  122.  
  123. async function createTicketEvent(ticket, ticketType, reaction, clickedReactionID, user) {
  124.     console.log("Ticket Created: " + ticket.name);
  125.     console.log("   " + ticketType);
  126.     console.log("   " + user.username);
  127.  
  128.     let logid = await settings.get(`ticket-log-channel-id`);
  129.     let logchannel = ticket.guild.channels.cache.find(c => c.id === logid);
  130.    
  131.     logchannel.send("Ticket Created: " + ticket.name + "\n   " + ticketType + "\n   " + user.username);
  132. }
  133.  
  134. //
  135. // Reload Config
  136. //
  137.  
  138. // async function reloadConfig() {
  139. //     ({
  140. //         prefix, settings,
  141. //         CustomStatus, CustomStatusType,
  142. //         Status, ticketCreationDates,
  143. //         updateTitle, updateFooter,
  144. //         updateReactionUp, updateReactionDown,
  145. //         closeTicketError, ticketCreationTable,
  146. //         title, description,
  147. //         footer, color
  148. //     } = require('./config.js'));
  149. //     client.user.setPresence({
  150. //         activity: {
  151. //             name: CustomStatus,
  152. //             type: CustomStatusType
  153. //         },
  154. //         status: Status
  155. //     });
  156. //     console.log('Reloaded!');
  157. // }
  158.  
  159. //
  160. // Change Creation Messages
  161. //
  162.  
  163. function changeCreationMessage(index, creationMessage) {
  164.     if (index != 'ticketCreationMessage' ||
  165.         index != 'ticketWelcomeMessage' ||
  166.         index != 'ticketWelcomeDescMessage' ||
  167.         index != 'ticketWelcomeColorMessage') {
  168.         return;
  169.     }
  170.  
  171.     ticketCreationTable[index] = creationMessage;
  172. }
  173.  
  174. //
  175. // Create/Delete Ticket
  176. //
  177.  
  178. async function closeTicket(channel,user) {
  179.     if (!isTicket(channel.name)) { return channel.send(closeTicketError); }
  180.     closeTicketEvent(channel,channel.name.split('-')[0], user);
  181.     await createTranscript2(channel);
  182.     deleteLastMessage(channel.id);
  183.     channel.delete();
  184. }
  185.  
  186. async function createTicket(ticketType, reaction, user, reactionclicked, catID) {
  187.     // get current ticket catergory id
  188.     let id = catID;
  189.     // creates a channel for the ticket
  190.     // you have choosen with your username on the end of the ticket name
  191.     reaction.users.remove(user);
  192.     reaction.message.guild.channels.create(`${ticketType}-${user.username}`,{
  193.         permissionOverwrites: [
  194.             {
  195.                 id: user.id,
  196.                 allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
  197.             },
  198.             {
  199.                 id: reaction.message.guild.roles.everyone,
  200.                 deny: ["VIEW_CHANNEL"]
  201.             }
  202.         ],
  203.         type: 'text'
  204.     }).then(async channel => {
  205.         let o = [
  206.             {
  207.                 id: user.id,
  208.                 allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
  209.             },
  210.             {
  211.                 id: await settings.get('support-team-role-id'),
  212.                 allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
  213.             },
  214.             {
  215.                 id: reaction.message.guild.roles.everyone,
  216.                 deny: ["VIEW_CHANNEL"]
  217.             }
  218.         ];
  219.         if (channel && id) {
  220.             await channel.setParent(id);
  221.             await channel.overwritePermissions(o);
  222.         }
  223.         let tcm = ticketCreationTable['ticketCreationMessage'];
  224.         let twm = ticketCreationTable['ticketWelcomeMessage'];
  225.         let twdm = ticketCreationTable['ticketWelcomeDescMessage'];
  226.         let twcm = ticketCreationTable['ticketWelcomeColorMessage'];
  227.         try {
  228.             const regex = /uping/i;
  229.             tcm = tcm.replace(regex, `<@${user.id}>`);
  230.             twm = twm.replace(regex, `<@${user.id}>`);
  231.             twdm = twdm.replace(regex, `<@${user.id}>`);
  232.             twcm = twcm.replace(regex, `<@${user.id}>`);
  233.         } catch (err) {
  234.             console.log(err);
  235.         }
  236.         channel.send(
  237.             tcm,
  238.             new Discord.MessageEmbed()
  239.                 .setTitle(twm)
  240.                 .setDescription(twdm)
  241.                 .setColor(twcm))
  242.         var d = new Date();
  243.         var curTime = d.getMilliseconds();
  244.         setDateCreated(channel.id, curTime);
  245.         createTicketEvent(channel,ticketType,reaction,reactionclicked,user);
  246.     })
  247. }
  248.  
  249. //
  250. // Commands Array
  251. //
  252.  
  253. let commands = {
  254.     'ticket-setup': ticketSetupCommand,
  255.     'ticket-cat': ticketCatCommand,
  256.     'ticket-logs': ticketLogsCommand,
  257.     'support-team': supportTeamCommand,
  258.     'close': closeCommand,
  259.  
  260.     'help': helpCommand,
  261.     'update': updateCommand
  262.  
  263.     // 'reload-config': reloadConfigCommand
  264. };
  265.  
  266. //
  267. // Ticket Commands
  268. //
  269.  
  270. async function ticketSetupCommand(message,command,args) {
  271.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  272.         let channel = message.mentions.channels.first();
  273.         if (!channel) return message.reply(`Usage: ${prefix}ticket-setup #channel`);
  274.         let sent = await channel.send(
  275.             new Discord.MessageEmbed()
  276.                 .setTitle(title).setDescription(description).setFooter(footer).setColor(color));
  277.         ticketTypes.forEach(type => sent.react(ids[type]));
  278.         settings.set(`${message.guild.id}-ticket`, sent.id);
  279.         message.channel.send("Ticket Setup finished!")
  280.     } else {
  281.         message.channel.send("No Permission!");
  282.     }
  283. }
  284.  
  285. async function ticketCatCommand(message,command,args) {
  286.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  287.         if (args.length > 0) {
  288.             let cat = message.guild.channels.cache.find(c => c.id === args[0]);
  289.             if (cat) {
  290.                 settings.set(`${message.guild.id}-ticketscat`, args[0]);
  291.                 message.channel.send(`Ticket Catergory Set! ${cat.name}`);
  292.             } else { message.channel.send('Something went wrong!'); }
  293.         }
  294.     } else {
  295.         message.channel.send("No Permission!");
  296.     }
  297. }
  298.  
  299. async function supportTeamCommand(message,command,args) {
  300.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  301.         if (args.length >= 1) {
  302.             settings.set('support-team-role-id', args[0]);
  303.             message.channel.send("Support team role id updated!");
  304.         } else {
  305.             return message.reply(`Usage: ${prefix}support-team roleID`);
  306.         }
  307.     }
  308. }
  309.  
  310. async function ticketLogsCommand(message,command,args) {
  311.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  312.         if (args.length >= 1) {
  313.             settings.set('ticket-log-channel-id', args[0]);
  314.             message.channel.send("Ticket logs channel id updated!");
  315.         } else {
  316.             return message.reply(`Usage: ${prefix}ticket-logs channelID`);
  317.         }
  318.     }
  319. }
  320.  
  321. async function closeCommand(message,command,args) {
  322.     if (!isTicket(message.channel.name)) { return message.channel.send(closeTicketError); }
  323.     closeTicketEvent(message.channel,message.channel.name.split('-')[0],message.author);
  324.     await createTranscript(message);
  325.     message.channel.delete();
  326. }
  327.  
  328. //
  329. // Misc Commands
  330. //
  331.  
  332. async function helpCommand(message, command, args) {
  333.     let embed = new Discord.MessageEmbed()
  334.         .setTitle("MoonNode Help")
  335.         .setDescription("")
  336.         .setFooter(message.author.username + " requested", message.author.avatarURL())
  337.         .addFields(
  338.             { name: `${prefix}help`, value: 'Shows this help menu', inline: true },
  339.             { name: `${prefix}close`, value: 'Will close the current ticket your in', inline: true },
  340.         )
  341.         .setColor(color)
  342.         .setTimestamp();
  343.    
  344.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  345.         embed.addFields(
  346.             { name: `${prefix}ticket-logs <channelID>`, value: 'Sets logs channel for tickets', inline: true },
  347.             { name: `${prefix}update <#channel> <text>`, value: 'Sends a update embed to a channel with text', inline: true },
  348.             { name: `${prefix}support-team <categoryID>`, value: 'Sets support-team role by id', inline: true },
  349.             { name: `${prefix}ticket-cat <channelID>`, value: 'Sets category for tickets', inline: true },
  350.             { name: `${prefix}ticket-setup <#channel>`, value: 'Creates a create ticket message in the mentioned channel', inline: true },
  351.         );
  352.     }
  353.    
  354.     let sent = await message.channel.send(embed);      
  355. }
  356.  
  357. async function updateCommand(message,command,args) {
  358.     if (message.member.hasPermission(['ADMINISTRATOR'])) {
  359.         if (args.length >= 2) {
  360.             let channel = message.mentions.channels.first();
  361.             let text = args.slice(1).join(" ").toString();
  362.             let sent = await channel.send(new Discord.MessageEmbed()
  363.                 .setTitle(updateTitle)
  364.                 .setDescription(text)
  365.                 .setFooter(updateFooter, message.author.avatarURL())
  366.                 .setColor(color)
  367.                 .setTimestamp()
  368.             );                
  369.             sent.react(updateReactionUp);
  370.             sent.react(updateReactionDown);
  371.             settings.set(`${message.guild.id}-ticket`, sent.id);
  372.             message.channel.send("Update Sent!")
  373.         } else {
  374.             return message.reply(`Usage: ${prefix}update #channel <text>`);
  375.         }
  376.     } else {
  377.         message.channel.send("No Permission!");
  378.     }
  379. }
  380.  
  381. // async function reloadConfigCommand(message,command,args) {
  382. //     if (message.member.hasPermission(['MANAGE_CHANNELS'])) {
  383. //         reloadConfig();
  384. //         message.channel.send("Config Reloaded!");
  385. //     } else {
  386. //         message.channel.send("No Permission!");
  387. //     }
  388. // }
  389.  
  390. //
  391. // Bot Ready
  392. //
  393.  
  394. client.on('ready', async () => {
  395.     client.user.setPresence({
  396.         activity: {
  397.             name: CustomStatus,
  398.             type: CustomStatusType
  399.         },
  400.         status: Status
  401.     });
  402.     console.log('MOONNODE Ticketing & Update logger Bot is up and running!');
  403. });
  404.  
  405. //
  406. // Bot Commands
  407. //
  408.  
  409. client.on('message', async message => {
  410.     if (message.author.bot) return; // make sure that bots cannot use commands
  411.     if (message.content.indexOf(prefix) !== 0) return; // make sure the command contains the prefix
  412.     const args = message.content.slice(prefix.length).trim().split(/ +/g);
  413.     const command = args.shift().toLowerCase();
  414.     if (commands[command] == null) {
  415.         if (unknownCommand) {
  416.             if (message.content === prefix) { return; }
  417.             if (command.includes(prefix)) { return; }
  418.             if (message.content === ".did you know this can be disabled in config.js") { message.reply('yes'); return; }
  419.             message.channel.send(unknownCommandMessage);
  420.         }
  421.         return;
  422.     }
  423.     commands[command](message,command,args);
  424. });
  425.  
  426. //
  427. // Reactions
  428. //
  429.  
  430. client.on('messageReactionAdd', async (reaction, user) => {
  431.     if (user.partial) await user.fetch();
  432.     if (reaction.partial) await reaction.fetch();
  433.     if (reaction.message.partial) await reaction.message.fetch();
  434.     if (user.bot) return;
  435.    
  436.     // Check if react to open ticket exists
  437.     // if it doesnt exist it will skip everything
  438.     let reactID = await settings.get(`${reaction.message.guild.id}-ticket`);
  439.     if (!reactID) return;
  440.    
  441.     let cat = await settings.get(`${reaction.message.guild.id}-ticketscat`);
  442.     // check if the message id is the id of the react to open ticket message
  443.     // everything will be skipped if its not true
  444.     if (reaction.message.id == reactID) {
  445.         // create a const emojid
  446.         const emojid = reaction.emoji.id;
  447.        
  448.         // check for reaction ids
  449.         switch (emojid) {
  450.             case "870535840193974293":
  451.                 // if reaction id is server reaction id
  452.                 // create a vps ticket
  453.                 createTicket("vps", reaction, user, emojid, cat);
  454.                 break;
  455.             case "870531441241489499":
  456.                 // if reaction id is minecraft reaction id
  457.                 // create a minecraft ticket
  458.                 createTicket("minecraft", reaction, user, emojid, cat);
  459.                 break;
  460.             case "870531646422650900":
  461.                 // if reaction id is discord reaction id
  462.                 // create a discord ticket
  463.                 createTicket("discord", reaction, user, emojid, cat);
  464.                 break;
  465.             case "871283533778391050":
  466.                 // if reaction id is other reaction id
  467.                 // create a other ticket
  468.                 createTicket("other", reaction, user, emojid, cat);
  469.                 break;
  470.             default:
  471.                 // if (ticketTypes.includes(reaction.emoji.name) && ids.includes(emojid)) {
  472.                 //     // if reaction id is in the list ids and reaction name is in the ticketTypes list
  473.                 //     // create a default ticket with the prefix "default-%username%"
  474.                 //     createTicket("default", reaction, user, emojid, cat);
  475.                 //     break;
  476.                 // }
  477.                 break;
  478.         }
  479.     }
  480. });
  481.  
  482. //
  483. // FOR REPL.IT
  484. //
  485.  
  486. // keepAlive();
  487.  
  488. //
  489. // Login
  490. //
  491.  
  492. client.login(token);
RAW Paste Data