Browse Source

Support for receiving MOTD lines

tags/v0.8.0
Chris Smith 5 years ago
parent
commit
47abcf78bb

+ 1
- 0
CHANGELOG View File

@@ -1,6 +1,7 @@
1 1
 vNEXT (in development)
2 2
 
3 3
  * Added support for SCRAM-SHA-1 and SCRAM-SHA-256 SASL mechanisms
4
+ * Added MotdLineReceived event
4 5
 
5 6
 v0.7.0
6 7
 

+ 3
- 0
src/main/kotlin/com/dmdirc/ktirc/events/Events.kt View File

@@ -95,6 +95,9 @@ class ServerCapabilitiesAcknowledged(time: LocalDateTime, val capabilities: Map<
95 95
 /** Raised when the server has finished sending us capabilities. */
96 96
 class ServerCapabilitiesFinished(time: LocalDateTime) : IrcEvent(time)
97 97
 
98
+/** Raised when a line of the Message Of the Day has been received. */
99
+class MotdLineReceived(time: LocalDateTime, val line: String, val first: Boolean = false) : IrcEvent(time)
100
+
98 101
 /** Raised when a Message Of the Day has completed. */
99 102
 class MotdFinished(time: LocalDateTime, val missing: Boolean = false) : IrcEvent(time)
100 103
 

+ 4
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/MotdProcessor.kt View File

@@ -1,14 +1,17 @@
1 1
 package com.dmdirc.ktirc.messages
2 2
 
3 3
 import com.dmdirc.ktirc.events.MotdFinished
4
+import com.dmdirc.ktirc.events.MotdLineReceived
4 5
 import com.dmdirc.ktirc.model.IrcMessage
5 6
 
6 7
 internal class MotdProcessor : MessageProcessor {
7 8
 
8
-    override val commands = arrayOf(ERR_NOMOTD, RPL_ENDOFMOTD)
9
+    override val commands = arrayOf(ERR_NOMOTD, RPL_MOTDSTART, RPL_MOTD, RPL_ENDOFMOTD)
9 10
 
10 11
     override fun process(message: IrcMessage) = sequence {
11 12
         when (message.command) {
13
+            RPL_MOTDSTART -> yield(MotdLineReceived(message.time, String(message.params[1]), true))
14
+            RPL_MOTD -> yield(MotdLineReceived(message.time, String(message.params[1])))
12 15
             ERR_NOMOTD -> yield(MotdFinished(message.time, missing = true))
13 16
             RPL_ENDOFMOTD -> yield(MotdFinished(message.time))
14 17
         }

+ 2
- 0
src/main/kotlin/com/dmdirc/ktirc/messages/NumericConstants.kt View File

@@ -8,6 +8,8 @@ internal const val RPL_ISUPPORT = "005"
8 8
 internal const val RPL_UMODEIS = "221"
9 9
 
10 10
 internal const val RPL_CHANNELMODEIS = "324"
11
+internal const val RPL_MOTD = "372"
12
+internal const val RPL_MOTDSTART = "375"
11 13
 internal const val RPL_ENDOFMOTD = "376"
12 14
 
13 15
 internal const val ERR_NOMOTD = "422"

+ 35
- 3
src/test/kotlin/com/dmdirc/ktirc/messages/MotdProcessorTest.kt View File

@@ -2,6 +2,7 @@ package com.dmdirc.ktirc.messages
2 2
 
3 3
 import com.dmdirc.ktirc.TestConstants
4 4
 import com.dmdirc.ktirc.events.MotdFinished
5
+import com.dmdirc.ktirc.events.MotdLineReceived
5 6
 import com.dmdirc.ktirc.model.IrcMessage
6 7
 import com.dmdirc.ktirc.params
7 8
 import com.dmdirc.ktirc.util.currentTimeProvider
@@ -17,7 +18,7 @@ internal class MotdProcessorTest {
17 18
     }
18 19
 
19 20
     @Test
20
-    fun `MotdProcessor raises motdFinished when not found numeric received`() {
21
+    fun `raises MotdFinished when not found numeric received`() {
21 22
         val events = MotdProcessor().process(
22 23
                 IrcMessage(emptyMap(), "the.gibson".toByteArray(), "422", params("MOTD missing")))
23 24
         assertEquals(1, events.size)
@@ -28,7 +29,7 @@ internal class MotdProcessorTest {
28 29
     }
29 30
 
30 31
     @Test
31
-    fun `MotdProcessor raises motdFinished when MOTD finishes normally`() {
32
+    fun `raises MotdFinished when MOTD finishes normally`() {
32 33
         val events = MotdProcessor().process(
33 34
                 IrcMessage(emptyMap(), "the.gibson".toByteArray(), "376", params("acidBurn", "End of /MOTD command.")))
34 35
         assertEquals(1, events.size)
@@ -38,4 +39,35 @@ internal class MotdProcessorTest {
38 39
         assertFalse(event.missing)
39 40
     }
40 41
 
41
-}
42
+    @Test
43
+    fun `raises MotdLineReceived when start of MOTD received`() {
44
+        val events = MotdProcessor().process(
45
+                IrcMessage(emptyMap(), "the.gibson".toByteArray(), "375", params("acidBurn", "- the.gibson MOTD -")))
46
+        assertEquals(1, events.size)
47
+
48
+        val event = events[0] as MotdLineReceived
49
+        assertEquals(TestConstants.time, event.time)
50
+        assertEquals("- the.gibson MOTD -", event.line)
51
+        assertTrue(event.first)
52
+    }
53
+
54
+    @Test
55
+    fun `raises MotdLineReceived when line of MOTD received`() {
56
+        val events = MotdProcessor().process(
57
+                IrcMessage(emptyMap(), "the.gibson".toByteArray(), "372", params("acidBurn", "Hack the planet!")))
58
+        assertEquals(1, events.size)
59
+
60
+        val event = events[0] as MotdLineReceived
61
+        assertEquals(TestConstants.time, event.time)
62
+        assertEquals("Hack the planet!", event.line)
63
+        assertFalse(event.first)
64
+    }
65
+
66
+    @Test
67
+    fun `raises nothing for unsupported events`() {
68
+        val events = MotdProcessor().process(
69
+                IrcMessage(emptyMap(), "the.gibson".toByteArray(), "NOTICE", params("acidBurn", "Hi")))
70
+        assertEquals(0, events.size)
71
+    }
72
+
73
+}

Loading…
Cancel
Save