Ver código fonte

Disable broken commands and add support for DMDirc JIRA

master
Chris Smith 13 anos atrás
pai
commit
d0395a8653

+ 3
- 3
src/com/md87/charliebravo/InputHandler.java Ver arquivo

@@ -92,11 +92,11 @@ public class InputHandler implements ChannelMessageListener, PrivateMessageListe
92 92
         commands.add(new SetCommand());
93 93
         commands.add(new SkillCommand());
94 94
         commands.add(new SnippetsCommand());
95
-        commands.add(new NewzbinCommand());
95
+        // commands.add(new NewzbinCommand()); - broken
96 96
         commands.add(new ReloadCommand());
97
-        commands.add(new DefineCommand());
97
+        // commands.add(new DefineCommand()); - broken
98 98
         commands.add(new LawCommand());
99
-        commands.add(new QuoteCommand());
99
+        //commands.add(new QuoteCommand()); - broken
100 100
     }
101 101
 
102 102
     public Config getConfig() {

+ 71
- 32
src/com/md87/charliebravo/commands/IssueCommand.java Ver arquivo

@@ -32,6 +32,7 @@ import java.util.List;
32 32
 import java.util.Map;
33 33
 import java.util.regex.Matcher;
34 34
 import java.util.regex.Pattern;
35
+import org.json.JSONObject;
35 36
 
36 37
 /**
37 38
  *
@@ -40,45 +41,83 @@ import java.util.regex.Pattern;
40 41
 public class IssueCommand implements Command {
41 42
 
42 43
     public void execute(InputHandler handler, Response response, String line) throws Exception {
43
-        if (line.isEmpty() || !line.matches("^[0-9]+$")) {
44
-            response.sendMessage("You need to specify an issue number", true);
44
+        if (line.matches("^[0-9]+$")) {
45
+            executeOldIssue(handler, response, line);
46
+        } else if (line.matches("^[A-Z]+-[0-9]+$")) {
47
+            executeNewIssue(handler, response, line);
45 48
         } else {
46
-            final List<String> result = Downloader.getPage("http://bugs.dmdirc.com/view.php?id="
47
-                    + line);
48
-            final StringBuilder builder = new StringBuilder();
49
+            response.sendMessage("You need to specify a valid issue number", true);
50
+        }
51
+    }
49 52
 
50
-            for (String resline : result) {
51
-                builder.append(resline);
52
-            }
53
+    protected void executeNewIssue(InputHandler handler, Response response, String line) throws Exception {
54
+        final List<String> result = Downloader.getPage("http://jira.dmdirc.com/rest/api/2.0.alpha1/issue/"
55
+                + line);
56
+        final StringBuilder builder = new StringBuilder();
57
+
58
+        for (String resline : result) {
59
+            builder.append(resline);
60
+        }
53 61
 
54
-            if (builder.indexOf("APPLICATION ERROR #1100") > -1) {
55
-                response.sendMessage("That issue was not found", true);
56
-            } else if (builder.indexOf("<p>Access Denied.</p>") > -1) {
57
-                response.sendMessage("that issue is private. Please see "
58
-                        + "http://bugs.dmdirc.com/view/" + line);
62
+        final JSONObject json = new JSONObject(builder.toString());
63
+        final JSONObject fields = json.getJSONObject("fields");
64
+        final Map<String, String> data = new HashMap<String, String>();
65
+        data.put("id", json.getString("key"));
66
+
67
+        for (String key : JSONObject.getNames(fields)) {
68
+            JSONObject complexValue = fields.getJSONObject(key).optJSONObject("value");
69
+            String value;
70
+
71
+            if (complexValue == null) {
72
+                value = fields.getJSONObject(key).optString("value", "");
59 73
             } else {
60
-                final Map<String, String> data = new HashMap<String, String>();
61
-
62
-                final Pattern pattern = Pattern.compile(
63
-                        "<td class=\"category\".*?>\\s*(.*?)\\s*"
64
-                        + "</td>\\s*(?:<!--.*?-->\\s*)?<td.*?>\\s*(.*?)\\s*</td>",
65
-                        Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
66
-                final Matcher matcher = pattern.matcher(builder);
67
-
68
-                while (matcher.find()) {
69
-                    data.put(matcher.group(1).toLowerCase(), matcher.group(2));
70
-                }
71
-
72
-                response.sendMessage("issue " + data.get("id") + " is \""
73
-                        + data.get("summary").substring(9) + "\". Current "
74
-                        + "status is " + data.get("status") + " ("
75
-                        + data.get("resolution") + "). See http://bugs.dmdirc.com/view/"
76
-                        + data.get("id"));
77
-                response.addFollowup(new IssueFollowup(data));
74
+                value = complexValue.optString("name", "");
78 75
             }
79
-            
76
+
77
+            data.put(fields.getJSONObject(key).optString("name", key), value);
80 78
         }
81 79
 
80
+        response.sendMessage("issue " + data.get("id") + " is \""
81
+                + data.get("summary") + "\" and is currently "
82
+                + data.get("status").toLowerCase() + ". See http://jira.dmdirc.com/browse/"
83
+                + data.get("id"));
84
+        response.addFollowup(new IssueFollowup(data));
85
+    }
86
+
87
+    protected void executeOldIssue(InputHandler handler, Response response, String line) throws Exception {
88
+        final List<String> result = Downloader.getPage("http://bugs.dmdirc.com/view.php?id="
89
+                + line);
90
+        final StringBuilder builder = new StringBuilder();
91
+
92
+        for (String resline : result) {
93
+            builder.append(resline);
94
+        }
95
+
96
+        if (builder.indexOf("APPLICATION ERROR #1100") > -1) {
97
+            response.sendMessage("That issue was not found", true);
98
+        } else if (builder.indexOf("<p>Access Denied.</p>") > -1) {
99
+            response.sendMessage("that issue is private. Please see "
100
+                    + "http://bugs.dmdirc.com/view/" + line);
101
+        } else {
102
+            final Map<String, String> data = new HashMap<String, String>();
103
+
104
+            final Pattern pattern = Pattern.compile(
105
+                    "<td class=\"category\".*?>\\s*(.*?)\\s*"
106
+                    + "</td>\\s*(?:<!--.*?-->\\s*)?<td.*?>\\s*(.*?)\\s*</td>",
107
+                    Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
108
+            final Matcher matcher = pattern.matcher(builder);
109
+
110
+            while (matcher.find()) {
111
+                data.put(matcher.group(1).toLowerCase(), matcher.group(2));
112
+            }
113
+
114
+            response.sendMessage("issue " + data.get("id") + " is \""
115
+                    + data.get("summary").substring(9) + "\". Current "
116
+                    + "status is " + data.get("status") + " ("
117
+                    + data.get("resolution") + "). See http://bugs.dmdirc.com/view/"
118
+                    + data.get("id"));
119
+            response.addFollowup(new IssueFollowup(data));
120
+        }
82 121
     }
83 122
 
84 123
     protected static class IssueFollowup implements Followup {

Carregando…
Cancelar
Salvar