<commit_before>//
// Copyright (c) 2016-2017 DrSmugleaf
//

"use strict"
const commando = require("discord.js-commando")
const DB = require("../../util/db.js")
const db = new DB()
const Quote = require("./base/quote")
const responses = require("../../util/constants").responses.QUOTE
const winston = require("winston")

module.exports = class QuoteCommand extends commando.Command {
  constructor(client) {
    super(client, {
      name: "quote",
      aliases: ["quote"],
      group: "misc",
      memberName: "quote",
      description: "Add, remove or get a quote from the list.",
      examples: ["quote", "quote 25", "quote add Hello World", "quote del 25"],
      guildOnly: true,
      throttling: {
        usages: 2,
        duration: 3
      },
      args: [
        {
          key: "mode",
          prompt: "Add, delete or get a quote",
          type: "string",
          default: "get"
        },
        {
          key: "id_text",
          label: "ID or text",
          prompt: "ID of the quote to add or delete or text of the quote to add to the list of quotes",
          type: "string",
          default: ""
        }
      ]
    })

    this.client.once("dbReady", async () => {
      const quote = new Quote(this.client)
      await quote.init()
      this.quote = quote
    })
  }

  async run(msg, args) {
    const mode = args.id_text == "" ? "get" : args.mode
    const id = args.mode == "" ?
      null : args.id_text == "" ?
      parseInt(args.mode, 10) : parseInt(args.id_text, 10)
    const text = args.id_text == "" ? args.mode : args.id_text
    var parameters

    switch (mode) {
    case "add":
    case "put":
      if(!text) return msg.reply(responses.EMPTY[msg.language])

      parameters = { text: text, submitter: msg.author.id, guild: msg.guild.id }
      this.quote.add(parameters).then(() => {
        return msg.reply(responses.ADDED[msg.language])
      }).catch((e) => {
        winston.info(e)
        return msg.reply(responses.ERROR[msg.language])
      })
      break
    case "del":
    case "delete":
    case "rem":
    case "remove":
      parameters = { id: id, guild: msg.guild.id }
      if(!this.quote.has(parameters)) return msg.reply(responses.MISSING[msg.language])
      if(!this.quote.get(parameters).submitter === msg.author.id) {
        return msg.reply(responses.NO_PERMISSION)
      }

      this.quote.delete(parameters).then(() => {
        return msg.reply(responses.REMOVED[msg.language](id))
      }).catch(() => {
        return msg.reply(responses.ERROR[msg.language])
      })
      break
    case "find":
    case "get": {
      parameters = { id: id, guild: msg.guild.id }
      if(id && !this.quote.has(parameters)) return msg.reply(responses.MISSING[msg.language])

      const quote = this.quote.get(parameters)
      msg.reply(responses.GET[msg.language](quote.id, quote.text))
      break
    }
    default:
      return msg.reply(responses.NO_MODE[msg.language](mode))
    }
  }
}
<commit_msg>Simplified quote command argument parsing<commit_after>//
// Copyright (c) 2016-2017 DrSmugleaf
//

"use strict"
const commando = require("discord.js-commando")
const DB = require("../../util/db.js")
const db = new DB()
const Quote = require("./base/quote")
const responses = require("../../util/constants").responses.QUOTE
const winston = require("winston")

module.exports = class QuoteCommand extends commando.Command {
  constructor(client) {
    super(client, {
      name: "quote",
      aliases: ["quote"],
      group: "misc",
      memberName: "quote",
      description: "Add, remove or get a quote from the list.",
      examples: ["quote", "quote 25", "quote add Hello World", "quote del 25"],
      guildOnly: true,
      throttling: {
        usages: 2,
        duration: 3
      },
      args: [
        {
          key: "mode",
          prompt: "Add, delete or get a quote",
          type: "string",
          default: "",
          parse: (mode) => {
            if(["add", "put"].includes(mode)) return "add"
            if(["del", "delete", "rem", "remove"].includes(mode)) return "delete"
            if(["find", "get"].includes(mode)) return "get"
            return "get"
          }
        },
        {
          key: "id_text",
          label: "ID or text",
          prompt: "ID of the quote to add or delete or text of the quote to add to the list of quotes",
          type: "string",
          default: ""
        }
      ]
    })

    this.client.once("dbReady", async () => {
      const quote = new Quote(this.client)
      await quote.init()
      this.quote = quote
    })
  }

  async run(msg, args) {
    const mode = this.args[0].parse(args.mode)
    const id = parseInt(args.mode, 10) || parseInt(args.id_text, 10) || null
    const text = args.id_text
    var parameters

    switch (mode) {
    case "add":
    case "put":
      if(!text) return msg.reply(responses.EMPTY[msg.language])

      parameters = { text: text, submitter: msg.author.id, guild: msg.guild.id }
      this.quote.add(parameters).then(() => {
        return msg.reply(responses.ADDED[msg.language])
      }).catch((e) => {
        winston.info(e)
        return msg.reply(responses.ERROR[msg.language])
      })
      break
    case "del":
    case "delete":
    case "rem":
    case "remove":
      parameters = { id: id, guild: msg.guild.id }
      if(!this.quote.has(parameters)) return msg.reply(responses.MISSING[msg.language])
      if(!this.quote.get(parameters).submitter === msg.author.id) {
        return msg.reply(responses.NO_PERMISSION)
      }

      this.quote.delete(parameters).then(() => {
        return msg.reply(responses.REMOVED[msg.language](id))
      }).catch(() => {
        return msg.reply(responses.ERROR[msg.language])
      })
      break
    case "find":
    case "get": {
      parameters = { id: id, guild: msg.guild.id }
      if(id && !this.quote.has(parameters)) return msg.reply(responses.MISSING[msg.language])

      const quote = this.quote.get(parameters)
      msg.reply(responses.GET[msg.language](quote.id, quote.text))
      break
    }
    default:
      return msg.reply(responses.NO_MODE[msg.language](mode))
    }
  }
}

{'fraction_non_alphanumeric': 0.1554294975688817, 'fraction_numerical': 0.005996758508914101, 'mean_word_length': 2.307073954983923, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4899909', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1935, 'n_words': 455}