<commit_before># Scala IRC

Scala irc is a small irc framework focused on a simple interface for receiving and responding to messages and composable interfaces.

## Installation

```scala
libraryDependencies += "org.conbere" %% "irc" % "0.3.0"
```

## Usage: Bots

The easiest way to get started is to extend the `ClassicBot` trait

``` scala
import org.conbere.irc._

class MyBot( val serverName:String
           , val nickName:String
           , val userName:String
           , val password:String
           , val realName:String
           , val rooms:List[Room])
extends ClassicBot {
```

For ease of use we'll grab `Messages` from the irc package. These form the foundational datatypes for using irc. `Messages` provides common extractors for all of the irc commands (PONG, PRIVMSG, JOIN, etc.) as well as providing an easy helper to produce a Message object for pushing back to the server. `Tokens` 
  
```scala
  import Messages._

  val toMePattern = ("^(" + nickName + "[:| ].*)").r
```

To build a bot the most common action is to respond to input from other clients on the server. To help with that, the `Bot` trait requires the `respondTo` method. `respondTo` is a `PartialFunction` takes in a `Message` object and return an optional `Response`.

```scala
  val respondTo = defaultResponse.orElse {
    case PrivMsg(from, `nickName`, _) =>
      Some(PrivMsg(from, "Hi " + from + " this is a private message"))
    case PrivMsg(from, channel, toMePattern(_match)) =>
      Some(PrivMsg(from, "Hi " + from + " this is a channel message directed at me"))
  }
```

Here you can see that we're using the `defaultResponse` method to help. This will set up sending credentials, and responding to any `Ping` messages from the server. We're also taking advantage of respondTo being a PartialFucntion and using the orElse method. This allows us to chain helpers together, in this case the matches in defaultResponse will short circuit, catching those messages before they get to our handler.

And finally we match against PrivMsg's comming in looking for some simple patterns, and respond with new PrivMsgs.


```scala<commit_msg>describe the Client object<commit_after># Scala IRC

Scala irc is a small irc framework focused on a simple interface for receiving and responding to messages and composable interfaces.

## Installation

```scala
libraryDependencies += "org.conbere" %% "irc" % "0.3.0"
```

## Usage: Bots

The easiest way to get started is to extend the `ClassicBot` trait

``` scala
import org.conbere.irc._

class MyBot( val serverName:String
           , val nickName:String
           , val userName:String
           , val password:String
           , val realName:String
           , val rooms:List[Room])
extends ClassicBot {
```

For ease of use we'll grab `Messages` from the irc package. These form the foundational datatypes for using irc. `Messages` provides common extractors for all of the irc commands (PONG, PRIVMSG, JOIN, etc.) as well as providing an easy helper to produce a Message object for pushing back to the server. `Tokens` 
  
```scala
  import Messages._

  val toMePattern = ("^(" + nickName + "[:| ].*)").r
```

To build a bot the most common action is to respond to input from other clients on the server. To help with that, the `Bot` trait requires the `respondTo` method. `respondTo` is a `PartialFunction` takes in a `Message` object and return an optional `Response`.

Here you can see that we're using the `defaultResponse` method to help. This will set up sending credentials, and responding to any `Ping` messages from the server. We're also taking advantage of respondTo being a PartialFucntion and using the orElse method. This allows us to chain helpers together, in this case the matches in defaultResponse will short circuit, catching those messages before they get to our handler.

And finally we match against PrivMsg's comming in looking for some simple patterns, and respond with new PrivMsgs.

```scala
  val respondTo = defaultResponse.orElse {
    case PrivMsg(from, `nickName`, _) =>
      Some(PrivMsg(from, "Hi " + from + " this is a private message"))
    case PrivMsg(from, channel, toMePattern(_match)) =>
      Some(PrivMsg(from, "Hi " + from + " this is a channel message directed at me"))
  }
}
```

The last task is to produce an runable executable. To run your bot the Client object defines a start method which given a server and port will host your bot in an Actor.

```scala
object Main {
  def main(args:Array[String]) = {
    val server = "irc.ny4dev.etsy.com"
    val port = 6667

    val rooms = List(Room("#testroom", None))

    val bot = new MyBot(server, "bot", "bot", "pass", "Bot", rooms)

    val actor = Client.start(server, port, bot)
  }
{'fraction_non_alphanumeric': 0.08741554054054054, 'fraction_numerical': 0.0023226351351351353, 'mean_word_length': 3.7848484848484847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6973981', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1295, 'n_words': 627}