Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2.  
  3. const commands = JSON.parse(fs.readFileSync('./Storage/commands.json', 'utf8'));
  4.  
  5. const prefix = require('../app.js');
  6.  
  7. exports.run = async (bot, message, args, cmd, func) => {
  8.     if (message === prefix + 'HELP') { // If they only type this, lets ONLY show the commands for regular users
  9.  
  10.         // Start of the embed
  11.         const embed = new Discord.RichEmbed()
  12.             .setColor(0x1D82B6); // You can set this color to whatever you want.
  13.  
  14.         // Variables
  15.         let commandsFound = 0; // We also want to tell them how many commands there are for that specific group.
  16.  
  17.         // Lets create the for loop that loops through the commands
  18.         for (var cmd in commands) { // We should start creating the commands json first.
  19.  
  20.             // Checks if the group is "users" - and replace type with group
  21.             if (commands[cmd].group.toUpperCase() === 'USER') {
  22.                 // Lets also count commandsFound + 1 every time it finds a command in the group
  23.                 commandsFound++;
  24.                 // Lets add the command field to the embed
  25.                 embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${prefix + commands[cmd].usage}`); // This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
  26.             }
  27.  
  28.         }
  29.  
  30.         // Add some more to the embed - we need to move that out of the for loop.
  31.         embed.setFooter(`Currently showing user commands. To view another group do ${prefix}help [group / command]`);
  32.         embed.setDescription(`**${commandsFound} commands found** - <> means required, [] means optional`);
  33.  
  34.         // We can output it two ways. 1 - Send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
  35.         message.author.send({embed})
  36.         // Post in chat they sent to DMs
  37.         message.channel.send({embed: {
  38.             color: 0x1D82B6,
  39.             description: `**Check your DMs ${message.author}!**`
  40.         }})
  41.  
  42.         // Let's test this! - We have a few bugs first though.
  43.         // Turns out you can only use the word embed to define embeds.
  44.  
  45.     } else if (args.join(" ").toUpperCase() === 'GROUPS') {
  46.  
  47.         // Variables
  48.         let groups = '';
  49.  
  50.         for (var cmd in commands) {
  51.             if (!groups.includes(commands[cmd].group)) {
  52.                 groups += `${commands[cmd].group}\n`
  53.             }
  54.         }
  55.  
  56.         message.channel.send({embed: {
  57.             description:`**${groups}**`,
  58.             title:"Groups",
  59.             color: 0x1D82B6
  60.         }})
  61.  
  62.         return; // Testing!
  63.  
  64.  
  65.     } else {
  66.         // Now, lets do something when they do ~help [cmd / group] - You can use copy and paste for a lot of this part.
  67.  
  68.         // Variables
  69.         let groupFound = '';
  70.  
  71.         for (var cmd in commands) { // This will see if their is a group named after what the user entered.
  72.  
  73.             if (args.join(" ").trim().toUpperCase() === commands[cmd].group.toUpperCase()) {
  74.                 groupFound = commands[cmd].group.toUpperCase(); // Lets set the ground found, then break out of the loop.
  75.                 break;
  76.             }
  77.  
  78.         }
  79.  
  80.         if (groupFound != '') { // If a group is found, run this statement.
  81.  
  82.             // Start of the embed
  83.             const embed = new Discord.RichEmbed()
  84.                 .setColor(0x1D82B6) // You can set this color to whatever you want.
  85.  
  86.             // Variables
  87.             let commandsFound = 0; // We also want to tell them how many commands there are for that specific group.
  88.  
  89.  
  90.             for (var cmd in commands) { // We can use copy and paste again
  91.  
  92.                 // Checks if the group is "users" - and replace type with group
  93.                 if (commands[cmd].group.toUpperCase() === groupFound) {
  94.                     // Lets also count commandsFound + 1 every time it finds a command in the group
  95.                     commandsFound++
  96.                     // Lets add the command field to the embed
  97.                     embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${prefix + commands[cmd].usage}`); // This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
  98.                 }
  99.  
  100.             }
  101.  
  102.             // Add some more to the embed - we need to move that out of the for loop.
  103.             embed.setFooter(`Currently showing ${groupFound} commands. To view another group do ${prefix}help [group / command]`)
  104.             embed.setDescription(`**${commandsFound} commands found** - <> means required, [] means optional`)
  105.  
  106.             // We can output it two ways. 1 - Send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
  107.             message.author.send({embed})
  108.             // Post in chat they sent to DMs
  109.             message.channel.send({embed: {
  110.                 color: 0x1D82B6,
  111.                 description: `**Check your DMs ${message.author}!**`
  112.             }})
  113.  
  114.             // Make sure you copy and paste into the right place, lets test it now!
  115.             return; // We want to make sure we return so it doesnt run the rest of the script after it finds a group! Lets test it!
  116.  
  117.             // Now lets show groups.
  118.         }
  119.  
  120.         // Although, if a group is not found, lets see if it is a command
  121.  
  122.         // Variables
  123.         let commandFound = '';
  124.         let commandDesc = '';
  125.         let commandUsage = '';
  126.         let commandGroup = '';
  127.  
  128.         for (var cmd in commands) { // Copy and paste
  129.  
  130.             if (args.join(" ").trim().toUpperCase() === commands[cmd].name.toUpperCase()) {
  131.                 commandFound = commands[cmd].name; // Lets change this so it doesnt make it go uppcase
  132.                 commandDesc = commands[cmd].desc;
  133.                 commandUsage = commands[cmd].usage;
  134.                 commandGroup = commands[cmd].group;
  135.                 break;
  136.             }
  137.  
  138.         }
  139.  
  140.         // Lets post in chat if nothing is found!
  141.         if (commandFound === '') {
  142.             message.channel.send({embed: {
  143.                 description:`**No group or command found titled \`${args.join(" ")}\`**`,
  144.                 color: 0x1D82B6,
  145.             }})
  146.  
  147.         }
  148.  
  149.         // Since this one is smaller, lets send the embed differently.
  150.         message.channel.send({embed: {
  151.             title:'<> means required, [] means optional',
  152.             color: 0x1D82B6,
  153.             fields: [{
  154.                 name:commandFound,
  155.                 value:`**Description:** ${commandDesc}\n**Usage:** ${commandUsage}\n**Group:** ${commandGroup}`
  156.             }]
  157.         }})
  158.  
  159.         return; // We want to return here so that it doesnt run the rest of the script also.
  160.  
  161.     }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement