<commit_before>/**
 * @file conversationHandler
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

const request = require('request-promise-native');

/**
 * Handles conversations with Bastion
 * @param {Message} message Discord.js message object
 * @returns {void}
 */
module.exports = async message => {
  try {
    message.content = message.content.replace(/^<@!?[0-9]{1,20}> ?/i, '');

    if (message.content.length < 2) return;

    let guildModel = await message.client.database.models.guild.findOne({
      attributes: [ 'chat' ],
      where: {
        guildID: message.guild.id
      }
    });
    if (!guildModel.dataValues.chat) return;

    message.channel.startTyping();

    let options = {
      url: 'https://api.bastionbot.org/chat',
      headers: {
        'User-Agent': 'Bastion Discord Bot (https://bastionbot.org)'
      },
      qs: {
        message: message.content
      },
      json: true
    };
    let response = await request(options);

    message.channel.stopTyping(true);

    if (response.status === 'success') {
      await message.channel.send(response.response);
    }
    else {
      await message.channel.send('Beep. Beep. Boop. Boop.');
    }
  }
  catch (e) {
    message.channel.stopTyping(true);

    message.client.log.error(e);
  }
};
<commit_msg>handlers: use bchat API for chatting module<commit_after>/**
 * @file conversationHandler
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

const request = require('request-promise-native');

/**
 * Handles conversations with Bastion
 * @param {Message} message Discord.js message object
 * @returns {void}
 */
module.exports = async message => {
  try {
    message.content = message.content.replace(/^<@!?[0-9]{1,20}> ?/i, '');

    if (message.content.length < 2) return;

    let guildModel = await message.client.database.models.guild.findOne({
      attributes: [ 'chat' ],
      where: {
        guildID: message.guild.id
      }
    });
    if (!guildModel.dataValues.chat) return;

    message.channel.startTyping();

    let options = {
      url: 'https://bchat.glitch.me/api',
      headers: {
        'User-Agent': 'Bastion Discord Bot (https://bastionbot.org)'
      },
      qs: {
        message: message.content
      },
      json: true
    };
    let response = await request(options);

    message.channel.stopTyping(true);

    if (response.status === 'success') {
      await message.channel.send(response.response);
    }
    else {
      await message.channel.send('Beep. Beep. Boop. Boop.');
    }
  }
  catch (e) {
    message.channel.stopTyping(true);

    message.client.log.error(e);
  }
};

{'fraction_non_alphanumeric': 0.15871212121212122, 'fraction_numerical': 0.00909090909090909, 'mean_word_length': 2.6327372764786796, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '2862906', 'n_tokens_mistral': 891, 'n_tokens_neox': 869, 'n_words': 172}