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
      */
371
      */
372
     public void checkWho() {
372
     public void checkWho() {
373
         if (onChannel && sendWho) {
373
         if (onChannel && sendWho) {
374
-            server.getParser().sendRawMessage("WHO :" + channelInfo.getName());
374
+            channelInfo.sendWho();
375
         }
375
         }
376
     }
376
     }
377
 
377
 
578
      * current topic
578
      * current topic
579
      */
579
      */
580
     public void setTopic(final String topic) {
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
             host = "*!*@" + user.getClient().getHostname();
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
     /** {@inheritDoc} */
72
     /** {@inheritDoc} */

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

51
             final boolean isSilent, final CommandArguments args) {
51
             final boolean isSilent, final CommandArguments args) {
52
         final String line = args.getArgumentsAsString();
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
     @Override
59
     @Override
60
     public void execute(final InputWindow origin, final Server server,
60
     public void execute(final InputWindow origin, final Server server,
61
             final boolean isSilent, final CommandArguments args) {        
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
         if (args.getArguments().length < 2) {
63
         if (args.getArguments().length < 2) {
64
             showUsage(origin, isSilent, "ctcp", "<target> <type> [arguments]");
64
             showUsage(origin, isSilent, "ctcp", "<target> <type> [arguments]");
65
         } else {
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
             sendLine(origin, isSilent, "selfCTCP", args.getArguments()[0],
68
             sendLine(origin, isSilent, "selfCTCP", args.getArguments()[0],
69
                     args.getArgumentsAsString(1));
69
                     args.getArgumentsAsString(1));
70
         }
70
         }

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

59
         if (args.getArguments().length < 2) {
59
         if (args.getArguments().length < 2) {
60
             showUsage(origin, isSilent, "msg", "<target> <message>");
60
             showUsage(origin, isSilent, "msg", "<target> <message>");
61
         } else {
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
             sendLine(origin, isSilent, "selfMessage", args.getArguments()[0],
64
             sendLine(origin, isSilent, "selfMessage", args.getArguments()[0],
65
                     args.getArgumentsAsString(1));
65
                     args.getArgumentsAsString(1));
66
         }
66
         }

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

41
      */
41
      */
42
     String getName();
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
      * Retrieves the current topic or subject of this channel.
52
      * Retrieves the current topic or subject of this channel.
46
      *
53
      *
108
      */
115
      */
109
     void part(String reason);
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
      * Adjust the modes on this channel. This method should queue modes to be
124
      * Adjust the modes on this channel. This method should queue modes to be
113
      * sent in one go, according to the configuration/behaviour of the backend
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
      */
45
      */
46
     String getModes();
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
      * Alters the user modes of the local client. This method will queue modes
61
      * Alters the user modes of the local client. This method will queue modes
50
      * to be sent in one go, according to the behaviour/configuration of the
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
      */
278
      */
279
     void sendMessage(String target, String message);
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
      * Sends an action to the specified target.
290
      * Sends an action to the specified target.
283
      *
291
      *

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

389
 	 *
389
 	 *
390
 	 * @param sNewTopic New contents of topic
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
         /** {@inheritDoc} */
394
         /** {@inheritDoc} */
395
         @Override
395
         @Override
724
             myParser.partChannel(sName, reason);
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
             }
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
 		sendString("PRIVMSG " + target + " :" + message);
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
 	public void sendNotice(final String target, final String message) {
1524
 	public void sendNotice(final String target, final String message) {
1529
 		if (target == null || message == null) { return; }
1525
 		if (target == null || message == null) { return; }
1530
 		if (target.isEmpty()/* || sMessage.isEmpty()*/) { return; }
1526
 		if (target.isEmpty()/* || sMessage.isEmpty()*/) { return; }

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

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

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

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

Loading…
Cancel
Save