{"size": 975, "ext": "js", "max_stars_repo_path": "src/utils/CommandUtils.js", "max_stars_repo_name": "Gorillas-Team/Kong", "max_stars_repo_stars_event_min_datetime": "2020-05-10T23:43:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-12T13:24:43.000Z", "max_issues_repo_path": "src/utils/CommandUtils.js", "max_issues_repo_name": "Gorillas-Team/Kong", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/CommandUtils.js", "max_forks_repo_name": "Gorillas-Team/Kong", "max_forks_repo_forks_event_min_datetime": "2020-04-30T01:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-31T06:14:01.000Z"}
{"max_stars_count": 7, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 23.7804878049, "max_line_length": 66, "alphanum_fraction": 0.6112820513}
const { prefixes } = require('../../config')

const CodeUtils = require('./CodeUtils')

/**
 * @name CommandUtils
 * @class
 */
class CommandUtils {
  /**
   * @param {import('eris').Message} message
   * @returns {string}
   */
  static getPrefix (message) {
    const toLowerCase = str => str.toLowerCase()
    const startsWith = str => prefix => str.startsWith(prefix)

    const content = toLowerCase(message.content)
    const pipe = CodeUtils.pipe(toLowerCase, startsWith(content))

    return prefixes.find(pipe)
  }

  /**
   * @param {string} content
   * @param {string} prefix
   * @returns {string[]}
   */
  static resolveArgs (content, prefix) {
    const slice = str => str.slice(prefix.length)
    const trim = str => str.trim()

    const split = str => str.split(/ +/g)
    const filter = str => str.filter(Boolean)

    return CodeUtils.pipe(slice, trim, split, filter)(content)
  }
}

module.exports = CommandUtils
