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.

EventUtils.kt 1.5KB

123456789101112131415161718192021222324252627282930313233
  1. package com.dmdirc.ktirc.events
  2. import com.dmdirc.ktirc.IrcClient
  3. import com.dmdirc.ktirc.messages.sendMessage
  4. import com.dmdirc.ktirc.model.ServerFeature
  5. import com.dmdirc.ktirc.model.asUser
  6. internal fun ChannelNamesReceived.toModesAndUsers(client: IrcClient) = sequence {
  7. val modePrefixes = client.serverState.features[ServerFeature.ModePrefixes]!!
  8. for (user in names) {
  9. user.takeWhile { modePrefixes.isPrefix(it) }.let { prefix ->
  10. yield(modePrefixes.getModes(prefix) to user.substring(prefix.length).asUser())
  11. }
  12. }
  13. }.toList()
  14. /**
  15. * Replies in the appropriate place to a message received.
  16. *
  17. * Messages sent direct to the client will be responded to in direct message back; messages sent to a channel
  18. * will be replied to in the channel. If [prefixWithNickname] is `true`, channel messages will be prefixed
  19. * with the other user's nickname (separated from the message by a colon and space).
  20. *
  21. * If the given [message] has a [com.dmdirc.ktirc.model.MessageTag.MessageId] tag then the reply will include
  22. * the message ID to tell other IRCv3 capable clients what message is being replied to.
  23. */
  24. fun IrcClient.reply(message: MessageReceived, response: String, prefixWithNickname: Boolean = false) {
  25. if (caseMapping.areEquivalent(message.target, serverState.localNickname)) {
  26. sendMessage(message.user.nickname, response, message.messageId)
  27. } else {
  28. sendMessage(message.target, if (prefixWithNickname) "${message.user.nickname}: $response" else response, message.messageId)
  29. }
  30. }