<commit_before># encoding: utf-8

require 'blather'

module Adhearsion
  class PunchblockPlugin
    class Initializer
      cattr_accessor :config, :client, :connection, :dispatcher, :attempts

      self.attempts = 0

      class << self
        def init
          self.config = Adhearsion.config[:punchblock]

          username = self.config.username
          connection_class = case (self.config.platform || :xmpp)
          when :xmpp
            username = Blather::JID.new username
            username = Blather::JID.new username.node, username.domain, resource unless username.resource
            username = username.to_s
            Punchblock::Connection::XMPP
          when :asterisk
            Punchblock::Connection::Asterisk
          end

          connection_options = {
            :username           => username,
            :password           => <PASSWORD>,
            :connection_timeout => self.config.connection_timeout,
            :host               => self.config.host,
            :port               => self.config.port,
            :root_domain        => self.config.root_domain,
            :calls_domain       => self.config.calls_domain,
            :mixers_domain      => self.config.mixers_domain,
            :media_engine       => self.config.media_engine
          }

          self.connection = connection_class.new connection_options
          self.client = Punchblock::Client.new :connection => connection

          # Tell the Punchblock connection that we are ready to process calls.
          Events.register_callback :after_initialization do
            connection.ready!
          end

          # When a stop is requested, change our status to "Do Not Disturb"
          # This should prevent the telephony engine from sending us any new calls.
          Events.register_callback :stop_requested do
            connection.not_ready! if connection.connected?
          end

          # Make sure we stop everything when we shutdown
          Events.register_callback :shutdown do
            client.stop
          end

          # Handle events from Punchblock via events system
          self.client.register_event_handler do |event|
            handle_event event<commit_msg>Use default port for respective platform if none is set<commit_after># encoding: utf-8

require 'blather'

module Adhearsion
  class PunchblockPlugin
    class Initializer
      cattr_accessor :config, :client, :connection, :dispatcher, :attempts

      self.attempts = 0

      class << self
        def init
          self.config = Adhearsion.config[:punchblock]

          username = self.config.username
          connection_class = case (self.config.platform || :xmpp)
          when :xmpp
            username = Blather::JID.new username
            username = Blather::JID.new username.node, username.domain, resource unless username.resource
            username = username.to_s
            port = 5222
            Punchblock::Connection::XMPP
          when :asterisk
            port = 5038
            Punchblock::Connection::Asterisk
          end

          connection_options = {
            :username           => username,
            :password           => <PASSWORD>,
            :connection_timeout => self.config.connection_timeout,
            :host               => self.config.host,
            :port               => self.config.port.nil? ? port : self.config.port,
            :root_domain        => self.config.root_domain,
            :calls_domain       => self.config.calls_domain,
            :mixers_domain      => self.config.mixers_domain,
            :media_engine       => self.config.media_engine
          }

          self.connection = connection_class.new connection_options
          self.client = Punchblock::Client.new :connection => connection

          # Tell the Punchblock connection that we are ready to process calls.
          Events.register_callback :after_initialization do
            connection.ready!
          end

          # When a stop is requested, change our status to "Do Not Disturb"
          # This should prevent the telephony engine from sending us any new calls.
          Events.register_callback :stop_requested do
            connection.not_ready! if connection.connected?
          end

          # Make sure we stop everything when we shutdown
          Events.register_callback :shutdown do
            client.stop
          end

          # Handle events from Punchblock via events system
          self.client.register_event_handler do |event|
            handle_event event
{'fraction_non_alphanumeric': 0.06941715782580223, 'fraction_numerical': 0.0026195153896529143, 'mean_word_length': 1.8872085696282295, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '3513147', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1112, 'n_words': 310}