SHARE
TWEET

Untitled

a guest Apr 26th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Player Input
  2. client.on('message', message => {
  3.  
  4.     let userID = message.author.id;
  5.     let channelID = message.channel.id;
  6.     let content = message.content;
  7.     if (content.substring(0, 1) === '!') {
  8.         let args = content.substring(1).split(' ');
  9.         let cmd = args[0];
  10.         args = args.splice(1);
  11.         switch (cmd) {
  12.             case 'unsubscribe':
  13.                 unsubscribeFromReminders(channelID);
  14.                 break;
  15.             case 'subscribe':
  16.                 subscribeToReminders(channelID);
  17.                 break;
  18.             case 'pearme':
  19.                 sendPearToChannel(channelID);
  20.                 break;
  21.             case 'tree':
  22.                 //changed args[0] to args
  23.                 performTreeOps(channelID, userID, args);
  24.                 break;
  25.             case 'clean':
  26.                 deleteMessagesFromChannel(channelID);
  27.                 break;
  28.             case 'eatpears':
  29.                 playFileInVoiceChannel(I_EAT_PEARS_MP3, message.member.voice.channel);
  30.                 break;
  31.             case 'shoutout':
  32.                 playFileInVoiceChannel(SHOUTOUT_MP3, message.member.voice.channel);
  33.                 break;
  34.         }
  35.     }
  36. });
  37.  
  38. //Input Switch
  39. function performTreeOps(channelID, userID, subfunction) {
  40.     switch (subfunction[0]) {
  41.         case "plant":
  42.             plantTree(channelID, userID);
  43.             break;
  44.         case "water":
  45.             waterTree(channelID, userID);
  46.             break;
  47.         case "harvest":
  48.             if(subfunction.length >= 2){
  49.                 harvestAmount(channelID, userID, subfunction[1].parseInt);
  50.                 break;
  51.             }
  52.             else{
  53.                 harvestTree(channelID, userID);
  54.                 break;
  55.             }
  56.         case "status":
  57.             sendTreeStatus(channelID, userID);
  58.             break;
  59.         case "count":
  60.             sendPearCount(channelID, userID);
  61.             break;
  62.         case "leader":
  63.             sendPearLeaderboard(channelID);
  64.             break;
  65.         default:
  66.             sendMessageToChannel(channelID, TREE_HELPER_MESSAGE);
  67.             break;
  68.     }
  69. }
  70.  
  71. //The Function
  72. function harvestAmount(channelID, userID, amount) {
  73.     let tree = trees[userID];
  74.     if (tree !== undefined) {
  75.         let pearsHarvested = tree.harvestAmount(amount);
  76.         tree.channelPlantedIn = channelID;
  77.         addPearsToCount(userID, pearsHarvested);
  78.         putIntoTable(TREE_TABLE_NAME, tree.toItem());
  79.         if(pearsHarvested != 0){
  80.             sendMessageToChannel(channelID, getUsername(userID) + " harvested " + pearsHarvested + " pears!\n"
  81.                 + getUsername(userID) + ": " + (pearCounts[userID] - pearsHarvested) + " + " + pearsHarvested + " = "
  82.                 + pearCounts[userID])
  83.         }
  84.         else{
  85.             sendMessageToChannel(channelID, "You can't harvest that amount! Try \"!tree harvest\"");
  86.         }
  87.     } else {
  88.         sendMessageToChannel(channelID, "You don't have a tree to harvest! Try \"!tree plant\"");
  89.     }
  90. }
  91.  
  92. //In tree class call
  93. harvestAmount(amount){
  94.         //Return the amount of pears successfully harvested
  95.         if (amount > this.pears || amount <= 0){
  96.             return 0;
  97.         }
  98.         else{
  99.             this.pears -= amount;
  100.             return amount;
  101.         }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top