<commit_before>const activities = require('../constants/activities');
const flatten = require('flat');
const currencies = require('../constants/currencies');

module.exports = {

  /*
   * Formats an activity *FOR INTERNAL USE* based on its type
   */
  formatMessageForPrivateChannel: (activity, format) => {

    var userString = '';
    var userId;
    var groupName = '';
    var publicUrl = '';
    var amount = null;
    var interval = '';
    var recurringAmount = null;
    var currency = '';
    var description = '';
    var eventType = '';
    var provider = '';
    var connectedAccountUsername = '';
    const connectedAccountLink = '';


    // get user data
    if (activity.data.user) {
      userString = getUserString(format, activity.data.user, true);
      userId = activity.data.user.id;
    }

    // get group data
    if (activity.data.group) {
      groupName = activity.data.group.name;
      publicUrl = activity.data.group.publicUrl;
    }

    // get donation data
    if (activity.data.donation) {
      amount = activity.data.donation.amount/100;
      currency = activity.data.donation.currency;
    }

    // get subscription data
    if (activity.data.subscription) {
      interval = activity.data.subscription.interval;
      recurringAmount = amount + (interval ? `/${interval}` : '');
    }

    // get transaction data
    if (activity.data.transaction) {
      amount = activity.data.transaction.amount;
      interval = activity.data.transaction.interval;
      recurringAmount = amount + (interval ? `/${interval}` : '');
      currency = activity.data.transaction.currency;
      tags = JSON.stringify(activity.data.transaction.tags);
      description = activity.data.transaction.description;
    }

    // get expense data
    if (activity.data.expense) {
      amount = activity.data.expense.amount/100;
      currency = activity.data.expense.currency;
      category = activity.data.expense.category;
      title = activity.data.expense.title;
      lastEditedById = activity.data.expense.lastEditedById;
    }

    // get connected account data
    if (activity.data.connectedAccount) {
      provider = activity.data.connectedAccount.provider;
      connectedAccountUsername = activity.data.connectedAccount.username;
      if (provider === 'github') {
        connectedAccountUsernameLink = linkify(format, `https://github.com/${connectedAccountUsername}`, null);
      }
    }

    // get event data
    if (activity.data.event) {
      eventType = activity.data.event.type;
    }

    const group = linkify(format, publicUrl, groupName);

    switch (activity.type) {

      // Currently used for both new donation and expense
      case activities.GROUP_TRANSACTION_CREATED:
        if (activity.data.transaction.isDonation) {
          return `New Donation: ${userString} gave ${currency} ${amount} to ${group}!`;
        }
        break;

      case activities.GROUP_EXPENSE_CREATED:
        return `New Expense: ${userString} submitted an expense to ${group}: ${currency} ${amount} for ${title}!`

      case activities.GROUP_EXPENSE_REJECTED:
        return `Expense rejected: ${currency} ${amount} for ${title} in ${group} by userId: ${lastEditedById}!`

      case activities.GROUP_EXPENSE_APPROVED:
        return `Expense approved: ${currency} ${amount} for ${title} in ${group} by userId: ${lastEditedById}!`

      case activities.CONNECTED_ACCOUNT_CREATED:
        return `New Connected Account created by ${connectedAccountUsername} on ${provider}. ${connectedAccountLink}`;

      case activities.GROUP_TRANSACTION_PAID:
        const details = activity.data.preapprovalDetails;
        const remaining = Number(details.maxTotalAmountOfAllPayments) - Number(details.curPaymentsAmount);
        return `Expense paid on ${group}: ${currency} ${amount} for '${description}' (${remaining} ${currency} remaining on preapproval key)`;

      case activities.USER_CREATED:
        return `New user joined: ${userString}`;

      case activities.WEBHOOK_STRIPE_RECEIVED:
        return `Stripe event received: ${eventType}`;

      case activities.SUBSCRIPTION_CONFIRMED:
        return `New subscription confirmed: ${currency} ${recurringAmount} from ${userString} to ${group}!`;

      case activities.SUBSCRIPTION_CANCELED:
        const subscriptionId = activity.data.subscriptionId;
        return `Subscription ${subscriptionId} canceled`;

      case activities.GROUP_CREATED:
        return `New group created: ${group} by ${userString}`;

      case activities.GROUP_USER_ADDED:
        return `New user: ${userString} (UserId: ${userId}) added to group: ${group}`;<commit_msg>fix bug for manual payments<commit_after>const activities = require('../constants/activities');
const flatten = require('flat');
const currencies = require('../constants/currencies');

module.exports = {

  /*
   * Formats an activity *FOR INTERNAL USE* based on its type
   */
  formatMessageForPrivateChannel: (activity, format) => {

    var userString = '';
    var userId;
    var groupName = '';
    var publicUrl = '';
    var amount = null;
    var interval = '';
    var recurringAmount = null;
    var currency = '';
    var description = '';
    var eventType = '';
    var provider = '';
    var connectedAccountUsername = '';
    const connectedAccountLink = '';


    // get user data
    if (activity.data.user) {
      userString = getUserString(format, activity.data.user, true);
      userId = activity.data.user.id;
    }

    // get group data
    if (activity.data.group) {
      groupName = activity.data.group.name;
      publicUrl = activity.data.group.publicUrl;
    }

    // get donation data
    if (activity.data.donation) {
      amount = activity.data.donation.amount/100;
      currency = activity.data.donation.currency;
    }

    // get subscription data
    if (activity.data.subscription) {
      interval = activity.data.subscription.interval;
      recurringAmount = amount + (interval ? `/${interval}` : '');
    }

    // get transaction data
    if (activity.data.transaction) {
      amount = activity.data.transaction.amount;
      interval = activity.data.transaction.interval;
      recurringAmount = amount + (interval ? `/${interval}` : '');
      currency = activity.data.transaction.currency;
      tags = JSON.stringify(activity.data.transaction.tags);
      description = activity.data.transaction.description;
    }

    // get expense data
    if (activity.data.expense) {
      amount = activity.data.expense.amount/100;
      currency = activity.data.expense.currency;
      category = activity.data.expense.category;
      title = activity.data.expense.title;
      lastEditedById = activity.data.expense.lastEditedById;
    }

    // get connected account data
    if (activity.data.connectedAccount) {
      provider = activity.data.connectedAccount.provider;
      connectedAccountUsername = activity.data.connectedAccount.username;
      if (provider === 'github') {
        connectedAccountUsernameLink = linkify(format, `https://github.com/${connectedAccountUsername}`, null);
      }
    }

    // get event data
    if (activity.data.event) {
      eventType = activity.data.event.type;
    }

    const group = linkify(format, publicUrl, groupName);

    switch (activity.type) {

      // Currently used for both new donation and expense
      case activities.GROUP_TRANSACTION_CREATED:
        if (activity.data.transaction.isDonation) {
          return `New Donation: ${userString} gave ${currency} ${amount} to ${group}!`;
        }
        break;

      case activities.GROUP_EXPENSE_CREATED:
        return `New Expense: ${userString} submitted an expense to ${group}: ${currency} ${amount} for ${title}!`

      case activities.GROUP_EXPENSE_REJECTED:
        return `Expense rejected: ${currency} ${amount} for ${title} in ${group} by userId: ${lastEditedById}!`

      case activities.GROUP_EXPENSE_APPROVED:
        return `Expense approved: ${currency} ${amount} for ${title} in ${group} by userId: ${lastEditedById}!`

      case activities.CONNECTED_ACCOUNT_CREATED:
        return `New Connected Account created by ${connectedAccountUsername} on ${provider}. ${connectedAccountLink}`;

      case activities.GROUP_TRANSACTION_PAID:
        const details = activity.data.preapprovalDetails;
        var remainingClause = '';
        if (details && details.maxTotalAmountOfAllPayments && details.curPaymentsAmount) {
          const remaining = Number(details.maxTotalAmountOfAllPayments) - Number(details.curPaymentsAmount);
          remainingClause = `(${remaining} ${currency} remaining on preapproval key)`;
        } else {
          remainingClause = `[Manual payment]`;
        }
        return `Expense paid on ${group}: ${currency} ${amount} for '${description}' ${remainingClause}`;

      case activities.USER_CREATED:
        return `New user joined: ${userString}`;

      case activities.WEBHOOK_STRIPE_RECEIVED:
        return `Stripe event received: ${eventType}`;

      case activities.SUBSCRIPTION_CONFIRMED:
        return `New subscription confirmed: ${currency} ${recurringAmount} from ${userString} to ${group}!`;

      case activities.SUBSCRIPTION_CANCELED:
        const subscriptionId = activity.data.subscriptionId;
        return `Subscription ${subscriptionId} canceled`;

      case activities.GROUP_CREATED:
        return `New group created: ${group} by ${userString}`;

      case activities.GROUP_USER_ADDED:
        return `New user: ${userString} (UserId: ${userId}) added to group: ${group}`;
{'fraction_non_alphanumeric': 0.12005442746493615, 'fraction_numerical': 0.0012560184216035169, 'mean_word_length': 3.127429805615551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5291230', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2642, 'n_words': 641}