<commit_before># frozen_string_literal: true

module Hackbot
  module SlackInteraction
    extend ActiveSupport::Concern

    def send_msg(channel, msg)
      opts = HashWithIndifferentAccess.new(as_user: true)

      if msg.is_a? String
        opts[:text] = msg
      else
        opts = opts.merge(msg)
      end

      if opts[:attachments]
        opts[:attachments] = insert_attachment_defaults(opts[:attachments])
      end

      ::SlackClient::Chat.send_msg(channel, nil, access_token, opts)

      sleep 1 # space out calls to slack's api to prevent rate limiting
    end

    def attach(channel, *attachments)
      send_msg(channel, attachments: attachments)
    end

    # Commenting because this method's name is somewhat confusing. Please rename
    # if you can think of something better.
    #
    # This method updates the message that triggered action with the passed in
    # message contents. It uses action's special response_url attribute to
    # update the source message without leaving a note in the user's Slack
    # client saying that the source message was edited, making the UX of the
    # edit much nicer.<commit_msg>Properly return response from Slack API<commit_after># frozen_string_literal: true

module Hackbot
  module SlackInteraction
    extend ActiveSupport::Concern

    def send_msg(channel, msg)
      opts = HashWithIndifferentAccess.new(as_user: true)

      if msg.is_a? String
        opts[:text] = msg
      else
        opts = opts.merge(msg)
      end

      if opts[:attachments]
        opts[:attachments] = insert_attachment_defaults(opts[:attachments])
      end

      resp = ::SlackClient::Chat.send_msg(channel, nil, access_token, opts)

      sleep 1 # space out calls to slack's api to prevent rate limiting

      resp
    end

    def attach(channel, *attachments)
      send_msg(channel, attachments: attachments)
    end

    # Commenting because this method's name is somewhat confusing. Please rename
    # if you can think of something better.
    #
    # This method updates the message that triggered action with the passed in
    # message contents. It uses action's special response_url attribute to
    # update the source message without leaving a note in the user's Slack
    # client saying that the source message was edited, making the UX of the
    # edit much nicer.
{'fraction_non_alphanumeric': 0.06263314870046868, 'fraction_numerical': 0.0008521516829995739, 'mean_word_length': 3.0905923344947737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4544023', 'n_tokens_mistral': 652, 'n_tokens_neox': 612, 'n_words': 244}