<commit_before>/**
 * @file wordFilter
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

/**
 * Handles filtering of specific words in messages
 * @param {Message} message Discord.js message object
 * @returns {void}
 */
module.exports = async message => {
  let guild = await message.client.db.get(`SELECT filterWord, filteredWords FROM guildSettings WHERE guildID=${message.guild.id}`).catch(e => {
    message.client.log.error(e);
  });

  if (!guild.filterWord || message.guild.members.get(message.author.id).hasPermission('ADMINISTRATOR')) return;

  let filteredWords = [];
  if (guild.filteredWords) {
    filteredWords = guild.filteredWords.split(' ');
  }
  for (let word of filteredWords) {
    if (message.content.toLowerCase().includes(word.toLowerCase())) {
      if (message.deletable) {
        return message.delete();
      }
    }
  }
};<commit_msg>Improvements to word filter * Implemented whitelists * Minor improvements * Minor fix<commit_after>/**
 * @file wordFilter
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

/**
 * Handles filtering of specific words in messages
 * @param {Message} message Discord.js message object
 * @returns {void}
 */
module.exports = async message => {
  try {
    let query = `SELECT filterWord, filteredWords, wordFilterWhitelistChannels, wordFilterWhitelistRoles FROM guildSettings LEFT OUTER JOIN whitelists ON guildSettings.guildID = whitelists.guildID WHERE guildSettings.guildId='${message.guild.id}'`;
    let guild = await message.client.db.get(query);

    if (!guild.filterWord) return;
    // If the channel is whitelisted, return
    if (guild.wordFilterWhitelistChannels) {
      let whitelistChannels = guild.wordFilterWhitelistChannels.split(' ');
      if (whitelistChannels.includes(message.channel.id)) return;
    }
    // If the user is in a whitelisted role, return
    if (guild.wordFilterWhitelistRoles) {
      let whitelistRoles = guild.wordFilterWhitelistRoles.split(' ');
      for (let whitelistRole of whitelistRoles) {
        if (message.member.roles.has(whitelistRole)) return;
      }
    }
    // If the user is an admin, return
    if (message.guild.members.get(message.author.id).hasPermission('ADMINISTRATOR')) return;

    let filteredWords = [];
    if (guild.filteredWords) {
      filteredWords = guild.filteredWords.split(' ');
    }
    for (let word of filteredWords) {
      if (message.content.toLowerCase().includes(word.toLowerCase())) {
        if (message.deletable) {
          return message.delete().catch(e => {
            message.client.log.error(e);
          });
        }
      }
    }
  }
  catch (e) {
    message.client.log.error(e);
  }
};
{'fraction_non_alphanumeric': 0.1304185351270553, 'fraction_numerical': 0.0029895366218236174, 'mean_word_length': 3.3741830065359477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3700218', 'n_tokens_mistral': 867, 'n_tokens_neox': 827, 'n_words': 188}