<commit_before>const moment = require('moment')
const logger = require('winston')
const { Module } = require('../../core')

class Butler extends Module {
  constructor (...args) {
    super(...args, {
      name: 'butler',
      events: {
        guildMemberAdd: 'onJoin',
        guildMemberRemove: 'onLeave'
      }
    })

    this.db = this.bot.engine.db.data
  }

  get tags () {
    return [
      'user',
      'userName',
      'guild',
      'userID',
      'guildID',
      'date',
      'members',
      'humans'
    ]
  }

  onJoin (guild, member) {
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.welcome === 'object' &&
      (settings.welcome.chan || settings.welcome.pm) &&
      (settings.welcome.pm ? this.bot.getDMChannel(member.id) : Promise.resolve(settings.welcome.chan)).then(chan =>
        this.send(chan, this.i18n.shift(settings.welcome.msg, {
          user: member.mention,
          guild: guild.name,
          userName: member.user.username,
          userID: member.id,
          guildID: guild.id,
          date: moment().toString(),
          members: guild.members.size,
          humans: guild.members.filter(m => !m.bot).length
        }))
      )
    ).catch(err => logger.error('Error sending welcome message -', err))
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.autorole === 'string' &&
      member.addRole(settings.autorole, 'Added role on user join -Haru')
    ).catch(err => logger.error('Error setting role -', err))
  }

  onLeave (guild, member) {
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.goodbye === 'object' &&
      settings.goodbye.chan &&
      this.send(settings.goodbye.chan, this.i18n.shift(settings.goodbye.msg, {
        user: member.mention,
        guild: guild.name,
        userName: member.user.username,
        userID: member.id,
        guildID: guild.id,
        date: moment().toString(),
        members: guild.members.size,
        humans: guild.members.filter(m => !m.bot).length
      }))
    ).catch(err => logger.error('Error sending goodbye message -', err))<commit_msg>:ambulance: :bug: fixes bug where autorole didn't actually work<commit_after>const moment = require('moment')
const logger = require('winston')
const { Module } = require('../../core')

class Butler extends Module {
  constructor (...args) {
    super(...args, {
      name: 'butler',
      events: {
        guildMemberAdd: 'onJoin',
        guildMemberRemove: 'onLeave'
      }
    })

    this.db = this.bot.engine.db.data
  }

  get tags () {
    return [
      'user',
      'userName',
      'guild',
      'userID',
      'guildID',
      'date',
      'members',
      'humans'
    ]
  }

  onJoin (guild, member) {
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.welcome === 'object' &&
      (settings.welcome.chan || settings.welcome.pm) &&
      (settings.welcome.pm ? this.bot.getDMChannel(member.id) : Promise.resolve(settings.welcome.chan)).then(chan =>
        this.send(chan, this.i18n.shift(settings.welcome.msg, {
          user: member.mention,
          guild: guild.name,
          userName: member.user.username,
          userID: member.id,
          guildID: guild.id,
          date: moment().toString(),
          members: guild.members.size,
          humans: guild.members.filter(m => !m.bot).length
        }))
      )
    ).catch(err => logger.error('Error sending welcome message -', err))
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.autorole.id === 'string' &&
      member.addRole(settings.autorole.id, 'Added role on user join -Haru')
    ).catch(err => logger.error('Error setting role -', err))
  }

  onLeave (guild, member) {
    this.db.Guild.fetch(guild.id).then(settings =>
      typeof settings.goodbye === 'object' &&
      settings.goodbye.chan &&
      this.send(settings.goodbye.chan, this.i18n.shift(settings.goodbye.msg, {
        user: member.mention,
        guild: guild.name,
        userName: member.user.username,
        userID: member.id,
        guildID: guild.id,
        date: moment().toString(),
        members: guild.members.size,
        humans: guild.members.filter(m => !m.bot).length
      }))
    ).catch(err => logger.error('Error sending goodbye message -', err))
{'fraction_non_alphanumeric': 0.15810185185185185, 'fraction_numerical': 0.001851851851851852, 'mean_word_length': 2.3731459797033567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '208793', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1374, 'n_words': 251}