<commit_before># Send a message to a Slack channel
#
# account        - The name of your Slack account (visible in URL, e.g. foo.slack.com)
# token          - The token of the webhook created in Slack
# channel        - The name of the channel to send the message to, prefixed with #
# notify_channel - Whether to send an "@channel" in the message, to alert everyone in the channel
# format         - An optional format string to change how the alert is displayed

require 'net/http'
require 'uri'

CONTACT_DEPS[:slack] = ['json']
CONTACT_DEPS[:slack].each do |d|
  require d
end

module God
  module Contacts

    class Slack < Contact
      class << self
        attr_accessor :account, :token, :channel, :notify_channel, :format
      end

      self.channel        = "#general"
      self.notify_channel = false
      self.format         = "%{priority} alert on %{host}: %{message} (%{category}, %{time})"

      def valid?
        valid = true
        valid &= complain("Attribute 'account' must be specified", self) unless arg(:account)
        valid &= complain("Attribute 'token' must be specified", self) unless arg(:token)
        valid
      end

      attr_accessor :account, :token, :channel, :notify_channel, :format

      def text(data)
        text = ""
        text << "<!channel> " if arg(:notify_channel)

        if RUBY_VERSION =~ /^1\.8/
          text << arg(:format).gsub(/%{(\w+)}/) do |match|
            data[$1.to_sym]
          end
        else
          text << arg(:format) % data
        end

        text
      end

      def notify(message, time, priority, category, host)
        text = text({
          :message => message,
          :time => time,
          :priority => priority,
          :category => category,
          :host => host
        })
<commit_msg>Escape curly braces in 1.8<commit_after># Send a message to a Slack channel
#
# account        - The name of your Slack account (visible in URL, e.g. foo.slack.com)
# token          - The token of the webhook created in Slack
# channel        - The name of the channel to send the message to, prefixed with #
# notify_channel - Whether to send an "@channel" in the message, to alert everyone in the channel
# format         - An optional format string to change how the alert is displayed

require 'net/http'
require 'uri'

CONTACT_DEPS[:slack] = ['json']
CONTACT_DEPS[:slack].each do |d|
  require d
end

module God
  module Contacts

    class Slack < Contact
      class << self
        attr_accessor :account, :token, :channel, :notify_channel, :format
      end

      self.channel        = "#general"
      self.notify_channel = false
      self.format         = "%{priority} alert on %{host}: %{message} (%{category}, %{time})"

      def valid?
        valid = true
        valid &= complain("Attribute 'account' must be specified", self) unless arg(:account)
        valid &= complain("Attribute 'token' must be specified", self) unless arg(:token)
        valid
      end

      attr_accessor :account, :token, :channel, :notify_channel, :format

      def text(data)
        text = ""
        text << "<!channel> " if arg(:notify_channel)

        if RUBY_VERSION =~ /^1\.8/
          text << arg(:format).gsub(/%\{(\w+)\}/) do |match|
            data[$1.to_sym]
          end
        else
          text << arg(:format) % data
        end

        text
      end

      def notify(message, time, priority, category, host)
        text = text({
          :message => message,
          :time => time,
          :priority => priority,
          :category => category,
          :host => host
        })

{'fraction_non_alphanumeric': 0.11430943814004982, 'fraction_numerical': 0.0022142264046498754, 'mean_word_length': 2.170175438596491, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, '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': '4006599', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1014, 'n_words': 364}