瀏覽代碼

* Added me and me/0 commands

* Updated command parser to create a new set of arguments for passing to Commands
* Updated Command to include a protected method to implode arguments
* Updated Quit command to actually use the user supplied method
* Updated Channel class to include a method to send an action

git-svn-id: http://svn.dmdirc.com/trunk@190 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 年之前
父節點
當前提交
7f5d6f7183

+ 5
- 0
src/uk/org/ownage/dmdirc/Channel.java 查看文件

@@ -79,6 +79,11 @@ public class Channel implements IRCParser.IChannelMessage,
79 79
         frame.addLine("> "+line);
80 80
     }
81 81
     
82
+    public void sendAction(String action) {
83
+        channelInfo.sendAction(action);
84
+        frame.addLine("*> "+action);
85
+    }    
86
+    
82 87
     public void onChannelMessage(IRCParser tParser, ChannelInfo cChannel,
83 88
             ChannelClientInfo cChannelClient, String sMessage, String sHost) {
84 89
         if (cChannelClient != null) {

+ 17
- 0
src/uk/org/ownage/dmdirc/commandparser/Command.java 查看文件

@@ -91,4 +91,21 @@ public abstract class Command {
91 91
         return name+" "+arguments+" - "+description;
92 92
     }
93 93
     
94
+    /**
95
+     * Implodes the given list of arguments
96
+     * @param args The arguments to implode
97
+     * @return A string containing each argument seperated by a space
98
+     */
99
+    protected String implodeArgs(String... args) {
100
+        String res = "";
101
+        for (int i = 0; i < args.length; i++) {
102
+            if (res.equals("")) {
103
+                res = args[i];
104
+            } else {
105
+                res = res.concat(" "+args[i]);
106
+            }
107
+        }
108
+        return res;
109
+    }
110
+    
94 111
 }

+ 3
- 0
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java 查看文件

@@ -25,6 +25,7 @@ package uk.org.ownage.dmdirc.commandparser;
25 25
 import java.util.Vector;
26 26
 import uk.org.ownage.dmdirc.commandparser.commands.*;
27 27
 import uk.org.ownage.dmdirc.commandparser.commands.server.*;
28
+import uk.org.ownage.dmdirc.commandparser.commands.channel.*;
28 29
 
29 30
 /**
30 31
  * The command manager creates and manages a single instance of all commands,
@@ -50,6 +51,8 @@ public class CommandManager {
50 51
         if (channelCommands == null) {
51 52
             channelCommands = new Vector<Command>(0,1);
52 53
             
54
+            channelCommands.add(new Me());
55
+            channelCommands.add(new MeEmpty());
53 56
         }
54 57
         
55 58
         for (Command com : channelCommands) {

+ 13
- 5
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java 查看文件

@@ -63,22 +63,30 @@ abstract public class CommandParser {
63 63
     public void parseCommand(CommandWindow origin, String line) {
64 64
         if (line.charAt(0) == Config.getOption("general","commandchar").charAt(0)) {
65 65
             String[] args = line.split(" ");
66
+            String[] comargs;
67
+            String command;
66 68
             
67 69
             assert(args.length > 0);
68 70
             
69
-            String command = args[0].substring(1);
71
+            command = args[0].substring(1);
70 72
             
71
-            String signature = command+"/"+(args.length-1);
73
+            comargs = new String[args.length-1];
74
+            
75
+            for (int i = 1; i < args.length; i++) {
76
+                comargs[i-1] = args[i];
77
+            }
78
+            
79
+            String signature = command+"/"+(comargs.length);
72 80
             
73 81
             // Check the specific signature first, so that polyadic commands can
74 82
             // have error handlers if there are too few arguments (e.g., msg/0 and
75 83
             // msg/1 would return errors, so msg only gets called with 2+ args).
76 84
             if (commands.containsKey(signature)) {
77
-                executeCommand(origin, commands.get(signature), args);
85
+                executeCommand(origin, commands.get(signature), comargs);
78 86
             } else if (commands.containsKey(command)) {
79
-                executeCommand(origin, commands.get(command), args);
87
+                executeCommand(origin, commands.get(command), comargs);
80 88
             } else {
81
-                handleInvalidCommand(origin, command, args);
89
+                handleInvalidCommand(origin, command, comargs);
82 90
             }
83 91
         } else {
84 92
             handleNonCommand(origin, line);

+ 50
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/channel/Me.java 查看文件

@@ -0,0 +1,50 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.commandparser.commands.channel;
24
+
25
+import uk.org.ownage.dmdirc.Channel;
26
+import uk.org.ownage.dmdirc.Server;
27
+import uk.org.ownage.dmdirc.commandparser.ChannelCommand;
28
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
29
+
30
+/**
31
+ *
32
+ * @author chris
33
+ */
34
+public class Me extends ChannelCommand {
35
+    
36
+    /** Creates a new instance of Me */
37
+    public Me() {
38
+        description = "sends an action to the current channel";
39
+        arguments = "<action>";
40
+        polyadic = true;
41
+        arity = 0;
42
+        name = "me";
43
+        show = true;
44
+    }
45
+
46
+    public void execute(CommandWindow origin, Server server, Channel channel, String... args) {
47
+        channel.sendAction(implodeArgs(args));
48
+    }
49
+    
50
+}

+ 51
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/channel/MeEmpty.java 查看文件

@@ -0,0 +1,51 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.commandparser.commands.channel;
24
+
25
+import uk.org.ownage.dmdirc.Channel;
26
+import uk.org.ownage.dmdirc.Config;
27
+import uk.org.ownage.dmdirc.Server;
28
+import uk.org.ownage.dmdirc.commandparser.ChannelCommand;
29
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
30
+
31
+/**
32
+ *
33
+ * @author chris
34
+ */
35
+public class MeEmpty extends ChannelCommand {
36
+    
37
+    /** Creates a new instance of Me */
38
+    public MeEmpty() {
39
+        description = "informs the user of the correct usage of the me command";
40
+        arguments = "";
41
+        polyadic = false;
42
+        arity = 0;
43
+        name = "me";
44
+        show = true;
45
+    }
46
+
47
+    public void execute(CommandWindow origin, Server server, Channel channel, String... args) {
48
+        origin.addLine("Usage: "+Config.getOption("general","commandchar")+"me <action>");
49
+    }
50
+    
51
+}

+ 2
- 3
src/uk/org/ownage/dmdirc/commandparser/commands/server/Quit.java 查看文件

@@ -45,10 +45,9 @@ public class Quit extends ServerCommand {
45 45
         name = "quit";
46 46
         show = true;
47 47
     }
48
-
48
+    
49 49
     public void execute(CommandWindow origin, Server server, String... args) {
50
-        // TODO: Read proper quit reason
51
-        ServerManager.getServerManager().disconnectAll("...");
50
+        ServerManager.getServerManager().disconnectAll(implodeArgs(args));
52 51
         Config.save();
53 52
         System.exit(0);
54 53
     }

Loading…
取消
儲存