<commit_before>const Discord = require('discord.js');
const { ChannelProcessor } = require('./channelProcessor');
const { discordApiToken, graphqlApiBaseUrl } = require('./config');
const { formatHaiku } = require('./formatHaiku');
const commands = require('./commands');
const apiFactory = require('./haiku-api-connection/apiFactory');

const api = apiFactory.createGraphqlApi(graphqlApiBaseUrl);
const client = new Discord.Client();

const channelProcessorMap = {};

const processMessage = (message) => {
  const { channel } = message;
  const serverID = channel.guild.id;
  const channelID = channel.id;

  if (channelProcessorMap[channelID] == null) {
    const newChannelProcessor = new ChannelProcessor(serverID, channelID);
    newChannelProcessor.setOnHaikuFunction((haiku) => {
      console.log(`Haiku triggered:
        authors: ${haiku.authors}
        lines: ${haiku.lines},
        serverId: ${haiku.serverId},
        channelId: ${haiku.channelId}`);
      api.saveHaiku(haiku)
        .then(responseHaiku => channel.send(formatHaiku(responseHaiku)))
        .catch((error) => {
          console.log(`Caught error ${JSON.stringify(error)} while saving haiku, ignoring...`);
          console.log('Failed to save haiku.');
        });
    });
    channelProcessorMap[channelID] = newChannelProcessor;
  }

  channelProcessorMap[channelID].processMessage(message);
};

client.on('ready', () => {
  console.log('Bot is ready');
});

client.on('message', (message) => {
  if (message.author.id === client.user.id) {
    // Ignore own messages
    return;
  }

  const { content } = message;
  if (commandregex.test(content)) {<commit_msg>Ignore all bot messages instead of only its own<commit_after>const Discord = require('discord.js');
const { ChannelProcessor } = require('./channelProcessor');
const { discordApiToken, graphqlApiBaseUrl } = require('./config');
const { formatHaiku } = require('./formatHaiku');
const commands = require('./commands');
const apiFactory = require('./haiku-api-connection/apiFactory');

const api = apiFactory.createGraphqlApi(graphqlApiBaseUrl);
const client = new Discord.Client();

const channelProcessorMap = {};

const processMessage = (message) => {
  const { channel } = message;
  const serverID = channel.guild.id;
  const channelID = channel.id;

  if (channelProcessorMap[channelID] == null) {
    const newChannelProcessor = new ChannelProcessor(serverID, channelID);
    newChannelProcessor.setOnHaikuFunction((haiku) => {
      console.log(`Haiku triggered:
        authors: ${haiku.authors}
        lines: ${haiku.lines},
        serverId: ${haiku.serverId},
        channelId: ${haiku.channelId}`);
      api.saveHaiku(haiku)
        .then(responseHaiku => channel.send(formatHaiku(responseHaiku)))
        .catch((error) => {
          console.log(`Caught error ${JSON.stringify(error)} while saving haiku, ignoring...`);
          console.log('Failed to save haiku.');
        });
    });
    channelProcessorMap[channelID] = newChannelProcessor;
  }

  channelProcessorMap[channelID].processMessage(message);
};

client.on('ready', () => {
  console.log('Bot is ready');
});

client.on('message', (message) => {
  // Check for bot mention at start of message
  const commandregex = new RegExp(`^<@!?${client.user.id}> `);
  if (message.author.bot) {
    // Ignore bot messages
    return;
  }

  const { content } = message;
  if (commandregex.test(content)) {
{'fraction_non_alphanumeric': 0.15236427320490367, 'fraction_numerical': 0.0, 'mean_word_length': 3.9238505747126435, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, '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': '2851243', 'n_tokens_mistral': 1000, 'n_tokens_neox': 995, 'n_words': 209}