<commit_before>const profanity = require('../misc/profanity.json');
const service = require('../main/service.js');
const language = require('../lang/language.js');

module.exports.AutoFunctions = class {
  static checkProfanity (msg, client) {
    function setLang (lang) {
      for (let i = 0; i < lang.length; ++i) {
        let patternStr =
          "(^|[0-9\\-!\\$%№\\^\\&\\*\\(\\)_\\+\\|~\\\"=\\'`\\{\\}\\[\\]:/;\\<\\>\\?,\\.@#]|\\s)SAMPLE([0-9\\-!\\$%№\\^\\&\\*\\(\\)_\\+\\|~\\\"=\\'`\\{\\}\\[\\]:/;\\<\\>\\?,\\.@#\\s]|$)";
        let pattern = new RegExp(patternStr.replace(/SAMPLE/, lang[i]), 'g');
        if (pattern.test(msg.content.toLowerCase())) {
          msg.channel.sendMessage(
            `${language.Language.getPhrase('Profanity')}!\n` +
            `${language.Language.getPhrase('Perpetrator')}: ` +
            `${msg.author} | ${language.Language.getPhrase('Time')}` +
            `: ${msg.createdAt} | ${language.Language.getPhrase(
              'ReasonWord'
            )}: $lang[i]}`
          );
          return;
        }
      }
    }

    if (msg.author.id !== client.user.id && !msg.author.bot) {
      setLang(profanity.profanity.en);
      setLang(profanity.profanity.ru);
      setLang(profanity.profanity.de);
      setLang(profanity.profanity.fr);
      setLang(profanity.profanity.es);
    }
  }

  static checkStream (oldMember, newMember) {
    if (
      newMember.presence.game !== null &&
      !newMember.user.bot &&
      oldMember.presence.game !== newMember.presence.game &&
      newMember.presence.game.streaming
    ) {
      try {
        newMember.guild.defaultChannel.sendMessage(
          `@here\n***` +
          `${language.Language.getPhrase('Stream').toUpperCase()}` +
          `***\n\n${newMember.user} ` +
          `${language.Language.getPhrase('StartedStreaming')} *` +
          `${newMember.presence.game.name}*\n` +
          `${language.Language.getPhrase('WatchOn')} ` +
          `${newMember.presence.game.url !== null
            ? service.Service.shortLink(newMember.presence.game.url)
            : 'N/A'}`
        );
      } catch (e) {
        console.log('Error: ' + e);
      }
    }
  }
};
<commit_msg>rewrite checkProfanity<commit_after>const profanity = require('../misc/profanity.json');
const service = require('../main/service.js');
const language = require('../lang/language.js');

module.exports.AutoFunctions = class {
  static checkProfanity (msg, client) {
    function passThroughtLangs () {
      function setLang (lang) {
        for (let i = 0; i < lang.length; ++i) {
          let patternStr =
            "(^|[0-9\\-!\\$%№\\^\\&\\*\\(\\)_\\+\\|~\\\"=\\'`\\{\\}\\[\\]:/;\\<\\>\\?,\\.@#]|\\s)SAMPLE([0-9\\-!\\$%№\\^\\&\\*\\(\\)_\\+\\|~\\\"=\\'`\\{\\}\\[\\]:/;\\<\\>\\?,\\.@#\\s]|$)";
          let pattern = new RegExp(patternStr.replace(/SAMPLE/, lang[i]), 'g');
          if (pattern.test(msg.content.toLowerCase())) {
            msg.channel.sendMessage(
              `${language.Language.getPhrase('Profanity')}!\n` +
              `${language.Language.getPhrase('Perpetrator')}: ` +
              `${msg.author} | ${language.Language.getPhrase('Time')}` +
              `: ${msg.createdAt} | ${language.Language.getPhrase(
                'ReasonWord'
              )}: ${lang[i]}`
            );
            return true;
          }
        }
        return false;
      }

      for (let i = 0; i < arguments.length; ++i) {
        if (setLang(arguments[i])) {
          return;
        }
      }
    }

    if (msg.author.id !== client.user.id && !msg.author.bot) {
      passThroughtLangs(
        profanity.profanity.en,
        profanity.profanity.ru,
        profanity.profanity.de,
        profanity.profanity.fr,
        profanity.profanity.es
      );
    }
  }

  static checkStream (oldMember, newMember) {
    if (
      newMember.presence.game !== null &&
      !newMember.user.bot &&
      oldMember.presence.game !== newMember.presence.game &&
      newMember.presence.game.streaming
    ) {
      try {
        newMember.guild.defaultChannel.sendMessage(
          `@here\n***` +
          `${language.Language.getPhrase('Stream').toUpperCase()}` +
          `***\n\n${newMember.user} ` +
          `${language.Language.getPhrase('StartedStreaming')} *` +
          `${newMember.presence.game.name}*\n` +
          `${language.Language.getPhrase('WatchOn')} ` +
          `${newMember.presence.game.url !== null
            ? service.Service.shortLink(newMember.presence.game.url)
            : 'N/A'}`
        );
      } catch (e) {
        console.log('Error: ' + e);
      }
    }
  }
};

{'fraction_non_alphanumeric': 0.22530329289428075, 'fraction_numerical': 0.002383015597920277, 'mean_word_length': 1.9482758620689655, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, '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': '1519528', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1596, 'n_words': 181}