瀏覽代碼

Use the parser's new whois command.

pull/541/head
Greg Holmes 9 年之前
父節點
當前提交
168b137e68

+ 5
- 0
src/com/dmdirc/Server.java 查看文件

@@ -1076,6 +1076,11 @@ public class Server extends FrameContainer implements Connection {
1076 1076
         return parser.map(Parser::getLocalClient).map(ClientInfo::getNickname);
1077 1077
     }
1078 1078
 
1079
+    @Override
1080
+    public void requestUserInfo(final User user) {
1081
+        parser.ifPresent(p -> p.sendWhois(user.getNickname()));
1082
+    }
1083
+
1079 1084
     /**
1080 1085
      * Utility method to get a result from the parser while holding the {@link #parserLock}
1081 1086
      * read lock.

+ 14
- 1
src/com/dmdirc/commandparser/commands/CommandModule.java 查看文件

@@ -64,6 +64,7 @@ import com.dmdirc.commandparser.commands.server.Raw;
64 64
 import com.dmdirc.commandparser.commands.server.RawServerCommand;
65 65
 import com.dmdirc.commandparser.commands.server.Reconnect;
66 66
 import com.dmdirc.commandparser.commands.server.Umode;
67
+import com.dmdirc.commandparser.commands.server.Whois;
67 68
 import com.dmdirc.interfaces.CommandController;
68 69
 import com.dmdirc.interfaces.CommandController.CommandDetails;
69 70
 
@@ -379,6 +380,18 @@ public class CommandModule {
379 380
         return new SimpleCommandDetails(command, Umode.INFO);
380 381
     }
381 382
 
383
+    /**
384
+     * Provides the /whois command.
385
+     * 
386
+     * @param command The instantiated command.
387
+     *
388
+     * @return The command's details
389
+     */
390
+    @Provides(type = Provides.Type.SET)
391
+    public CommandDetails getCommand(final Whois command) {
392
+        return new SimpleCommandDetails(command, Whois.INFO);
393
+    }
394
+
382 395
     /**
383 396
      * Provides a set of raw commands.
384 397
      *
@@ -389,7 +402,7 @@ public class CommandModule {
389 402
     @Provides(type = Provides.Type.SET_VALUES)
390 403
     public Set<CommandDetails> getRawCommands(final CommandController controller) {
391 404
         final Set<CommandDetails> results = new HashSet<>();
392
-        for (String name : new String[]{"lusers", "map", "motd", "oper", "whois", "who"}) {
405
+        for (String name : new String[]{"lusers", "map", "motd", "oper", "who"}) {
393 406
             final RawServerCommand rawCommand = new RawServerCommand(controller, name);
394 407
             results.add(new SimpleCommandDetails(rawCommand, rawCommand));
395 408
         }

+ 72
- 0
src/com/dmdirc/commandparser/commands/server/Whois.java 查看文件

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
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 com.dmdirc.commandparser.commands.server;
24
+
25
+import com.dmdirc.ServerState;
26
+import com.dmdirc.commandparser.BaseCommandInfo;
27
+import com.dmdirc.commandparser.CommandArguments;
28
+import com.dmdirc.commandparser.CommandInfo;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.CommandOptions;
32
+import com.dmdirc.commandparser.commands.context.CommandContext;
33
+import com.dmdirc.commandparser.commands.context.ServerCommandContext;
34
+import com.dmdirc.interfaces.CommandController;
35
+import com.dmdirc.interfaces.Connection;
36
+import com.dmdirc.interfaces.WindowModel;
37
+
38
+import javax.annotation.Nonnull;
39
+import javax.inject.Inject;
40
+
41
+/**
42
+ *
43
+ */
44
+@CommandOptions(allowOffline = false)
45
+public class Whois extends Command {
46
+
47
+    /** A command info object for this command. */
48
+    public static final CommandInfo INFO = new BaseCommandInfo("whois",
49
+            "whois [nickname] - sends a whois request", CommandType.TYPE_SERVER);
50
+
51
+    /**
52
+     * Creates a new instance of this command.
53
+     *
54
+     * @param controller The controller to use for command information.
55
+     */
56
+    @Inject
57
+    public Whois(final CommandController controller) {
58
+        super(controller);
59
+    }
60
+
61
+    @Override
62
+    public void execute(@Nonnull final WindowModel origin,
63
+            final CommandArguments args, final CommandContext context) {
64
+        final Connection connection = ((ServerCommandContext) context).getConnection();
65
+        if (connection.getState() != ServerState.CONNECTED) {
66
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Not connected");
67
+            return;
68
+        }
69
+
70
+        connection.getParser().get().sendWhois(args.getArgumentsAsString());
71
+    }
72
+}

+ 2
- 0
src/com/dmdirc/interfaces/Connection.java 查看文件

@@ -416,4 +416,6 @@ public interface Connection {
416 416
      */
417 417
     Optional<String> getNickname();
418 418
 
419
+    void requestUserInfo(User user);
420
+
419 421
 }

Loading…
取消
儲存