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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /** Base class for all events. */
  8. sealed class IrcEvent(val time: LocalDateTime)
  9. /** Raised when a connection to the server is being established. */
  10. class ServerConnecting(time: LocalDateTime) : IrcEvent(time)
  11. /** Raised when the connection to the server has been established. The server will not be ready for use yet. */
  12. class ServerConnected(time: LocalDateTime) : IrcEvent(time)
  13. /** Raised when the connection to the server has ended. */
  14. class ServerDisconnected(time: LocalDateTime) : IrcEvent(time)
  15. /** Raised when an error occurred trying to connect. */
  16. class ServerConnectionError(time: LocalDateTime, val error: ConnectionError, val details: String?) : IrcEvent(time)
  17. /** Raised when the server is ready for use. */
  18. class ServerReady(time: LocalDateTime) : IrcEvent(time)
  19. /** Raised when the server initially welcomes us to the IRC network. */
  20. class ServerWelcome(time: LocalDateTime, val server: String, val localNick: String) : IrcEvent(time)
  21. /** Raised when the features supported by the server have changed. This may occur numerous times. */
  22. class ServerFeaturesUpdated(time: LocalDateTime, val serverFeatures: ServerFeatureMap) : IrcEvent(time)
  23. /** Raised whenever a PING is received from the server. */
  24. class PingReceived(time: LocalDateTime, val nonce: ByteArray) : IrcEvent(time)
  25. /** Raised when a user joins a channel. */
  26. class ChannelJoined(time: LocalDateTime, val user: User, val channel: String) : IrcEvent(time)
  27. /** Raised when a user leaves a channel. */
  28. class ChannelParted(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
  29. /** Raised when a [victim] is kicked from a channel. */
  30. class ChannelUserKicked(time: LocalDateTime, val user: User, val channel: String, val victim: String, val reason: String = "") : IrcEvent(time)
  31. /** Raised when a user quits, and is in a channel. */
  32. class ChannelQuit(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
  33. /** Raised when a user changes nickname, and is in a channel. */
  34. class ChannelNickChanged(time: LocalDateTime, val user: User, val channel: String, val newNick: String) : IrcEvent(time)
  35. /** Raised when a batch of the channel's member list has been received. More batches may follow. */
  36. class ChannelNamesReceived(time: LocalDateTime, val channel: String, val names: List<String>) : IrcEvent(time)
  37. /** Raised when the entirety of the channel's member list has been received. */
  38. class ChannelNamesFinished(time: LocalDateTime, val channel: String) : IrcEvent(time)
  39. /** Raised when a channel topic is discovered (not changed). Usually followed by [ChannelTopicMetadataDiscovered]. */
  40. class ChannelTopicDiscovered(time: LocalDateTime, val channel: String, val topic: String) : IrcEvent(time)
  41. /** Raised when a channel topic's metadata is discovered. */
  42. class ChannelTopicMetadataDiscovered(time: LocalDateTime, val channel: String, val user: User, val setTime: LocalDateTime) : IrcEvent(time)
  43. /** Raised when a message is received. */
  44. class MessageReceived(time: LocalDateTime, val user: User, val target: String, val message: String, val messageId: String? = null) : IrcEvent(time)
  45. /**
  46. * Raised when a notice is received.
  47. *
  48. * The [user] may in fact be a server, or have a nickname of `*` while connecting.
  49. */
  50. class NoticeReceived(time: LocalDateTime, val user: User, val target: String, val message: String) : IrcEvent(time)
  51. /** Raised when an action is received. */
  52. class ActionReceived(time: LocalDateTime, val user: User, val target: String, val action: String, val messageId: String? = null) : IrcEvent(time)
  53. /** Raised when a CTCP is received. */
  54. class CtcpReceived(time: LocalDateTime, val user: User, val target: String, val type: String, val content: String) : IrcEvent(time)
  55. /** Raised when a CTCP reply is received. */
  56. class CtcpReplyReceived(time: LocalDateTime, val user: User, val target: String, val type: String, val content: String) : IrcEvent(time)
  57. /** Raised when a user quits. */
  58. class UserQuit(time: LocalDateTime, val user: User, val reason: String = "") : IrcEvent(time)
  59. /** Raised when a user changes nickname. */
  60. class UserNickChanged(time: LocalDateTime, val user: User, val newNick: String) : IrcEvent(time)
  61. /**
  62. * Raised when a user's account changes (i.e., they auth'd or deauth'd with services).
  63. *
  64. * This event is only raised if the server supports the `account-notify` capability.
  65. */
  66. class UserAccountChanged(time: LocalDateTime, val user: User, val newAccount: String?) : IrcEvent(time)
  67. /** Raised when available server capabilities are received. More batches may follow. */
  68. class ServerCapabilitiesReceived(time: LocalDateTime, val capabilities: Map<Capability, String>) : IrcEvent(time)
  69. /** Raised when our requested capabilities are acknowledged. More batches may follow. */
  70. class ServerCapabilitiesAcknowledged(time: LocalDateTime, val capabilities: Map<Capability, String>) : IrcEvent(time)
  71. /** Raised when the server has finished sending us capabilities. */
  72. class ServerCapabilitiesFinished(time: LocalDateTime) : IrcEvent(time)
  73. /** Raised when a line of the Message Of the Day has been received. */
  74. class MotdLineReceived(time: LocalDateTime, val line: String, val first: Boolean = false) : IrcEvent(time)
  75. /** Raised when a Message Of the Day has completed. */
  76. class MotdFinished(time: LocalDateTime, val missing: Boolean = false) : IrcEvent(time)
  77. /**
  78. * Raised when a mode change occurs.
  79. *
  80. * If [discovered] is true then the event is in response to the server providing the full set of modes on the target,
  81. * and the given modes are thus exhaustive. Otherwise, the modes are a sequence of changes to apply to the existing
  82. * state.
  83. */
  84. class ModeChanged(time: LocalDateTime, val target: String, val modes: String, val arguments: Array<String>, val discovered: Boolean = false) : IrcEvent(time)
  85. /** Raised when an AUTHENTICATION message is received. [argument] is `null` if the server sent an empty reply ("+") */
  86. class AuthenticationMessage(time: LocalDateTime, val argument: String?) : IrcEvent(time)
  87. /** Raised when a SASL attempt finishes, successfully or otherwise. */
  88. class SaslFinished(time: LocalDateTime, var success: Boolean) : IrcEvent(time)
  89. /** Raised when the server says our SASL mechanism isn't available, but gives us a list of others. */
  90. class SaslMechanismNotAvailableError(time: LocalDateTime, var mechanisms: Collection<String>) : IrcEvent(time)