<commit_before>package com.pauldoo.spraffbot.irc

import java.net.InetSocketAddress
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.Deploy
import akka.actor.Props
import akka.actor.actorRef2Scala
import akka.io.IO
import akka.io.Tcp
import akka.io.TcpPipelineHandler
import akka.io.TcpPipelineHandler.Init
import akka.io.TcpPipelineHandler.WithinActorContext
import akka.io.TcpReadWriteAdapter
import akka.actor.ActorRef
import com.pauldoo.spraffbot.SpraffBot
import scala.concurrent.Future
import javax.net.ssl.SSLEngine
import javax.net.ssl.SSLContext
import akka.io.SslTlsSupport

object IrcConnection {
  def props(app: ActorRef): Props =
    Props(classOf[IrcConnection], SpraffBot.ircServer, app);
}

class IrcConnection(remote: InetSocketAddress, app: ActorRef) extends Actor with ActorLogging {
  import context._

  private val handlers: List[ActorRef] =
    List(
      context.actorOf(Ping.props, "ping"),
      context.actorOf(Privmsg.props(app), "privmsg"));

  {
    IO(Tcp) ! Tcp.Connect(remote);
  }

  def receive = unconnectedReceive;

  private val sslEngine: SSLEngine = {
    val engine = SSLContext.getDefault.createSSLEngine()
    engine.setUseClientMode(true)
    engine
  }

  def unconnectedReceive: Receive = {
    case Tcp.Connected(remote, local) => {
      log.info("Connected!");
      val connection = sender;

      val init = TcpPipelineHandler.withLogger(log,
        new IrcMessageStage() >>
          new BreakIntoLinesStage() >>
          new TcpReadWriteAdapter() >>
          new SslTlsSupport(sslEngine));

      val pipeline = context.actorOf(TcpPipelineHandler.props(
        init, connection, self).withDeploy(Deploy.local))

      connection ! Tcp.Register(pipeline);

      val send = sendMessage(pipeline, init)_;
      context become connectedReceive(init, send);
<commit_msg>Logging.<commit_after>package com.pauldoo.spraffbot.irc

import java.net.InetSocketAddress
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.Deploy
import akka.actor.Props
import akka.actor.actorRef2Scala
import akka.io.IO
import akka.io.Tcp
import akka.io.TcpPipelineHandler
import akka.io.TcpPipelineHandler.Init
import akka.io.TcpPipelineHandler.WithinActorContext
import akka.io.TcpReadWriteAdapter
import akka.actor.ActorRef
import com.pauldoo.spraffbot.SpraffBot
import scala.concurrent.Future
import javax.net.ssl.SSLEngine
import javax.net.ssl.SSLContext
import akka.io.SslTlsSupport

object IrcConnection {
  def props(app: ActorRef): Props =
    Props(classOf[IrcConnection], SpraffBot.ircServer, app);
}

class IrcConnection(remote: InetSocketAddress, app: ActorRef) extends Actor with ActorLogging {
  import context._

  private val handlers: List[ActorRef] =
    List(
      context.actorOf(Ping.props, "ping"),
      context.actorOf(Privmsg.props(app), "privmsg"));

  {
    IO(Tcp) ! Tcp.Connect(remote);
  }

  def receive = unconnectedReceive;

  private val sslEngine: SSLEngine = {
    val engine = SSLContext.getDefault.createSSLEngine()
    engine.setUseClientMode(true)
    log.info(s"Supported SSL protocols: ${engine.getSupportedProtocols().toList}")
    log.info(s"Enabled SSL protocols: ${engine.getEnabledProtocols().toList}")
    engine
  }

  def unconnectedReceive: Receive = {
    case Tcp.Connected(remote, local) => {
      log.info("Connected!");
      val connection = sender;

      val init = TcpPipelineHandler.withLogger(log,
        new IrcMessageStage() >>
          new BreakIntoLinesStage() >>
          new TcpReadWriteAdapter() >>
          new SslTlsSupport(sslEngine));

      val pipeline = context.actorOf(TcpPipelineHandler.props(
        init, connection, self).withDeploy(Deploy.local))

      connection ! Tcp.Register(pipeline);

      val send = sendMessage(pipeline, init)_;
      context become connectedReceive(init, send);

{'fraction_non_alphanumeric': 0.10142671854734112, 'fraction_numerical': 0.0005188067444876783, 'mean_word_length': 4.141333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7591191', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1223, 'n_words': 244}