Sfoglia il codice sorgente

Add support for snippets

master
Chris Smith 15 anni fa
parent
commit
69d1ed10d5
1 ha cambiato i file con 21 aggiunte e 1 eliminazioni
  1. 21
    1
      src/com/md87/charliebravo/InputHandler.java

+ 21
- 1
src/com/md87/charliebravo/InputHandler.java Vedi File

@@ -18,6 +18,7 @@ import com.md87.charliebravo.commands.GitCommand;
18 18
 import com.md87.charliebravo.commands.GoogleCommand;
19 19
 import com.md87.charliebravo.commands.HelpCommand;
20 20
 import com.md87.charliebravo.commands.IssueCommand;
21
+import com.md87.charliebravo.commands.NewzbinCommand;
21 22
 import com.md87.charliebravo.commands.QuitCommand;
22 23
 import com.md87.charliebravo.commands.SetCommand;
23 24
 import com.md87.charliebravo.commands.SkillCommand;
@@ -41,6 +42,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage {
41 42
 
42 43
     protected final List<Command> commands = new ArrayList<Command>();
43 44
     protected final Map<String, Response> responses = new HashMap<String, Response>();
45
+    protected final Map<String, String> snippets = new HashMap<String, String>();
44 46
 
45 47
     public InputHandler(final Config config) {
46 48
         this.config = config;
@@ -57,6 +59,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage {
57 59
         commands.add(new GitCommand());
58 60
         commands.add(new SetCommand());
59 61
         commands.add(new SkillCommand());
62
+        commands.add(new NewzbinCommand());
60 63
     }
61 64
 
62 65
     public Config getConfig() {
@@ -87,7 +90,23 @@ public class InputHandler implements IChannelMessage, IPrivateMessage {
87 90
         for (String nick : getNicknames()) {
88 91
             if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "[,:!] .*")) {
89 92
                 handleInput(ClientInfo.parseHost(sHost), cChannel.getName(),
90
-                        sMessage.substring(tParser.getMyNickname().length() + 2));
93
+                        sMessage.substring(nick.length() + 2));
94
+                break;
95
+            } else if (sMessage.matches("^(?i)" + Matcher.quoteReplacement(nick) + "\\?")
96
+                    && snippets.containsKey(cChannel.getName())) {
97
+                handleInput(ClientInfo.parseHost(sHost), cChannel.getName(),
98
+                        snippets.get(cChannel.getName()));
99
+                break;
100
+            }
101
+        }
102
+
103
+        for (Map.Entry<String, String> snippet : config.getConfigfile()
104
+                .getKeyDomain("snippets").entrySet()) {
105
+            System.out.println("Snippet test: " + snippet.getKey());
106
+            if (sMessage.matches(snippet.getKey())) {
107
+                snippets.put(cChannel.getName(), sMessage.replaceFirst(snippet.getKey(),
108
+                        snippet.getValue()));
109
+                System.out.println("Snippet: " + snippets.get(cChannel.getName()));
91 110
                 break;
92 111
             }
93 112
         }
@@ -98,6 +117,7 @@ public class InputHandler implements IChannelMessage, IPrivateMessage {
98 117
             parser.getMyNickname(),
99 118
             parser.getMyNickname().replaceAll("[a-z]", ""),
100 119
             parser.getMyNickname().replaceAll("[^a-zA-Z]", ""),
120
+            parser.getMyNickname().replaceAll("[^A-Z]", ""),
101 121
         };
102 122
     }
103 123
 

Loading…
Annulla
Salva