You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageBuilders.kt 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.dmdirc.ktirc.messages
  2. import com.dmdirc.ktirc.IrcClient
  3. /** Sends a message to ask the server to list capabilities. */
  4. internal fun IrcClient.sendCapabilityList() = send("CAP LS 302")
  5. /** Sends a message indicating the end of capability negotiation. */
  6. internal fun IrcClient.sendCapabilityEnd() = send("CAP END")
  7. /** Sends a message requesting the specified caps are enabled. */
  8. internal fun IrcClient.sendCapabilityRequest(capabilities: List<String>) = send("CAP REQ :${capabilities.joinToString(" ")}")
  9. /** Sends a request to join the given channel. */
  10. fun IrcClient.sendJoin(channel: String) = send("JOIN :$channel")
  11. /** Sends a request to change to the given nickname. */
  12. fun IrcClient.sendNickChange(nick: String) = send("NICK :$nick")
  13. /** Sends the connection password to the server. */
  14. internal fun IrcClient.sendPassword(password: String) = send("PASS :$password")
  15. /** Sends a response to a PING event. */
  16. internal fun IrcClient.sendPong(nonce: ByteArray) = send("PONG :${String(nonce)}")
  17. /** Sends a CTCP message of the specified [type] and with optional [data] to [target] (a user or a channel). */
  18. fun IrcClient.sendCtcp(target: String, type: String, data: String? = null) =
  19. sendMessage(target, "\u0001${type.toUpperCase()}${data?.let { " $it" } ?: ""}\u0001")
  20. /** Sends an action to the given [target] (a user or a channel). */
  21. fun IrcClient.sendAction(target: String, action: String) = sendCtcp(target, "ACTION", action)
  22. /** Sends a private message to a user or channel. */
  23. fun IrcClient.sendMessage(target: String, message: String) = send("PRIVMSG $target :$message")
  24. /** Sends a message to register a user with the server. */
  25. internal fun IrcClient.sendUser(userName: String, realName: String) = send("USER $userName 0 * :$realName")
  26. /** Starts an authentication request. */
  27. internal fun IrcClient.sendAuthenticationMessage(data: String = "+") =send("AUTHENTICATE $data")