Overview

This command adds a members portfolio website to the #member-portfolios channel

Code

const security = require('../security')
const portfolioService = require('../services/portfolioService')

//Help Text enables the bot to show this command as part of !fsc help command
const helpText = `
  Command: portfolio
  Description: Used to update the managed portfolios message for the server. The managed message is updated automatically by fsc.bot.
  Subcommands: 
    - Subcommand: add
      Description: Allows a member to add or update their portfolio item. Each member is allowed one entry.
      Examples:
        - Input: !fsc portfolio add <https://brianmorrison.me>
          Output: None directly. Will add or update the members portfolio site in the list.
    - Subcommand: init
      Description: Allows admins to initialize a new managed portfolios message in the current channel.
      Examples:
        - Input: !fsc portfolio init
          Output: **Member Portfolios:** (This is the start of the managed message.)
`

module.exports = {
  command: 'portfolio',
  isEnabled: true,
  helpText,
  shouldCleanup: true,
  fn: async msg => {
    let args = msg.content.split(' ')

		//This is for members to add their portfolios to the message
    if(args[2] === 'add') {
      if(args.length < 4) {
        //Checks if a member has provided their portfolio URL
        msg.author.send("Please provide a url to add to the portfolio list. Format should be `!fsc portfolio add <https://brianmorrison.me`>");
      } else {
        //Calls updatePortfolios service which updates the message to include the 
				//Members portfolio
        await portfolioService.updatePortfolios(msg, msg.author.username, args[3])
      }
    }
    
    //This is for admins/mods to create a new message in the channel
    if(args[2] === 'init') {
      //Checks if the user is a mod or not
      let isMod = await security.isMod(msg, msg.author.id)
      if(isMod) {
        //Initialises a new portfolio message
        await portfolioService.initMessage(msg);
      } else {
        msg.author.send("You are not permitted to use the '!fsc portfolio init' command..")
      }
    }
  }
}