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.

ModeProcessor.kt 1.2KB

1234567891011121314151617181920212223242526272829303132
  1. package com.dmdirc.ktirc.messages.processors
  2. import com.dmdirc.ktirc.events.ModeChanged
  3. import com.dmdirc.ktirc.messages.RPL_CHANNELMODEIS
  4. import com.dmdirc.ktirc.messages.RPL_UMODEIS
  5. import com.dmdirc.ktirc.model.IrcMessage
  6. import com.dmdirc.ktirc.util.logger
  7. internal class ModeProcessor : MessageProcessor {
  8. private val log by logger()
  9. override val commands = arrayOf(RPL_CHANNELMODEIS, RPL_UMODEIS, "MODE")
  10. override fun process(message: IrcMessage): List<ModeChanged> {
  11. val isDiscovery = message.command == RPL_CHANNELMODEIS || message.command == RPL_UMODEIS
  12. val paramOffset = if (message.command == RPL_CHANNELMODEIS) 1 else 0
  13. if (message.params.size < paramOffset + 2) {
  14. log.warning { "Discarding MODE line with insufficient parameters: $message" }
  15. return emptyList()
  16. }
  17. return listOf(ModeChanged(
  18. message.metadata,
  19. target = String(message.params[paramOffset]),
  20. modes = String(message.params[paramOffset + 1]),
  21. arguments = message.params.takeLast(message.params.size - paramOffset - 2).map { String(it) }.toTypedArray(),
  22. discovered = isDiscovery))
  23. }
  24. }