|
5 | 5 |
|
6 | 6 | package org.mangorage.mangobot.modules.logs; |
7 | 7 |
|
8 | | -import java.io.IOException; |
9 | | -import java.io.InputStream; |
10 | | -import java.util.ArrayList; |
11 | 8 | import java.util.HashSet; |
12 | 9 | import java.util.List; |
13 | 10 | import java.util.Set; |
14 | 11 | import java.util.function.BiPredicate; |
15 | 12 |
|
16 | | -import org.mangorage.mangobot.core.Util; |
17 | | - |
18 | | -import net.dv8tion.jda.api.entities.Message; |
19 | | - |
20 | 13 | public final class LogAnalyser { |
21 | 14 | public static LogAnalyser of(LogAnalyserModule... modules) { |
22 | 15 | return new LogAnalyser(List.of(modules)); |
@@ -59,67 +52,8 @@ public void addAll(LogAnalyserModule... modules) { |
59 | 52 | this.mods.addAll(List.of(modules)); |
60 | 53 | } |
61 | 54 |
|
62 | | - |
63 | | - // Be sure to include slashes, Paste.ee and other sites without separate or |
64 | | - // only raw URLs will not work, ones with fancy raw URLs like OpenSUSE paste |
65 | | - // will also not be included at this time. |
66 | | - public String[] supported_paste_sites = new String[] { |
67 | | - "paste.mikumikudance.jp/", |
68 | | - "paste.centos.org/", |
69 | | - "pastebin.com/", "mclo.gs/" |
70 | | - }; |
71 | | - |
72 | | - public void scanMessage(Message message, StringBuilder stringBuilder) { |
73 | | - String content = message.getContentStripped(); |
74 | | - for (String uri : getLogURLs(content)) { |
75 | | - InputStream log = Util.getFileInputStream(uri); |
76 | | - if (log != null) { |
77 | | - try { |
78 | | - String str = Util.getStringFromInputStream(log); |
79 | | - readLog(stringBuilder, str); |
80 | | - } catch (IOException e) { |
81 | | - // TODO Auto-generated catch block |
82 | | - e.printStackTrace(); |
83 | | - } |
84 | | - } |
85 | | - |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - public ArrayList<String> getLogURLs(String message) { |
90 | | - ArrayList<String> list = new ArrayList<>(); |
91 | | - for (String word : message.split(" ")) { |
92 | | - |
93 | | - for (String paste : supported_paste_sites) { |
94 | | - if (word.contains(paste)) { |
95 | | - |
96 | | - if (paste.equals("mclo.gs/")) { |
97 | | - String[] url_arr = word.split("/"); |
98 | | - String slug = url_arr[url_arr.length - 1]; |
99 | | - list.add("https://api.mclo.gs/1/raw/" + slug); |
100 | | - } else if (paste.equals("pastebin.com/")) { |
101 | | - String[] url_arr = word.split("/"); |
102 | | - String slug = url_arr[url_arr.length - 1]; |
103 | | - list.add("https://pastebin.com/raw/" + slug); |
104 | | - } else { // Add more else ifs for other sites |
105 | | - if (word.contains("/view/raw/")) { |
106 | | - list.add(word); |
107 | | - } else if (word.contains("/view/")) { |
108 | | - list.add(word.replace("/view/", "/view/raw/")); |
109 | | - } |
110 | | - |
111 | | - } |
112 | | - |
113 | | - } |
114 | | - |
115 | | - } |
116 | | - |
117 | | - } |
118 | | - |
119 | | - return list; |
120 | | - } |
121 | | - |
122 | 55 | public void readLog(StringBuilder message, String log) { |
| 56 | + log = log.replace("\\r?\\n", "\\n"); |
123 | 57 | for(LogAnalyserModule mod : mods) { |
124 | 58 | mod.analyse(log, message); |
125 | 59 | } |
|
0 commit comments