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.0KB

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