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 9.5KB

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