Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Player Input
- client.on('message', message => {
- let userID = message.author.id;
- let channelID = message.channel.id;
- let content = message.content;
- if (content.substring(0, 1) === '!') {
- let args = content.substring(1).split(' ');
- let cmd = args[0];
- args = args.splice(1);
- switch (cmd) {
- case 'unsubscribe':
- unsubscribeFromReminders(channelID);
- break;
- case 'subscribe':
- subscribeToReminders(channelID);
- break;
- case 'pearme':
- sendPearToChannel(channelID);
- break;
- case 'tree':
- //changed args[0] to args
- performTreeOps(channelID, userID, args);
- break;
- case 'clean':
- deleteMessagesFromChannel(channelID);
- break;
- case 'eatpears':
- playFileInVoiceChannel(I_EAT_PEARS_MP3, message.member.voice.channel);
- break;
- case 'shoutout':
- playFileInVoiceChannel(SHOUTOUT_MP3, message.member.voice.channel);
- break;
- }
- }
- });
- //Input Switch
- function performTreeOps(channelID, userID, subfunction) {
- switch (subfunction[0]) {
- case "plant":
- plantTree(channelID, userID);
- break;
- case "water":
- waterTree(channelID, userID);
- break;
- case "harvest":
- if(subfunction.length >= 2){
- harvestAmount(channelID, userID, subfunction[1].parseInt);
- break;
- }
- else{
- harvestTree(channelID, userID);
- break;
- }
- case "status":
- sendTreeStatus(channelID, userID);
- break;
- case "count":
- sendPearCount(channelID, userID);
- break;
- case "leader":
- sendPearLeaderboard(channelID);
- break;
- default:
- sendMessageToChannel(channelID, TREE_HELPER_MESSAGE);
- break;
- }
- }
- //The Function
- function harvestAmount(channelID, userID, amount) {
- let tree = trees[userID];
- if (tree !== undefined) {
- let pearsHarvested = tree.harvestAmount(amount);
- tree.channelPlantedIn = channelID;
- addPearsToCount(userID, pearsHarvested);
- putIntoTable(TREE_TABLE_NAME, tree.toItem());
- if(pearsHarvested != 0){
- sendMessageToChannel(channelID, getUsername(userID) + " harvested " + pearsHarvested + " pears!\n"
- + getUsername(userID) + ": " + (pearCounts[userID] - pearsHarvested) + " + " + pearsHarvested + " = "
- + pearCounts[userID])
- }
- else{
- sendMessageToChannel(channelID, "You can't harvest that amount! Try \"!tree harvest\"");
- }
- } else {
- sendMessageToChannel(channelID, "You don't have a tree to harvest! Try \"!tree plant\"");
- }
- }
- //In tree class call
- harvestAmount(amount){
- //Return the amount of pears successfully harvested
- if (amount > this.pears || amount <= 0){
- return 0;
- }
- else{
- this.pears -= amount;
- return amount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement