<commit_before>const logger = require('winston')
const { Command, Permitter } = require('../../core')

class Autorole extends Command {
  constructor (...args) {
    super(...args, {
      name: 'autorole',
      description: 'Add a role to a user on join',
      usage: [
        { name: 'role', type: 'role', optional: true }
      ],
      options: { guildOnly: true, localeKey: 'settings', modOnly: true }
    })
  }


  async handle ({ msg, args, data, settings }, responder) {
    if (!args.role) {
      console.log(settings.autorole.name === null)
      if (settings.autorole.name === null) {
        return responder.format('emoji:info').reply('{{autorole.none}}')
      }
      return responder.format('emoji:info').reply('{{autorole.current}}', { role: `**${settings.autorole.name}**` })
    }
    try {
      console.log(args.role);
      console.log(args.role[0].id);
      console.log(args.role[0].name);
      settings.autorole.id = args.role[0].id
      settings.autorole.name = args.role[0].name
      await settings.save()
      return responder.success('{{autorole.success}}', {
        role: `**\`${args.role[0].name}\`**`
      })
    } catch (err) {
      logger.error(`Could not ${cmd} for ${msg.channel.guild.name} (${msg.channel.guild.id}) - ${err}`)
      return responder.error()
    }
  }
}

module.exports = Autorole<commit_msg>:art: :sparkles: Finishes work for autorole command, reformatting into subcommands and adding a remove subcommand<commit_after>const logger = require('winston')
const { Command, Permitter } = require('../../core')

class Autorole extends Command {
  constructor (...args) {
    super(...args, {
      name: 'autorole',
      description: 'Add a role to a user on join',
      usage: [
        { name: 'action', displayName: ' add | remove', type: 'string', optional: true }],
      subcommands: {
        add: {
          usage: [
            { name: 'role', type: 'role', optional: false }
          ]
        },
        remove: {
          aliases: ['delete']
        }
      },
      options: { guildOnly: true, localeKey: 'settings', modOnly: true }
    })
  }


  async handle ({ msg, data, settings }, responder) {
    try {
      if (settings.autorole.name === null) {
        return responder.format('emoji:info').reply('{{autorole.none}}')
      }
      return responder.format('emoji:info').reply('{{autorole.current}}', { role: `**${settings.autorole.name}**` })
    } catch (err) {
      logger.error(`Could not ${cmd} for ${msg.channel.guild.name} (${msg.channel.guild.id}) - ${err}`)
      return responder.error()
    }
  }

  async add ({ msg, args, data, settings }, responder) {
    try {
      settings.autorole.id = args.role[0].id
      settings.autorole.name = args.role[0].name
      await settings.save()
      return responder.success('{{autorole.success}}', {
        role: `**\`${args.role[0].name}\`**`
      })
    } catch (err) {
      logger.error(`Could not ${cmd} for ${msg.channel.guild.name} (${msg.channel.guild.id}) - ${err}`)
      return responder.error()
    }
  }

  async remove ({ msg, data, settings }, responder) {
    try {
      settings.autorole.id = null
      settings.autorole.name = null
      await settings.save()
      return responder.success('{{autorole.none}}')
    } catch (err) {
      logger.error(`Cound not ${cmd} for ${msg.channel.guild.name} (${msg.channel.guild.id}) - ${err}`)
      return responder.error()
    }
  }
  
}

module.exports = Autorole
{'fraction_non_alphanumeric': 0.18082349553699972, 'fraction_numerical': 0.002303484019579614, 'mean_word_length': 2.6149843912591053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7468902', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1130, 'n_words': 237}