|
@@ -18,13 +18,14 @@ internal interface MessageEmitter {
|
18
|
18
|
}
|
19
|
19
|
|
20
|
20
|
internal class MessageHandler(
|
21
|
|
- private val processors: List<MessageProcessor>,
|
|
21
|
+ processors: List<MessageProcessor>,
|
22
|
22
|
private val mutators: List<EventMutator>,
|
23
|
23
|
private val handlers: List<EventHandler>) : MessageEmitter {
|
24
|
24
|
|
25
|
25
|
private val log by logger()
|
26
|
26
|
|
27
|
27
|
private val emitters = mutableListOf<(IrcEvent) -> Unit>()
|
|
28
|
+ private val processorMap = processors.flatMap { it.commands.map { c -> c to it } }.toMap()
|
28
|
29
|
|
29
|
30
|
suspend fun processMessages(ircClient: IrcClient, messages: ReceiveChannel<IrcMessage>) {
|
30
|
31
|
for (message in messages) {
|
|
@@ -54,7 +55,7 @@ internal class MessageHandler(
|
54
|
55
|
}
|
55
|
56
|
|
56
|
57
|
private fun IrcMessage.toEvents() = this.getProcessor()?.process(this) ?: emptyList()
|
57
|
|
- private fun IrcMessage.getProcessor() = processors.firstOrNull { it.commands.contains(command) } ?: run {
|
|
58
|
+ private fun IrcMessage.getProcessor() = processorMap[command] ?: run {
|
58
|
59
|
log.warning { "No processor found for $command" }
|
59
|
60
|
null
|
60
|
61
|
}
|