Guest User

GA

a guest
Apr 12th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*jshint esversion: 6*/
  2. const commando = require('discord.js-commando');
  3. const db = require('../../config/db');
  4. const skills = require('../../funcs/tradeskills');
  5.  
  6. module.exports = class Farming extends commando.Command {
  7.   constructor (client) {
  8.     super(client, {
  9.       name: 'gather',
  10.       aliases: ['get'],
  11.       group: 'actions',
  12.       memberName: 'gather',
  13.       hasPermissions: ['READ_MESSAGE_HISTORY'],
  14.       description: 'gathering actions',
  15.       guildOnly: true,
  16.       args: [
  17.       {
  18.         key: 'what',
  19.         prompt: 'What do you want to gather? List: Farming, herbology, hunting, lumber, mining, stone.',
  20.         type: 'string',
  21.       },
  22.       {
  23.         key: 'type',
  24.         prompt: 'What to gather from selected tradeskill?',
  25.         type: 'string',
  26.       },
  27.       {
  28.         key: 'amount',
  29.         prompt: 'How many actions before a report is sent. 10-1000',
  30.         type: 'integer',
  31.       },
  32.     ],
  33.     });
  34.   }
  35.  
  36.   run(msg, { what, type, amount }) {
  37.     // asign user
  38.     var userData = msg.member.user;
  39.  
  40.     // Check for channel
  41.     if (msg.channel.name != 'tradeskills-1' && msg.channel.name != 'tradeskills-2') {
  42.       return msg.reply('Please use the tradeskill channels for this command.');
  43.     }
  44.  
  45.     // Battle report check
  46.     if (amount <= 9 || amount >= 1001) {
  47.       return msg.reply('The action report amount must be 10-1000, please try again.');
  48.     }
  49.  
  50.     // Check if registered
  51.     var userSQL = 'SELECT * FROM users_meta WHERE userid = ?';
  52.     db.query(userSQL, userData.id, (err, row) => {
  53.       if (row[0] === undefined) {
  54.         return msg.reply('You are not registered!');
  55.       } else {
  56.         // set game data for user - if already exists, update
  57.         userData.game = row[0];
  58.  
  59.  
  60.         // Set type to lowercase
  61.         what = what.toLowerCase();
  62.         type = type.toLowerCase();
  63.         var expertise;
  64.         var sendMsg;
  65.  
  66.         var stats = {
  67.           exp: 0,
  68.           actions: amount,
  69.           yield: 0,
  70.         };
  71.  
  72.         // Farming Block
  73.         if (what === 'farming' || what === 'food') {
  74.           sendMsg = 'You are now farming: ' + type;
  75.           expertise = Math.floor((userData.game.farming_expgain +
  76.             userData.game.farming_yield + userData.game.farming_double) / 2);
  77.           switch (type) {
  78.             case 'wheat':
  79.               msg.reply(sendMsg);
  80.               autos(msg, what, type, amount, userData, stats);
  81.               break;
  82.             case 'carrot':
  83.               if (expertise <= 9) {
  84.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  85.               } else {
  86.                 msg.reply(sendMsg);
  87.                 autos(msg, what, type, amount, userData, stats);
  88.               }
  89.  
  90.               break;
  91.             case 'tomato':
  92.               if (expertise <= 24) {
  93.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  94.               } else {
  95.                 msg.reply(sendMsg);
  96.                 autos(msg, what, type, amount, userData, stats);
  97.               }
  98.  
  99.               break;
  100.             case 'cucumber':
  101.               if (expertise <= 39) {
  102.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  103.               } else {
  104.                 msg.reply(sendMsg);
  105.                 autos(msg, what, type, amount, userData, stats);
  106.               }
  107.  
  108.               break;
  109.             case 'potato':
  110.               if (expertise <= 59) {
  111.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  112.               } else {
  113.                 msg.reply(sendMsg);
  114.                 autos(msg, what, type, amount, userData, stats);
  115.               }
  116.  
  117.               break;
  118.             default:
  119.               return msg.reply('You did not produce the correct arguments.');
  120.           }
  121.  
  122.           // Herb Block
  123.         } else if (what === 'herbology' || what === 'herbs') {
  124.           sendMsg = 'You are now gathering: ' + type;
  125.           expertise = Math.floor((userData.game.herbology_expgain +
  126.             userData.game.herbology_yield + userData.game.herbology_double) / 2);
  127.           switch (type) {
  128.             case 'basil':
  129.               msg.reply(sendMsg);
  130.               autos(msg, what, type, amount, userData, stats);
  131.               break;
  132.             case 'cilantro':
  133.               if (expertise <= 9) {
  134.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  135.               } else {
  136.                 msg.reply(sendMsg);
  137.                 autos(msg, what, type, amount, userData, stats);
  138.               }
  139.  
  140.               break;
  141.             case 'dill':
  142.               if (expertise <= 24) {
  143.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  144.               } else {
  145.                 msg.reply(sendMsg);
  146.                 autos(msg, what, type, amount, userData, stats);
  147.               }
  148.  
  149.               break;
  150.             case 'thyme':
  151.               if (expertise <= 39) {
  152.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  153.               } else {
  154.                 msg.reply(sendMsg);
  155.                 autos(msg, what, type, amount, userData, stats);
  156.               }
  157.  
  158.               break;
  159.             case 'garlic':
  160.               if (expertise <= 59) {
  161.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  162.               } else {
  163.                 msg.reply(sendMsg);
  164.                 autos(msg, what, type, amount, userData, stats);
  165.               }
  166.  
  167.               break;
  168.             default:
  169.               return msg.reply('You did not produce the correct arguments.');
  170.           }
  171.  
  172.           // start hunting block
  173.         } else if (what === 'hunting' || what === 'hunt') {
  174.           sendMsg = 'You are now hunting: ' + type;
  175.           expertise = Math.floor((userData.game.hunting_expgain +
  176.             userData.game.hunting_yield + userData.game.hunting_double) / 2);
  177.           switch (type) {
  178.             case 'rabbit':
  179.               msg.reply(sendMsg);
  180.               autos(msg, what, type, amount, userData, stats);
  181.               break;
  182.             case 'wolf':
  183.               if (expertise <= 9) {
  184.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  185.               } else {
  186.                 msg.reply(sendMsg);
  187.                 autos(msg, what, type, amount, userData, stats);
  188.               }
  189.  
  190.               break;
  191.             case 'deer':
  192.               if (expertise <= 24) {
  193.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  194.               } else {
  195.                 msg.reply(sendMsg);
  196.                 autos(msg, what, type, amount, userData, stats);
  197.               }
  198.  
  199.               break;
  200.             case 'bear':
  201.               if (expertise <= 39) {
  202.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  203.               } else {
  204.                 msg.reply(sendMsg);
  205.                 autos(msg, what, type, amount, userData, stats);
  206.               }
  207.  
  208.               break;
  209.             case 'dragon':
  210.               if (expertise <= 59) {
  211.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  212.               } else {
  213.                 msg.reply(sendMsg);
  214.                 autos(msg, what, type, amount, userData, stats);
  215.               }
  216.  
  217.               break;
  218.             default:
  219.               return msg.reply('You did not produce the correct arguments.');
  220.           }
  221.  
  222.           // start lumber block
  223.         } else if (what === 'lumber' || what === 'wood') {
  224.           sendMsg = 'You are now chopping: ' + type;
  225.           expertise = Math.floor((userData.game.lumber_expgain +
  226.             userData.game.lumber_yield + userData.game.lumber_double) / 2);
  227.           switch (type) {
  228.             case 'oak':
  229.               msg.reply(sendMsg);
  230.               autos(msg, what, type, amount, userData, stats);
  231.               break;
  232.             case 'birch':
  233.               if (expertise <= 9) {
  234.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  235.               } else {
  236.                 msg.reply(sendMsg);
  237.                 autos(msg, what, type, amount, userData, stats);
  238.               }
  239.  
  240.               break;
  241.             case 'cypruss':
  242.               if (expertise <= 24) {
  243.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  244.               } else {
  245.                 msg.reply(sendMsg);
  246.                 autos(msg, what, type, amount, userData, stats);
  247.               }
  248.  
  249.               break;
  250.             case 'pine':
  251.               if (expertise <= 39) {
  252.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  253.               } else {
  254.                 msg.reply(sendMsg);
  255.                 autos(msg, what, type, amount, userData, stats);
  256.               }
  257.  
  258.               break;
  259.             case 'spruce':
  260.               if (expertise <= 59) {
  261.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  262.               } else {
  263.                 msg.reply(sendMsg);
  264.                 autos(msg, what, type, amount, userData, stats);
  265.               }
  266.  
  267.               break;
  268.             default:
  269.               return msg.reply('You did not produce the correct arguments.');
  270.           }
  271.  
  272.           // start mining block
  273.         } else if (what === 'mining' || what === 'mine') {
  274.           sendMsg = 'You are now mining: ' + type;
  275.           expertise = Math.floor((userData.game.mining_expgain +
  276.             userData.game.mining_yield + userData.game.mining_double) / 2);
  277.           switch (type) {
  278.             case 'copper':
  279.               msg.reply(sendMsg);
  280.               autos(msg, what, type, amount, userData, stats);
  281.               break;
  282.             case 'iron':
  283.               if (expertise <= 9) {
  284.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  285.               } else {
  286.                 msg.reply(sendMsg);
  287.                 autos(msg, what, type, amount, userData, stats);
  288.               }
  289.  
  290.               break;
  291.             case 'silver':
  292.               if (expertise <= 24) {
  293.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  294.               } else {
  295.                 msg.reply(sendMsg);
  296.                 autos(msg, what, type, amount, userData, stats);
  297.               }
  298.  
  299.               break;
  300.             case 'malachite':
  301.               if (expertise <= 39) {
  302.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  303.               } else {
  304.                 msg.reply(sendMsg);
  305.                 autos(msg, what, type, amount, userData, stats);
  306.               }
  307.  
  308.               break;
  309.             case 'cobalt':
  310.               if (expertise <= 59) {
  311.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  312.               } else {
  313.                 msg.reply(sendMsg);
  314.                 autos(msg, what, type, amount, userData, stats);
  315.               }
  316.  
  317.               break;
  318.             default:
  319.               return msg.reply('You did not produce the correct arguments.');
  320.           }
  321.  
  322.           // start stone block
  323.         } else if (what === 'stone') {
  324.           sendMsg = 'You are now excavating: ' + type;
  325.           expertise = Math.floor((userData.game.stone_expgain +
  326.             userData.game.stone_yield + userData.game.stone_double) / 2);
  327.           switch (type) {
  328.             case 'basalt':
  329.               msg.reply(sendMsg);
  330.               autos(msg, what, type, amount, userData, stats);
  331.               break;
  332.             case 'granite':
  333.               if (expertise <= 9) {
  334.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 10 or more.');
  335.               } else {
  336.                 msg.reply(sendMsg);
  337.                 autos(msg, what, type, amount, userData, stats);
  338.               }
  339.  
  340.               break;
  341.             case 'quartz':
  342.               if (expertise <= 24) {
  343.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 25 or more.');
  344.               } else {
  345.                 msg.reply(sendMsg);
  346.                 autos(msg, what, type, amount, userData, stats);
  347.               }
  348.  
  349.               break;
  350.             case 'marble':
  351.               if (expertise <= 39) {
  352.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 40 or more.');
  353.               } else {
  354.                 msg.reply(sendMsg);
  355.                 autos(msg, what, type, amount, userData, stats);
  356.               }
  357.  
  358.               break;
  359.             case 'obsidian':
  360.               if (expertise <= 59) {
  361.                 return msg.reply('You do not meet the expertise requirement. You have ' + expertise + ' but need 60 or more.');
  362.               } else {
  363.                 msg.reply(sendMsg);
  364.                 autos(msg, what, type, amount, userData, stats);
  365.               }
  366.  
  367.               break;
  368.             default:
  369.               return msg.reply('You did not produce the correct arguments.');
  370.           }
  371.         } else {
  372.           return msg.reply('You did not produce the correct arguments.');
  373.         }
  374.       }
  375.  
  376.       function autos(msg, what, type, amount, userData, stats) {
  377.         if (userData.interval === undefined || userData.interval === false) {
  378.           userData.interval = setInterval(() => {
  379.             skills.tradeSkill(msg, what, type, amount, userData, stats);
  380.             userData.intervalTime = Date.now();
  381.           }, 6000);
  382.           skills.tradeSkill(msg, what, type, amount, userData, stats);
  383.         } else {
  384.           var timing = userData.intervalTime + 5900 - Date.now();
  385.           if (timing < 0) {
  386.             timing = 0;
  387.           }
  388.  
  389.           // Waits for current to end, then updates it.
  390.           setTimeout(() => {
  391.             clearInterval(userData.interval);
  392.             userData.interval = setInterval(() => {
  393.               skills.tradeSkill(msg, what, type, amount, userData, stats);
  394.               userData.intervalTime = Date.now();
  395.             }, 6000);
  396.             skills.tradeSkill(msg, what, type, amount, userData, stats);
  397.           }, timing);
  398.         }
  399.       }
  400.  
  401.     });
  402.  
  403.   }
  404. };
Advertisement
Add Comment
Please, Sign In to add comment