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.Connection
|
||||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage
|
import com.shr4pnel.ferretirc.net.messages.ClientMessage
|
||||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
|
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
|
||||||
import io.github.oshai.kotlinlogging.slf4j.logger
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import org.slf4j.helpers.NOPLogger
|
|
||||||
|
|
||||||
class IrcClient(
|
class IrcClient(
|
||||||
hostname: String,
|
hostname: String,
|
||||||
@@ -30,8 +27,7 @@ class IrcClient(
|
|||||||
lateinit var server: Server
|
lateinit var server: Server
|
||||||
private set
|
private set
|
||||||
|
|
||||||
lateinit var currentUser: User
|
val user = User()
|
||||||
private set
|
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal val connection = Connection(hostname, port, scope, enableLogging)
|
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 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
|
* Send a message to the IRC server writer
|
||||||
@@ -108,19 +107,17 @@ class IrcClient(
|
|||||||
realName: String? = null,
|
realName: String? = null,
|
||||||
password: String? = null,
|
password: String? = null,
|
||||||
) {
|
) {
|
||||||
currentUser = User(nick, "") // TODO TEMP USER ASSIGNMENT
|
user.nick = nick // TODO TEMP USER ASSIGNMENT
|
||||||
val messages =
|
val messages =
|
||||||
buildList {
|
buildList {
|
||||||
if (!password.isNullOrEmpty()) add(ClientMessage.Pass(password))
|
if (!password.isNullOrEmpty()) add(ClientMessage.Pass(password))
|
||||||
add(ClientMessage.Cap.LS())
|
add(ClientMessage.Cap.LS())
|
||||||
add(ClientMessage.Nick(nick))
|
add(ClientMessage.Nick(nick))
|
||||||
if (!realName.isNullOrEmpty()) {
|
if (!realName.isNullOrEmpty()) add(ClientMessage.User(nick, realName))
|
||||||
add(ClientMessage.User(nick, realName))
|
else add(ClientMessage.User(nick, nick))
|
||||||
} else {
|
|
||||||
add(ClientMessage.User(nick, nick))
|
|
||||||
}
|
|
||||||
add(ClientMessage.Cap.END())
|
add(ClientMessage.Cap.END())
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
|
|
||||||
waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) }
|
waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user