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

const Discord = require('discord.js');

module.exports = class WebhookHandler {
  /**
   * Handles the webhooks sent by Bastion.
   * @constructor
   * @param {Object} webhooks The webhooks object in the `credentials.json` file.
   */
  constructor(webhooks) {
    if (!webhooks) return null;

    for (let hook of Object.keys(webhooks)) {
      let webhookCredentials = webhooks[hook].split('/').slice(-2);
      this[hook] = {
        url: webhooks[hook],
        id: webhookCredentials[0],
        token: webhookCredentials[1]
      };
      this[hook].client = new Discord.WebhookClient(this[hook].id, this[hook].token);
    }
  }

  /**
   * Sends the specified message as a webhook to the specified webhook channel.
   * @function send
   * @param {String} webhook The name of the webhook where the message is to be sent.
   * @param {String|Number|Object} content The message content to send with the webhook. A string, number or Discord.js embed object.
   * @returns {void}
   */
  send(webhook, content) {
    if (webhook === 'bastionLog') {
      if (typeof content === 'object' && !(content instanceof Array)) {
        content = {
          embeds: [ content ]
        };
      }
      if (content) {
        this.bastionLog.client.send(content);
      }
    }
  }
};<commit_msg>Improvements to webhook handler * Webhook handler can now automatically handle any no. of hooks from credentials<commit_after>/**
 * @file webhookHandler
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

const Discord = require('discord.js');

module.exports = class WebhookHandler {
  /**
   * Handles the webhooks sent by Bastion.
   * @constructor
   * @param {Object} webhooks The webhooks object in the `credentials.json` file.
   */
  constructor(webhooks) {
    if (!webhooks) return null;
    this.webhooks = [];
    for (let hook of Object.keys(webhooks)) {
      this.webhooks.push(hook);
      let webhookCredentials = webhooks[hook].split('/').slice(-2);
      this[hook] = {
        url: webhooks[hook],
        id: webhookCredentials[0],
        token: webhookCredentials[1]
      };
      this[hook].client = new Discord.WebhookClient(this[hook].id, this[hook].token);
    }
  }

  /**
   * Sends the specified message as a webhook to the specified webhook channel.
   * @function send
   * @param {String} webhook The name of the webhook where the message is to be sent.
   * @param {String|Number|Object} content The message content to send with the webhook. A string, number or Discord.js embed object.
   * @returns {void}
   */
  send(webhook, content) {
    if (this.webhooks.includes(webhook)) {
      if (typeof content === 'object' && !(content instanceof Array)) {
        content = {
          embeds: [ content ]
        };
      }
      if (content) {
        this[webhook].client.send(content).catch(() => {});
      }
    }
  }
};
{'fraction_non_alphanumeric': 0.13061086736415795, 'fraction_numerical': 0.004724940938238272, 'mean_word_length': 2.790281329923274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '743024', 'n_tokens_mistral': 915, 'n_tokens_neox': 935, 'n_words': 262}