Add new client messages to API
This commit is contained in:
@@ -6,14 +6,11 @@ import com.shr4pnel.ferretirc.irc.User
|
||||
import com.shr4pnel.ferretirc.net.Connection
|
||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage
|
||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
|
||||
import io.github.oshai.kotlinlogging.slf4j.logger
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import org.slf4j.helpers.NOPLogger
|
||||
|
||||
class IrcClient(
|
||||
hostname: String,
|
||||
@@ -30,8 +27,7 @@ class IrcClient(
|
||||
lateinit var server: Server
|
||||
private set
|
||||
|
||||
lateinit var currentUser: User
|
||||
private set
|
||||
val user = User()
|
||||
|
||||
@PublishedApi
|
||||
internal val connection = Connection(hostname, port, scope, enableLogging)
|
||||
@@ -52,6 +48,9 @@ class IrcClient(
|
||||
}
|
||||
|
||||
suspend fun join(channel: IRCChannel) = queueMessage(ClientMessage.Join(channel))
|
||||
suspend fun quit(reason: String) = queueMessage(ClientMessage.Quit(reason))
|
||||
suspend fun part(channels: List<String>) = queueMessage(ClientMessage.Part(channels))
|
||||
suspend fun part(channel: String) = queueMessage(ClientMessage.Part(listOf(channel)))
|
||||
|
||||
/**
|
||||
* Send a message to the IRC server writer
|
||||
@@ -108,19 +107,17 @@ class IrcClient(
|
||||
realName: String? = null,
|
||||
password: String? = null,
|
||||
) {
|
||||
currentUser = User(nick, "") // TODO TEMP USER ASSIGNMENT
|
||||
user.nick = nick // TODO TEMP USER ASSIGNMENT
|
||||
val messages =
|
||||
buildList {
|
||||
if (!password.isNullOrEmpty()) add(ClientMessage.Pass(password))
|
||||
add(ClientMessage.Cap.LS())
|
||||
add(ClientMessage.Nick(nick))
|
||||
if (!realName.isNullOrEmpty()) {
|
||||
add(ClientMessage.User(nick, realName))
|
||||
} else {
|
||||
add(ClientMessage.User(nick, nick))
|
||||
}
|
||||
if (!realName.isNullOrEmpty()) add(ClientMessage.User(nick, realName))
|
||||
else add(ClientMessage.User(nick, nick))
|
||||
add(ClientMessage.Cap.END())
|
||||
}.toTypedArray()
|
||||
|
||||
waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user