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.

Events.kt 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package com.dmdirc.ktirc.events
  2. import com.dmdirc.ktirc.model.Capability
  3. import com.dmdirc.ktirc.model.ConnectionError
  4. import com.dmdirc.ktirc.model.ServerFeatureMap
  5. import com.dmdirc.ktirc.model.User
  6. import java.time.LocalDateTime
  7. /**
  8. * Metadata associated with an event.
  9. *
  10. * @param time The best-guess time at which the event occurred.
  11. * @param batchId The ID of the batch this event is part of, if any.
  12. * @param messageId The unique ID of this message, if any.
  13. */
  14. data class EventMetadata(val time: LocalDateTime, val batchId: String? = null, val messageId: String? = null)
  15. /** Base class for all events. */
  16. sealed class IrcEvent(val metadata: EventMetadata) {
  17. /** The time at which the event occurred. */
  18. @Deprecated("Moved to metadata; to be removed post-1.0.0", replaceWith = ReplaceWith("metadata.time"))
  19. val time: LocalDateTime
  20. get() = metadata.time
  21. }
  22. /** Raised when a connection to the server is being established. */
  23. class ServerConnecting(metadata: EventMetadata) : IrcEvent(metadata)
  24. /** Raised when the connection to the server has been established. The server will not be ready for use yet. */
  25. class ServerConnected(metadata: EventMetadata) : IrcEvent(metadata)
  26. /** Raised when the connection to the server has ended. */
  27. class ServerDisconnected(metadata: EventMetadata) : IrcEvent(metadata)
  28. /** Raised when an error occurred trying to connect. */
  29. class ServerConnectionError(metadata: EventMetadata, val error: ConnectionError, val details: String?) : IrcEvent(metadata)
  30. /** Raised when the server is ready for use. */
  31. class ServerReady(metadata: EventMetadata) : IrcEvent(metadata)
  32. /** Raised when the server initially welcomes us to the IRC network. */
  33. class ServerWelcome(metadata: EventMetadata, val server: String, val localNick: String) : IrcEvent(metadata)
  34. /** Raised when the features supported by the server have changed. This may occur numerous times. */
  35. class ServerFeaturesUpdated(metadata: EventMetadata, val serverFeatures: ServerFeatureMap) : IrcEvent(metadata)
  36. /** Raised whenever a PING is received from the server. */
  37. class PingReceived(metadata: EventMetadata, val nonce: ByteArray) : IrcEvent(metadata)
  38. /** Raised when a user joins a channel. */
  39. class ChannelJoined(metadata: EventMetadata, val user: User, val channel: String) : IrcEvent(metadata)
  40. /** Raised when a user leaves a channel. */
  41. class ChannelParted(metadata: EventMetadata, val user: User, val channel: String, val reason: String = "") : IrcEvent(metadata)
  42. /** Raised when a [victim] is kicked from a channel. */
  43. class ChannelUserKicked(metadata: EventMetadata, val user: User, val channel: String, val victim: String, val reason: String = "") : IrcEvent(metadata)
  44. /** Raised when a user quits, and is in a channel. */
  45. class ChannelQuit(metadata: EventMetadata, val user: User, val channel: String, val reason: String = "") : IrcEvent(metadata)
  46. /** Raised when a user changes nickname, and is in a channel. */
  47. class ChannelNickChanged(metadata: EventMetadata, val user: User, val channel: String, val newNick: String) : IrcEvent(metadata)
  48. /** Raised when a batch of the channel's member list has been received. More batches may follow. */
  49. class ChannelNamesReceived(metadata: EventMetadata, val channel: String, val names: List<String>) : IrcEvent(metadata)
  50. /** Raised when the entirety of the channel's member list has been received. */
  51. class ChannelNamesFinished(metadata: EventMetadata, val channel: String) : IrcEvent(metadata)
  52. /** Raised when a channel topic is discovered (not changed). Usually followed by [ChannelTopicMetadataDiscovered] if the [topic] is non-null. */
  53. class ChannelTopicDiscovered(metadata: EventMetadata, val channel: String, val topic: String?) : IrcEvent(metadata)
  54. /** Raised when a channel topic's metadata is discovered. */
  55. class ChannelTopicMetadataDiscovered(metadata: EventMetadata, val channel: String, val user: User, val setTime: LocalDateTime) : IrcEvent(metadata)
  56. /**
  57. * Raised when a channel's topic is changed.
  58. *
  59. * If the topic has been unset (cleared), [topic] will be `null`
  60. */
  61. class ChannelTopicChanged(metadata: EventMetadata, val user: User, val channel: String, val topic: String?) : IrcEvent(metadata)
  62. /** Raised when a message is received. */
  63. class MessageReceived(metadata: EventMetadata, val user: User, val target: String, val message: String) : IrcEvent(metadata) {
  64. /** The message ID of this message. */
  65. @Deprecated("Moved to metadata; to be removed post-1.0.0", replaceWith = ReplaceWith("metadata.messageId"))
  66. val messageId: String?
  67. get() = metadata.messageId
  68. }
  69. /**
  70. * Raised when a notice is received.
  71. *
  72. * The [user] may in fact be a server, or have a nickname of `*` while connecting.
  73. */
  74. class NoticeReceived(metadata: EventMetadata, val user: User, val target: String, val message: String) : IrcEvent(metadata)
  75. /** Raised when an action is received. */
  76. class ActionReceived(metadata: EventMetadata, val user: User, val target: String, val action: String) : IrcEvent(metadata) {
  77. /** The message ID of this action. */
  78. @Deprecated("Moved to metadata; to be removed post-1.0.0", replaceWith = ReplaceWith("metadata.messageId"))
  79. val messageId: String?
  80. get() = metadata.messageId
  81. }
  82. /** Raised when a CTCP is received. */
  83. class CtcpReceived(metadata: EventMetadata, val user: User, val target: String, val type: String, val content: String) : IrcEvent(metadata)
  84. /** Raised when a CTCP reply is received. */
  85. class CtcpReplyReceived(metadata: EventMetadata, val user: User, val target: String, val type: String, val content: String) : IrcEvent(metadata)
  86. /** Raised when a user quits. */
  87. class UserQuit(metadata: EventMetadata, val user: User, val reason: String = "") : IrcEvent(metadata)
  88. /** Raised when a user changes nickname. */
  89. class UserNickChanged(metadata: EventMetadata, val user: User, val newNick: String) : IrcEvent(metadata)
  90. /** Raised when a user changes hostname. */
  91. class UserHostChanged(metadata: EventMetadata, val user: User, val newIdent: String, val newHost: String) : IrcEvent(metadata)
  92. /**
  93. * Raised when a user's account changes (i.e., they auth'd or deauth'd with services).
  94. *
  95. * This event is only raised if the server supports the `account-notify` capability.
  96. */
  97. class UserAccountChanged(metadata: EventMetadata, val user: User, val newAccount: String?) : IrcEvent(metadata)
  98. /** Raised when available server capabilities are received. More batches may follow. */
  99. class ServerCapabilitiesReceived(metadata: EventMetadata, val capabilities: Map<Capability, String>) : IrcEvent(metadata)
  100. /** Raised when our requested capabilities are acknowledged. More batches may follow. */
  101. class ServerCapabilitiesAcknowledged(metadata: EventMetadata, val capabilities: Map<Capability, String>) : IrcEvent(metadata)
  102. /** Raised when the server has finished sending us capabilities. */
  103. class ServerCapabilitiesFinished(metadata: EventMetadata) : IrcEvent(metadata)
  104. /** Raised when a line of the Message Of the Day has been received. */
  105. class MotdLineReceived(metadata: EventMetadata, val line: String, val first: Boolean = false) : IrcEvent(metadata)
  106. /** Raised when a Message Of the Day has completed. */
  107. class MotdFinished(metadata: EventMetadata, val missing: Boolean = false) : IrcEvent(metadata)
  108. /**
  109. * Raised when a mode change occurs.
  110. *
  111. * If [discovered] is true then the event is in response to the server providing the full set of modes on the target,
  112. * and the given modes are thus exhaustive. Otherwise, the modes are a sequence of changes to apply to the existing
  113. * state.
  114. */
  115. class ModeChanged(metadata: EventMetadata, val target: String, val modes: String, val arguments: Array<String>, val discovered: Boolean = false) : IrcEvent(metadata)
  116. /** Raised when an AUTHENTICATION message is received. [argument] is `null` if the server sent an empty reply ("+") */
  117. class AuthenticationMessage(metadata: EventMetadata, val argument: String?) : IrcEvent(metadata)
  118. /** Raised when a SASL attempt finishes, successfully or otherwise. */
  119. class SaslFinished(metadata: EventMetadata, var success: Boolean) : IrcEvent(metadata)
  120. /** Raised when the server says our SASL mechanism isn't available, but gives us a list of others. */
  121. class SaslMechanismNotAvailableError(metadata: EventMetadata, var mechanisms: Collection<String>) : IrcEvent(metadata)
  122. /** Indicates a batch of messages has begun. */
  123. class BatchStarted(metadata: EventMetadata, val referenceId: String, val batchType: String, val params: Array<String>) : IrcEvent(metadata)
  124. /** Indicates a batch of messages has finished. */
  125. class BatchFinished(metadata: EventMetadata, val referenceId: String) : IrcEvent(metadata)
  126. /** A batch of events that should be handled together. */
  127. class BatchReceived(metadata: EventMetadata, val type: String, val params: Array<String>, val events: List<IrcEvent>) : IrcEvent(metadata)