From 4602af4e446b1a4d6919c2258d8c9e9ed40330dc Mon Sep 17 00:00:00 2001 From: observer Date: Mon, 5 Oct 2026 12:47:17 +0100 Subject: [PATCH] Use new server.kt listener methods --- .../kotlin/com/shr4pnel/ferretirc/IrcClient.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/shr4pnel/ferretirc/IrcClient.kt b/src/main/kotlin/com/shr4pnel/ferretirc/IrcClient.kt index 73cd32a..696b155 100644 --- a/src/main/kotlin/com/shr4pnel/ferretirc/IrcClient.kt +++ b/src/main/kotlin/com/shr4pnel/ferretirc/IrcClient.kt @@ -1,5 +1,6 @@ package com.shr4pnel.ferretirc +import com.shr4pnel.ferretirc.irc.IRCChannel import com.shr4pnel.ferretirc.irc.Server import com.shr4pnel.ferretirc.irc.User import com.shr4pnel.ferretirc.net.Connection @@ -17,13 +18,13 @@ import org.slf4j.helpers.NOPLogger class IrcClient( hostname: String, port: Int, - var enableLogging: Boolean = false, + val enableLogging: Boolean = false, ) { init { KotlinLoggingConfiguration.logStartupMessage = false } - private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER) +// private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER) val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) lateinit var server: Server @@ -43,14 +44,15 @@ class IrcClient( } /** - * Send a message to the IRC server writer - * This is asynchronous and ordered + * Send a message to the IRC server message writer * @param message The client message to send to the server */ suspend fun queueMessage(message: ClientMessage) { connection.writer.outgoingMessages.send(message) } + suspend fun join(channel: IRCChannel) = queueMessage(ClientMessage.Join(channel)) + /** * Send a message to the IRC server writer * This is asynchronous and ordered @@ -85,7 +87,7 @@ class IrcClient( * @param predicate A function to filter a message based on its parameters * @see com.shr4pnel.ferretirc.IrcClient.waitForNext */ - suspend inline fun queueAndWaitForNext( + suspend inline fun queueMessageAndWaitForNext( message: ClientMessage, noinline predicate: (T) -> Boolean = { true }, ): T = server.waitForNext(T::class, predicate) { queueMessage(message) } @@ -96,10 +98,10 @@ class IrcClient( * @param action A function to execute after message buffer flow collection has begun * @see com.shr4pnel.ferretirc.IrcClient.waitForNext */ - suspend inline fun waitForNextAfterAction( + suspend inline fun waitForNextMessageAfterAction( noinline predicate: (T) -> Boolean = { true }, noinline action: suspend () -> Unit, - ): T = server.waitForNext(T::class, predicate, action) + ): T = server.waitForNext(T::class, predicate) { action() } suspend fun register( nick: String, @@ -119,6 +121,6 @@ class IrcClient( } add(ClientMessage.Cap.END()) }.toTypedArray() - queueMessages(*messages) + waitForNextMessageAfterAction { queueMessages(*messages) } } }