Browse Source

More parser abstraction, issue 2736

tags/0.6.3m2a1
Chris Smith 15 years ago
parent
commit
c740256650

+ 2
- 2
src/com/dmdirc/Channel.java View File

@@ -371,7 +371,7 @@ public class Channel extends MessageTarget implements ConfigChangeListener,
371 371
      */
372 372
     public void checkWho() {
373 373
         if (onChannel && sendWho) {
374
-            server.getParser().sendRawMessage("WHO :" + channelInfo.getName());
374
+            channelInfo.sendWho();
375 375
         }
376 376
     }
377 377
 
@@ -578,6 +578,6 @@ public class Channel extends MessageTarget implements ConfigChangeListener,
578 578
      * current topic
579 579
      */
580 580
     public void setTopic(final String topic) {
581
-        server.getParser().sendRawMessage("TOPIC " + channelInfo.getName() + " :" + topic);
581
+        channelInfo.setTopic(topic);
582 582
     }
583 583
 }

+ 2
- 1
src/com/dmdirc/commandparser/commands/channel/Ban.java View File

@@ -65,7 +65,8 @@ public final class Ban extends ChannelCommand implements IntelligentCommand {
65 65
             host = "*!*@" + user.getClient().getHostname();
66 66
         }
67 67
         
68
-        server.getParser().sendRawMessage("MODE " + channel + " +b " + host);
68
+        channel.getChannelInfo().alterMode(true, 'b', host);
69
+        channel.getChannelInfo().flushModes();
69 70
     }
70 71
     
71 72
     /** {@inheritDoc} */

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Away.java View File

@@ -51,7 +51,7 @@ public final class Away extends ServerCommand {
51 51
             final boolean isSilent, final CommandArguments args) {
52 52
         final String line = args.getArgumentsAsString();
53 53
 
54
-        server.getParser().sendRawMessage("AWAY :" + line);
54
+        server.getParser().getLocalClient().setAway(line);
55 55
     }
56 56
     
57 57
     

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Back.java View File

@@ -59,7 +59,7 @@ public final class Back extends ServerCommand implements IntelligentCommand {
59 59
     @Override
60 60
     public void execute(final InputWindow origin, final Server server,
61 61
             final boolean isSilent, final CommandArguments args) {        
62
-        server.getParser().sendRawMessage("AWAY");
62
+        server.getParser().getLocalClient().setBack();
63 63
     }
64 64
     
65 65
     

+ 2
- 2
src/com/dmdirc/commandparser/commands/server/Ctcp.java View File

@@ -63,8 +63,8 @@ public final class Ctcp extends ServerCommand implements IntelligentCommand {
63 63
         if (args.getArguments().length < 2) {
64 64
             showUsage(origin, isSilent, "ctcp", "<target> <type> [arguments]");
65 65
         } else {
66
-            server.getParser().sendRawMessage("PRIVMSG " + args.getArguments()[0] + " :"
67
-                    + ((char) 1) + args.getArgumentsAsString(1) + ((char) 1));
66
+            server.getParser().sendCTCP(args.getArguments()[0],
67
+                    args.getArguments()[1], args.getArgumentsAsString(2));
68 68
             sendLine(origin, isSilent, "selfCTCP", args.getArguments()[0],
69 69
                     args.getArgumentsAsString(1));
70 70
         }

+ 2
- 2
src/com/dmdirc/commandparser/commands/server/Message.java View File

@@ -59,8 +59,8 @@ public final class Message extends ServerCommand implements IntelligentCommand,
59 59
         if (args.getArguments().length < 2) {
60 60
             showUsage(origin, isSilent, "msg", "<target> <message>");
61 61
         } else {
62
-            server.getParser().sendRawMessage("PRIVMSG " + args.getArguments()[0] + " :"
63
-                    + args.getArgumentsAsString(1));
62
+            server.getParser().sendMessage(args.getArguments()[0],
63
+                    args.getArgumentsAsString(1));
64 64
             sendLine(origin, isSilent, "selfMessage", args.getArguments()[0],
65 65
                     args.getArgumentsAsString(1));
66 66
         }

+ 12
- 0
src/com/dmdirc/parser/interfaces/ChannelInfo.java View File

@@ -41,6 +41,13 @@ public interface ChannelInfo {
41 41
      */
42 42
     String getName();
43 43
 
44
+    /**
45
+     * Changes the topic of this channel.
46
+     *
47
+     * @param topic This channel's new topic
48
+     */
49
+    void setTopic(String topic);
50
+
44 51
     /**
45 52
      * Retrieves the current topic or subject of this channel.
46 53
      *
@@ -108,6 +115,11 @@ public interface ChannelInfo {
108 115
      */
109 116
     void part(String reason);
110 117
 
118
+    /**
119
+     * Sends a WHO request to get details about people who are on the channel.
120
+     */
121
+    void sendWho();
122
+
111 123
     /**
112 124
      * Adjust the modes on this channel. This method should queue modes to be
113 125
      * sent in one go, according to the configuration/behaviour of the backend

+ 12
- 0
src/com/dmdirc/parser/interfaces/LocalClientInfo.java View File

@@ -45,6 +45,18 @@ public interface LocalClientInfo extends ClientInfo {
45 45
      */
46 46
     String getModes();
47 47
 
48
+    /**
49
+     * Marks the local client as being away.
50
+     *
51
+     * @param reason The reason for being away
52
+     */
53
+    void setAway(String reason);
54
+
55
+    /**
56
+     * Marks the local client as being back (not away).
57
+     */
58
+    void setBack();
59
+
48 60
     /**
49 61
      * Alters the user modes of the local client. This method will queue modes
50 62
      * to be sent in one go, according to the behaviour/configuration of the

+ 8
- 0
src/com/dmdirc/parser/interfaces/Parser.java View File

@@ -278,6 +278,14 @@ public interface Parser extends Runnable {
278 278
      */
279 279
     void sendMessage(String target, String message);
280 280
 
281
+    /**
282
+     * Sends a notice to the specified target.
283
+     *
284
+     * @param target The target to send the notice to
285
+     * @param message The message to be sent
286
+     */
287
+    void sendNotice(String target, String message);
288
+
281 289
     /**
282 290
      * Sends an action to the specified target.
283 291
      *

+ 13
- 1
src/com/dmdirc/parser/irc/IRCChannelInfo.java View File

@@ -389,7 +389,7 @@ public class IRCChannelInfo implements ChannelInfo {
389 389
 	 *
390 390
 	 * @param sNewTopic New contents of topic
391 391
 	 */	
392
-	protected void setTopic(final String sNewTopic) { sTopic = sNewTopic; }
392
+	protected void setInternalTopic(final String sNewTopic) { sTopic = sNewTopic; }
393 393
 	
394 394
         /** {@inheritDoc} */
395 395
         @Override
@@ -724,5 +724,17 @@ public class IRCChannelInfo implements ChannelInfo {
724 724
             myParser.partChannel(sName, reason);
725 725
         }
726 726
 
727
+    /** {@inheritDoc} */
728
+    @Override
729
+    public void setTopic(final String topic) {
730
+        myParser.sendRawMessage("TOPIC " + sName + " :" + topic);
731
+    }
732
+
733
+    /** {@inheritDoc} */
734
+    @Override
735
+    public void sendWho() {
736
+        myParser.sendRawMessage("WHO " + sName);
737
+    }
738
+
727 739
 }
728 740
 

+ 12
- 0
src/com/dmdirc/parser/irc/IRCClientInfo.java View File

@@ -402,4 +402,16 @@ public class IRCClientInfo implements LocalClientInfo {
402 402
             }
403 403
         }
404 404
 
405
+    /** {@inheritDoc} */
406
+    @Override
407
+    public void setAway(String reason) {
408
+        myParser.sendRawMessage("AWAY :" + reason);
409
+    }
410
+
411
+    /** {@inheritDoc} */
412
+    @Override
413
+    public void setBack() {
414
+        myParser.sendRawMessage("AWAY");
415
+    }
416
+
405 417
 }

