mirror of
https://github.com/demodude4u/Factorio-FBSR.git
synced 2024-11-27 08:20:57 +02:00
Resolved #5
This commit is contained in:
parent
f14b33ede6
commit
0cb5639ea9
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"discord_bot_token": "",
|
"discord_bot_token": "",
|
||||||
|
"pastebin_developer_api_key": "",
|
||||||
"factorio": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Factorio",
|
"factorio": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Factorio",
|
||||||
"type_schema": "https://raw.githubusercontent.com/demodude4u/factorio-tools/master/schema.json",
|
"type_schema": "https://raw.githubusercontent.com/demodude4u/factorio-tools/master/schema.json",
|
||||||
"__type_schema": "https://raw.githubusercontent.com/jcranmer/factorio-tools/master/schema.json"
|
"__type_schema": "https://raw.githubusercontent.com/jcranmer/factorio-tools/master/schema.json"
|
||||||
|
@ -60,5 +60,10 @@
|
|||||||
<artifactId>commons-text</artifactId>
|
<artifactId>commons-text</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>fluent-hc</artifactId>
|
||||||
|
<version>4.5.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
1
FactorioBlueprintStringRenderer/src/com/demod/fbsr/.gitignore
vendored
Normal file
1
FactorioBlueprintStringRenderer/src/com/demod/fbsr/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/MultipartUtility.java
|
@ -1,5 +1,6 @@
|
|||||||
package com.demod.fbsr;
|
package com.demod.fbsr;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -50,6 +51,21 @@ public final class WebUtils {
|
|||||||
return Utils.readJsonFromStream(new URL(url).openStream());
|
return Utils.readJsonFromStream(new URL(url).openStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static URL uploadToHostingService(String fileName, byte[] fileData) throws IOException {
|
||||||
|
try (ByteArrayInputStream bais = new ByteArrayInputStream(fileData)) {
|
||||||
|
return uploadToNyaIs(fileName, bais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static URL uploadToNyaIs(String fileName, InputStream inputStream) throws IOException {
|
||||||
|
// XXX You can get a copy of the MultipartUtility from
|
||||||
|
// http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically
|
||||||
|
MultipartUtility utility = new MultipartUtility("https://nya.is/upload", "UTF-8");
|
||||||
|
utility.addFormField("name", fileName);
|
||||||
|
utility.addFilePart("files[]", fileName, inputStream);
|
||||||
|
return new URL(new JSONObject(utility.finish().get(0)).getJSONArray("files").getJSONObject(0).getString("url"));
|
||||||
|
}
|
||||||
|
|
||||||
private WebUtils() {
|
private WebUtils() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.io.PrintStream;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -39,6 +40,7 @@ import com.demod.fbsr.FBSR;
|
|||||||
import com.demod.fbsr.RenderUtils;
|
import com.demod.fbsr.RenderUtils;
|
||||||
import com.demod.fbsr.TaskReporting;
|
import com.demod.fbsr.TaskReporting;
|
||||||
import com.demod.fbsr.TaskReporting.Level;
|
import com.demod.fbsr.TaskReporting.Level;
|
||||||
|
import com.demod.fbsr.WebUtils;
|
||||||
import com.demod.fbsr.WorldMap;
|
import com.demod.fbsr.WorldMap;
|
||||||
import com.google.common.collect.LinkedHashMultiset;
|
import com.google.common.collect.LinkedHashMultiset;
|
||||||
import com.google.common.collect.Multiset;
|
import com.google.common.collect.Multiset;
|
||||||
@ -83,7 +85,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
|||||||
.complete();
|
.complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendLuaDumpFile(event, key, lua.get(), reporting);
|
sendLuaDumpFile(event, "raw", key, lua.get(), reporting);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
reporting.addException(e);
|
reporting.addException(e);
|
||||||
}
|
}
|
||||||
@ -121,7 +123,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendLuaDumpFile(event, category + "_" + prototype.get().getName(), prototype.get().lua(), reporting);
|
sendLuaDumpFile(event, category, prototype.get().getName(), prototype.get().lua(), reporting);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
reporting.addException(e);
|
reporting.addException(e);
|
||||||
}
|
}
|
||||||
@ -197,10 +199,10 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
|||||||
if (!results.isEmpty()) {
|
if (!results.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = BlueprintStringData.extractJSON(results.get(0)).toString(2).getBytes();
|
byte[] bytes = BlueprintStringData.extractJSON(results.get(0)).toString(2).getBytes();
|
||||||
if (results.size() == 1 && bytes.length < 8000000) {
|
if (results.size() == 1) {
|
||||||
Message response = event.getChannel()
|
URL url = WebUtils.uploadToHostingService("blueprint.json", bytes);
|
||||||
.sendFile(new ByteArrayInputStream(bytes), "blueprint.json", null).complete();
|
event.getChannel().sendMessage("Blueprint JSON: " + url.toString()).complete();
|
||||||
reporting.addDownloadURL(response.getAttachments().get(0).getUrl());
|
reporting.addDownloadURL(url.toString());
|
||||||
} else {
|
} else {
|
||||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zos = new ZipOutputStream(baos)) {
|
ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||||
@ -276,16 +278,17 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendLuaDumpFile(MessageReceivedEvent event, String name, LuaValue lua, TaskReporting reporting)
|
private void sendLuaDumpFile(MessageReceivedEvent event, String category, String name, LuaValue lua,
|
||||||
throws IOException {
|
TaskReporting reporting) throws IOException {
|
||||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos)) {
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos)) {
|
||||||
ps.println("Lua Data Dump of " + name + " for Factorio " + FBSR.getVersion());
|
ps.println("Lua Data Dump of " + category + " " + name + " for Factorio " + FBSR.getVersion());
|
||||||
ps.println();
|
ps.println();
|
||||||
Utils.debugPrintLua(lua, ps);
|
Utils.debugPrintLua(lua, ps);
|
||||||
ps.flush();
|
ps.flush();
|
||||||
Message response = event.getChannel()
|
URL url = WebUtils.uploadToHostingService(category + "_" + name + "_dump_" + FBSR.getVersion() + ".txt",
|
||||||
.sendFile(baos.toByteArray(), name + "_dump_" + FBSR.getVersion() + ".txt", null).complete();
|
baos.toByteArray());
|
||||||
reporting.addDownloadURL(response.getAttachments().get(0).getUrl());
|
event.getChannel().sendMessage(category + " " + name + " lua dump: " + url.toString()).complete();
|
||||||
|
reporting.addDownloadURL(url.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user