+ 2
- 6
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -1519,12 +1519,8 @@ public class IRCParser implements SecureParser, Runnable {
1519 1519
 		sendString("PRIVMSG " + target + " :" + message);
1520 1520
 	}
1521 1521
 
1522
-	/**
1523
-	 * Send a notice message to a target.
1524
-	 *
1525
-	 * @param target Target
1526
-	 * @param message Message to send
1527
-	 */
1522
+	/** {@inheritDoc} */
1523
+        @Override
1528 1524
 	public void sendNotice(final String target, final String message) {
1529 1525
 		if (target == null || message == null) { return; }
1530 1526
 		if (target.isEmpty()/* || sMessage.isEmpty()*/) { return; }

+ 2
- 2
src/com/dmdirc/parser/irc/ProcessTopic.java View File

@@ -41,7 +41,7 @@ public class ProcessTopic extends IRCProcessor {
41 41
 		if (sParam.equals("332")) {
42 42
 			iChannel = getChannel(token[3]);
43 43
 			if (iChannel == null) { return; }
44
-			iChannel.setTopic(token[token.length-1]);
44
+			iChannel.setInternalTopic(token[token.length-1]);
45 45
 		} else if (sParam.equals("333")) {
46 46
 			if (token.length > 3) {
47 47
 				iChannel = getChannel(token[3]);
@@ -64,7 +64,7 @@ public class ProcessTopic extends IRCProcessor {
64 64
 			iChannel.setTopicTime(System.currentTimeMillis() / 1000);
65 65
 			if (token[0].charAt(0) == ':') { token[0] = token[0].substring(1); }
66 66
 			iChannel.setTopicUser(token[0]);
67
-			iChannel.setTopic(token[token.length-1]);
67
+			iChannel.setInternalTopic(token[token.length-1]);
68 68
 			callChannelTopic(iChannel,false);
69 69
 		}
70 70
 	}

+ 1
- 1
test/com/dmdirc/parser/irc/ChannelInfoTest.java View File

@@ -74,7 +74,7 @@ public class ChannelInfoTest {
74 74
 
75 75
     @Test
76 76
     public void testTopic() {
77
-        ci.setTopic("abcdef");
77
+        ci.setInternalTopic("abcdef");
78 78
 
79 79
         assertEquals("abcdef", ci.getTopic());
80 80
     }

Loading…
Cancel
Save