Search in sources :

Example 1 with DataTable

use of com.demod.factorio.DataTable in project Factorio-FBSR by demodude4u.

the class BlueprintBotDiscordService method handleBlueprintTotalsCommand.

private void handleBlueprintTotalsCommand(SlashCommandEvent event) {
    DataTable table;
    try {
        table = FactorioData.getTable();
    } catch (JSONException | IOException e1) {
        throw new InternalError(e1);
    }
    String content = event.getCommandString();
    Optional<Attachment> attachment = event.optParamAttachment("file");
    if (attachment.isPresent()) {
        content += " " + attachment.get().getUrl();
    }
    List<BlueprintStringData> blueprintStringDatas = BlueprintFinder.search(content, event.getReporting());
    Map<String, Double> totalItems = new LinkedHashMap<>();
    for (BlueprintStringData blueprintStringData : blueprintStringDatas) {
        for (Blueprint blueprint : blueprintStringData.getBlueprints()) {
            Map<String, Double> items = FBSR.generateSummedTotalItems(table, blueprint);
            items.forEach((k, v) -> {
                totalItems.compute(k, ($, old) -> old == null ? v : old + v);
            });
        }
    }
    if (!totalItems.isEmpty()) {
        String responseContent = totalItems.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).map(e -> e.getKey() + ": " + RenderUtils.fmtDouble2(e.getValue())).collect(Collectors.joining("\n"));
        String response = "```ldif\n" + responseContent + "```";
        if (response.length() < 2000) {
            event.reply(response);
        } else {
            event.replyFile(responseContent.getBytes(), "totals.txt");
        }
    } else if (blueprintStringDatas.stream().anyMatch(d -> !d.getBlueprints().isEmpty())) {
        event.replyIfNoException("I couldn't find any items!");
    } else {
        event.replyIfNoException("No blueprint found!");
    }
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) Arrays(java.util.Arrays) EventReply(com.demod.dcba.EventReply) URL(java.net.URL) FBSR(com.demod.fbsr.FBSR) Permission(net.dv8tion.jda.api.Permission) SlashCommandHandler(com.demod.dcba.SlashCommandHandler) Field(net.dv8tion.jda.api.entities.MessageEmbed.Field) TextChannel(net.dv8tion.jda.api.entities.TextChannel) DataTable(com.demod.factorio.DataTable) RenderUtils(com.demod.fbsr.RenderUtils) JSONException(org.json.JSONException) Matcher(java.util.regex.Matcher) JSONObject(org.json.JSONObject) Map(java.util.Map) ZipEntry(java.util.zip.ZipEntry) WebUtils(com.demod.fbsr.WebUtils) Message(net.dv8tion.jda.api.entities.Message) BufferedImage(java.awt.image.BufferedImage) DataPrototype(com.demod.factorio.prototype.DataPrototype) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) Collectors(java.util.stream.Collectors) Config(com.demod.factorio.Config) BlueprintEntity(com.demod.fbsr.BlueprintEntity) List(java.util.List) FactorioData(com.demod.factorio.FactorioData) MessageCommandEvent(com.demod.dcba.MessageCommandEvent) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) BlueprintStringData(com.demod.fbsr.BlueprintStringData) ZipOutputStream(java.util.zip.ZipOutputStream) Blueprint(com.demod.fbsr.Blueprint) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WatchdogReporter(com.demod.fbsr.app.WatchdogService.WatchdogReporter) ImmutableList(com.google.common.collect.ImmutableList) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) SlashCommandEvent(com.demod.dcba.SlashCommandEvent) SimpleEntry(java.util.AbstractMap.SimpleEntry) Attachment(net.dv8tion.jda.api.entities.Message.Attachment) MapVersion(com.demod.fbsr.MapVersion) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) CommandReporting(com.demod.dcba.CommandReporting) DCBA(com.demod.dcba.DCBA) IOException(java.io.IOException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Utils(com.demod.factorio.Utils) DiscordBot(com.demod.dcba.DiscordBot) LuaValue(org.luaj.vm2.LuaValue) AutoCompleteHandler(com.demod.dcba.AutoCompleteHandler) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) ArrayDeque(java.util.ArrayDeque) BlueprintFinder(com.demod.fbsr.BlueprintFinder) ChunkingFilter(net.dv8tion.jda.api.utils.ChunkingFilter) JSONArray(org.json.JSONArray) DataTable(com.demod.factorio.DataTable) Blueprint(com.demod.fbsr.Blueprint) JSONException(org.json.JSONException) Attachment(net.dv8tion.jda.api.entities.Message.Attachment) BlueprintStringData(com.demod.fbsr.BlueprintStringData) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DataTable

use of com.demod.factorio.DataTable in project Factorio-FBSR by demodude4u.

the class FBSR method createItemListPanel.

private static PanelRenderer createItemListPanel(DataTable table, String title, Map<String, Double> items) {
    final double header = 0.8;
    final double spacing = 0.7;
    final double iconSize = 0.6;
    return new PanelRenderer(3.0, header + items.size() * spacing + 0.2) {

        @Override
        public void render(Graphics2D g, double width, double height) {
            g.setColor(GRID_COLOR);
            g.setStroke(GRID_STROKE);
            g.draw(new Rectangle2D.Double(0, 0, width, height));
            Font font = new Font("Monospaced", Font.BOLD, 1).deriveFont(0.6f);
            g.setFont(font);
            g.drawString(title, 0.3f, 0.65f);
            double startX = 0.6;
            double startY = header + spacing / 2.0;
            Rectangle2D.Double spriteBox = new Rectangle2D.Double(startX - iconSize / 2.0, startY - iconSize / 2.0, iconSize, iconSize);
            Point2D.Double textPos = new Point2D.Double(startX + 0.5, startY + 0.18);
            items.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).forEach(e -> {
                String itemName = e.getKey();
                double amount = e.getValue();
                Optional<BufferedImage> image = Optional.empty();
                if (itemName.equals(TotalRawCalculator.RAW_TIME)) {
                    image = Optional.of(timeIcon);
                } else {
                    Optional<? extends DataPrototype> prototype = table.getItem(itemName);
                    if (!prototype.isPresent()) {
                        prototype = table.getFluid(itemName);
                    }
                    image = prototype.map(FactorioData::getIcon);
                }
                image.ifPresent(i -> {
                    RenderUtils.drawImageInBounds(i, new Rectangle(0, 0, i.getWidth(), i.getHeight()), spriteBox, g);
                });
                String amountStr;
                if (amount < 99999) {
                    g.setColor(GRID_COLOR);
                    amountStr = RenderUtils.fmtDouble(Math.ceil(amount));
                } else if (amount < 9999999) {
                    g.setColor(GRID_COLOR.brighter());
                    amountStr = RenderUtils.fmtDouble(Math.ceil(amount / 1000)) + "k";
                } else {
                    g.setColor(GRID_COLOR.brighter().brighter());
                    amountStr = RenderUtils.fmtDouble(Math.ceil(amount / 1000000)) + "M";
                }
                g.setFont(font);
                g.drawString(amountStr, (float) textPos.x, (float) textPos.y);
                spriteBox.y += spacing;
                textPos.y += spacing;
            });
        }
    };
}
Also used : Color(java.awt.Color) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Point2D(java.awt.geom.Point2D) Level(com.demod.dcba.CommandReporting.Level) Rectangle2D(java.awt.geom.Rectangle2D) RenderingHints(java.awt.RenderingHints) DataTable(com.demod.factorio.DataTable) JSONException(org.json.JSONException) RailEdge(com.demod.fbsr.WorldMap.RailEdge) JSONObject(org.json.JSONObject) Ellipse2D(java.awt.geom.Ellipse2D) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) LinkedHashMultiset(com.google.common.collect.LinkedHashMultiset) Shape(java.awt.Shape) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) DataPrototype(com.demod.factorio.prototype.DataPrototype) Collection(java.util.Collection) Set(java.util.Set) AffineTransform(java.awt.geom.AffineTransform) CubicCurve2D(java.awt.geom.CubicCurve2D) ItemPrototype(com.demod.factorio.prototype.ItemPrototype) List(java.util.List) ModInfo(com.demod.factorio.ModInfo) FactorioData(com.demod.factorio.FactorioData) Entry(java.util.Map.Entry) Optional(java.util.Optional) BasicStroke(java.awt.BasicStroke) Queue(java.util.Queue) EntityPrototype(com.demod.factorio.prototype.EntityPrototype) Rectangle(java.awt.Rectangle) Multiset(com.google.common.collect.Multiset) HashMap(java.util.HashMap) RecipePrototype(com.demod.factorio.prototype.RecipePrototype) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RailNode(com.demod.fbsr.WorldMap.RailNode) ImmutableList(com.google.common.collect.ImmutableList) Graphics2D(java.awt.Graphics2D) SimpleEntry(java.util.AbstractMap.SimpleEntry) Layer(com.demod.fbsr.Renderer.Layer) Stroke(java.awt.Stroke) TilePrototype(com.demod.factorio.prototype.TilePrototype) Line2D(java.awt.geom.Line2D) CommandReporting(com.demod.dcba.CommandReporting) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) Consumer(java.util.function.Consumer) Utils(com.demod.factorio.Utils) ArrayDeque(java.util.ArrayDeque) TotalRawCalculator(com.demod.factorio.TotalRawCalculator) Table(com.google.common.collect.Table) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D)

Example 3 with DataTable

use of com.demod.factorio.DataTable in project Factorio-FBSR by demodude4u.

the class EntityRendererFactory method createRenderers.

public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
    try {
        List<Sprite> sprites;
        Optional<LuaValue> findSpriteLua = defaultProperties.stream().map(p -> prototype.lua().get(p)).filter(l -> l != LuaValue.NIL).findAny();
        if (findSpriteLua.isPresent()) {
            LuaValue spriteLua = findSpriteLua.get();
            boolean hasDir = spriteLua.get(entity.getDirection().name().toLowerCase()) != LuaValue.NIL;
            if (hasDir) {
                spriteLua = spriteLua.get(entity.getDirection().name().toLowerCase());
            }
            sprites = RenderUtils.getSpritesFromAnimation(spriteLua, entity.getDirection());
        } else {
            Sprite sprite = new Sprite();
            sprite.image = FactorioData.getModImage(prototype.lua().get("icon").tojstring());
            sprite.source = new Rectangle(0, 0, sprite.image.getWidth(), sprite.image.getHeight());
            sprite.bounds = (Rectangle2D.Double) prototype.getSelectionBox().clone();
            sprites = ImmutableList.of(sprite);
        }
        register.accept(RenderUtils.spriteRenderer(sprites, entity, prototype));
    } catch (RuntimeException e) {
        debugPrintContext(entity, prototype);
        throw e;
    }
}
Also used : Color(java.awt.Color) SplitterRendering(com.demod.fbsr.entity.SplitterRendering) Point2D(java.awt.geom.Point2D) ReactorRendering(com.demod.fbsr.entity.ReactorRendering) SolarPanelRendering(com.demod.fbsr.entity.SolarPanelRendering) Rectangle2D(java.awt.geom.Rectangle2D) Random(java.util.Random) CurvedRailRendering(com.demod.fbsr.entity.CurvedRailRendering) DataTable(com.demod.factorio.DataTable) JSONObject(org.json.JSONObject) Ellipse2D(java.awt.geom.Ellipse2D) FurnaceRendering(com.demod.fbsr.entity.FurnaceRendering) LinkedBeltRendering(com.demod.fbsr.entity.LinkedBeltRendering) BoilerRendering(com.demod.fbsr.entity.BoilerRendering) Map(java.util.Map) LinkedHashMultiset(com.google.common.collect.LinkedHashMultiset) ArtilleryWagonRendering(com.demod.fbsr.entity.ArtilleryWagonRendering) AssemblingMachineRendering(com.demod.fbsr.entity.AssemblingMachineRendering) LandMineRendering(com.demod.fbsr.entity.LandMineRendering) LogisticContainerRendering(com.demod.fbsr.entity.LogisticContainerRendering) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) WallRendering(com.demod.fbsr.entity.WallRendering) Set(java.util.Set) RailSignalRendering(com.demod.fbsr.entity.RailSignalRendering) TurretRendering(com.demod.fbsr.entity.TurretRendering) RoboportRendering(com.demod.fbsr.entity.RoboportRendering) Collectors(java.util.stream.Collectors) GeneratorRendering(com.demod.fbsr.entity.GeneratorRendering) LabRendering(com.demod.fbsr.entity.LabRendering) TransportBeltRendering(com.demod.fbsr.entity.TransportBeltRendering) List(java.util.List) FactorioData(com.demod.factorio.FactorioData) ArtilleryTurretRendering(com.demod.fbsr.entity.ArtilleryTurretRendering) ProgrammableSpeakerRendering(com.demod.fbsr.entity.ProgrammableSpeakerRendering) ElectricEnergyInterfaceRendering(com.demod.fbsr.entity.ElectricEnergyInterfaceRendering) StraightRailRendering(com.demod.fbsr.entity.StraightRailRendering) Entry(java.util.Map.Entry) Optional(java.util.Optional) EntityPrototype(com.demod.factorio.prototype.EntityPrototype) ContainerRendering(com.demod.fbsr.entity.ContainerRendering) PumpRendering(com.demod.fbsr.entity.PumpRendering) ElectricPoleRendering(com.demod.fbsr.entity.ElectricPoleRendering) Rectangle(java.awt.Rectangle) InfinityContainerRendering(com.demod.fbsr.entity.InfinityContainerRendering) ConstantCombinatorRendering(com.demod.fbsr.entity.ConstantCombinatorRendering) DeciderCombinatorRendering(com.demod.fbsr.entity.DeciderCombinatorRendering) GateRendering(com.demod.fbsr.entity.GateRendering) InserterRendering(com.demod.fbsr.entity.InserterRendering) BeaconRendering(com.demod.fbsr.entity.BeaconRendering) Multiset(com.google.common.collect.Multiset) RollingStockRendering(com.demod.fbsr.entity.RollingStockRendering) HashMap(java.util.HashMap) ArithmeticCombinatorRendering(com.demod.fbsr.entity.ArithmeticCombinatorRendering) RecipePrototype(com.demod.factorio.prototype.RecipePrototype) FluidTurretRendering(com.demod.fbsr.entity.FluidTurretRendering) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) LoaderRendering(com.demod.fbsr.entity.LoaderRendering) RailChainSignalRendering(com.demod.fbsr.entity.RailChainSignalRendering) ImmutableList(com.google.common.collect.ImmutableList) Graphics2D(java.awt.Graphics2D) LinkedContainerRendering(com.demod.fbsr.entity.LinkedContainerRendering) AccumulatorRendering(com.demod.fbsr.entity.AccumulatorRendering) OffshorePumpRendering(com.demod.fbsr.entity.OffshorePumpRendering) HeatPipeRendering(com.demod.fbsr.entity.HeatPipeRendering) PowerSwitchRendering(com.demod.fbsr.entity.PowerSwitchRendering) BurnerGeneratorRendering(com.demod.fbsr.entity.BurnerGeneratorRendering) SimpleEntry(java.util.AbstractMap.SimpleEntry) LinkedHashSet(java.util.LinkedHashSet) Layer(com.demod.fbsr.Renderer.Layer) StorageTankRendering(com.demod.fbsr.entity.StorageTankRendering) HeatInterfaceRendering(com.demod.fbsr.entity.HeatInterfaceRendering) LampRendering(com.demod.fbsr.entity.LampRendering) RadarRendering(com.demod.fbsr.entity.RadarRendering) PipeToGroundRendering(com.demod.fbsr.entity.PipeToGroundRendering) RocketSiloRendering(com.demod.fbsr.entity.RocketSiloRendering) MiningDrillRendering(com.demod.fbsr.entity.MiningDrillRendering) TrainStopRendering(com.demod.fbsr.entity.TrainStopRendering) PipeRendering(com.demod.fbsr.entity.PipeRendering) Consumer(java.util.function.Consumer) Utils(com.demod.factorio.Utils) UndergroundBeltRendering(com.demod.fbsr.entity.UndergroundBeltRendering) LuaValue(org.luaj.vm2.LuaValue) JSONArray(org.json.JSONArray) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) LuaValue(org.luaj.vm2.LuaValue)

Example 4 with DataTable

use of com.demod.factorio.DataTable in project Factorio-FBSR by demodude4u.

the class AssemblingMachineRendering method populateWorldMap.

@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
    String recipeName = entity.json().optString("recipe", null);
    boolean hasFluid = false;
    if (recipeName != null) {
        Optional<RecipePrototype> optRecipe = dataTable.getRecipe(recipeName);
        if (optRecipe.isPresent()) {
            RecipePrototype protoRecipe = optRecipe.get();
            List<LuaValue> items = new ArrayList<>();
            Utils.forEach(protoRecipe.lua().get("ingredients"), (Consumer<LuaValue>) items::add);
            LuaValue resultsLua = protoRecipe.lua().get("results");
            if (resultsLua != LuaValue.NIL) {
                items.add(resultsLua);
            }
            hasFluid = items.stream().anyMatch(lua -> {
                LuaValue typeLua = lua.get("type");
                return typeLua != LuaValue.NIL && typeLua.toString().equals("fluid");
            });
        }
    }
    LuaValue fluidBoxesLua = prototype.lua().get("fluid_boxes");
    boolean offWhenNoFluidRecipe = fluidBoxesLua.isnil() ? true : fluidBoxesLua.get("off_when_no_fluid_recipe").optboolean(false);
    if (!fluidBoxesLua.isnil() && (!offWhenNoFluidRecipe || hasFluid)) {
        Utils.forEach(fluidBoxesLua, fluidBoxLua -> {
            if (!fluidBoxLua.istable()) {
                return;
            }
            Utils.forEach(fluidBoxLua.get("pipe_connections"), pipeConnectionLua -> {
                Point2D.Double offset = Utils.parsePoint2D(pipeConnectionLua.get("position"));
                if (Math.abs(offset.y) > Math.abs(offset.x)) {
                    offset.y += -Math.signum(offset.y);
                } else {
                    offset.x += -Math.signum(offset.x);
                }
                Point2D.Double pos = entity.getDirection().left().offset(entity.getDirection().back().offset(entity.getPosition(), offset.y), offset.x);
                Direction direction = offset.y > 0 ? entity.getDirection().back() : entity.getDirection();
                map.setPipe(pos, direction);
            });
        });
    }
}
Also used : Color(java.awt.Color) Rectangle(java.awt.Rectangle) Point2D(java.awt.geom.Point2D) DataPrototype(com.demod.factorio.prototype.DataPrototype) Rectangle2D(java.awt.geom.Rectangle2D) RecipePrototype(com.demod.factorio.prototype.RecipePrototype) BlueprintEntity(com.demod.fbsr.BlueprintEntity) DataTable(com.demod.factorio.DataTable) ArrayList(java.util.ArrayList) RenderUtils(com.demod.fbsr.RenderUtils) Consumer(java.util.function.Consumer) Renderer(com.demod.fbsr.Renderer) Sprite(com.demod.fbsr.Sprite) WorldMap(com.demod.fbsr.WorldMap) EntityRendererFactory(com.demod.fbsr.EntityRendererFactory) List(java.util.List) Utils(com.demod.factorio.Utils) FactorioData(com.demod.factorio.FactorioData) Direction(com.demod.fbsr.Direction) Graphics2D(java.awt.Graphics2D) LuaValue(org.luaj.vm2.LuaValue) Optional(java.util.Optional) EntityPrototype(com.demod.factorio.prototype.EntityPrototype) Layer(com.demod.fbsr.Renderer.Layer) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) LuaValue(org.luaj.vm2.LuaValue) Direction(com.demod.fbsr.Direction) RecipePrototype(com.demod.factorio.prototype.RecipePrototype)

Example 5 with DataTable

use of com.demod.factorio.DataTable in project Factorio-FBSR by demodude4u.

the class BlueprintBotDiscordService method startUp.

@Override
protected void startUp() throws JSONException, IOException {
    configJson = Config.get().getJSONObject("discord");
    DataTable table = FactorioData.getTable();
    System.out.println("Factorio " + FBSR.getVersion() + " Data Loaded.");
    bot = // 
    DCBA.builder().setInfo(// 
    "Blueprint Bot").withSupport(// 
    "Find Demod and complain to him!\nYou can find him over in the [Factorio Discord.](https://discord.gg/factorio)").withTechnology("[FBSR](https://github.com/demodude4u/Factorio-FBSR)", // 
    "Factorio Blueprint String Renderer").withTechnology("[FactorioDataWrapper](https://github.com/demodude4u/Java-Factorio-Data-Wrapper)", // 
    "Factorio Data Scraper").withCredits("Attribution", // 
    "[Factorio](https://www.factorio.com/) - Made by Wube Software").withCredits("Contributors", // 
    "Demod").withCredits("Contributors", // 
    "Bilka").withCredits("Contributors", // 
    "FactorioBlueprints").withCredits("Contributors", // 
    "acid").withCredits("Contributors", // 
    "Vilsol").withInvite(new Permission[] { // 
    Permission.VIEW_CHANNEL, // 
    Permission.MESSAGE_SEND, // 
    Permission.MESSAGE_ATTACH_FILES, // 
    Permission.MESSAGE_EXT_EMOJI, // 
    Permission.MESSAGE_EMBED_LINKS, // 
    Permission.MESSAGE_HISTORY, // 
    Permission.MESSAGE_ADD_REACTION }).withCustomField("Need old !blueprint commands?", // 
    "[BlueprintBot Legacy Invite Link](https://discord.com/oauth2/authorize?scope=bot&client_id=958469202824552498&permissions=379968)").addMessageCommand("Blueprint Image", event -> handleBlueprintMessageCommand(event)).addSlashCommand("blueprint/string", "Renders an image of the blueprint string.", // 
    event -> handleBlueprintSlashCommand(event)).withParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.BOOLEAN, "simple", "Set True to show just the image, no side panels.").withOptionalParam(OptionType.INTEGER, "max-width", "Maximum width of image, in pixels.").withOptionalParam(OptionType.INTEGER, "max-height", "Maximum height of image, in pixels.").withLegacyWarning("blueprint", // 
    "bp").addSlashCommand("blueprint/url", "Renders an image of the blueprint url.", // 
    event -> handleBlueprintSlashCommand(event)).withParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.BOOLEAN, "simple", "Set True to show just the image, no side panels.").withOptionalParam(OptionType.INTEGER, "max-width", "Maximum width of image, in pixels.").withOptionalParam(OptionType.INTEGER, "max-height", "Maximum height of image, in pixels.").addSlashCommand("blueprint/file", "Renders an image of the blueprint attachment.", // 
    event -> handleBlueprintSlashCommand(event)).withParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withOptionalParam(OptionType.BOOLEAN, "simple", "Set True to show just the image, no side panels.").withOptionalParam(OptionType.INTEGER, "max-width", "Maximum width of image, in pixels.").withOptionalParam(OptionType.INTEGER, "max-height", "Maximum height of image, in pixels.").addSlashCommand("json", "Provides a dump of the json data in the specified blueprint string.", // 
    event -> handleBlueprintJsonCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning(// 
    "blueprintJSON").addSlashCommand("upgrade/belts", "Converts all yellow belts into red belts, and all red belts into blue belts.", // 
    event -> handleBlueprintUpgradeBeltsCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning(// 
    "blueprintUpgradeBelts").addSlashCommand("items", "Prints out all of the items needed by the blueprint.", // 
    event -> handleBlueprintItemsCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning("blueprintItems", // 
    "bpItems").addSlashCommand("raw/items", "Prints out all of the raw items needed by the blueprint.", // 
    event -> handleBlueprintItemsRawCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning("blueprintRawItems", // 
    "bpRawItems").addSlashCommand("counts", "Prints out the total counts of entities, items and tiles needed by the blueprint.", event -> handleBlueprintTotalsCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning("blueprintCounts", // 
    "bpCounts").addSlashCommand("book/extract", "Provides an collection of blueprint strings contained within the specified blueprint book.", // 
    event -> handleBlueprintBookExtractCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning(// 
    "blueprintBookExtract").addSlashCommand("book/assemble", "Combines all blueprints (including from other books) from multiple strings into a single book.", // 
    event -> handleBlueprintBookAssembleCommand(event)).withOptionalParam(OptionType.STRING, "string", // 
    "Blueprint string.").withOptionalParam(OptionType.STRING, "url", // 
    "Url containing blueprint string.").withOptionalParam(OptionType.ATTACHMENT, "file", // 
    "File containing blueprint string.").withLegacyWarning(// 
    "blueprintBookAssemble").addSlashCommand("prototype/entity", "Lua data for the specified entity prototype.", createPrototypeCommandHandler("entity", table.getEntities()), // 
    createPrototypeAutoCompleteHandler(table.getEntities())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the entity.").withLegacyWarning(// 
    "prototypeEntity").addSlashCommand("prototype/recipe", "Lua data for the specified recipe prototype.", createPrototypeCommandHandler("recipe", table.getRecipes()), // 
    createPrototypeAutoCompleteHandler(table.getRecipes())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the recipe.").withLegacyWarning(// 
    "prototypeRecipe").addSlashCommand("prototype/fluid", "Lua data for the specified fluid prototype.", createPrototypeCommandHandler("fluid", table.getFluids()), // 
    createPrototypeAutoCompleteHandler(table.getFluids())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the fluid.").withLegacyWarning(// 
    "prototypeFluid").addSlashCommand("prototype/item", "Lua data for the specified item prototype.", createPrototypeCommandHandler("item", table.getItems()), // 
    createPrototypeAutoCompleteHandler(table.getItems())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the item.").withLegacyWarning(// 
    "prototypeItem").addSlashCommand("prototype/technology", "Lua data for the specified technology prototype.", createPrototypeCommandHandler("technology", table.getTechnologies()), // 
    createPrototypeAutoCompleteHandler(table.getTechnologies())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the technology.").withLegacyWarning(// 
    "prototypeTechnology").addSlashCommand("prototype/equipment", "Lua data for the specified equipment prototype.", createPrototypeCommandHandler("equipment", table.getEquipments()), // 
    createPrototypeAutoCompleteHandler(table.getEquipments())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the equipment.").withLegacyWarning(// 
    "prototypeEquipment").addSlashCommand("prototype/tile", "Lua data for the specified tile prototype.", createPrototypeCommandHandler("tile", table.getTiles()), // 
    createPrototypeAutoCompleteHandler(table.getTiles())).withAutoParam(OptionType.STRING, "name", // 
    "Prototype name of the tile.").withLegacyWarning(// 
    "prototypeTile").addSlashCommand("data/raw", "Lua from `data.raw` for the specified key.", // 
    createDataRawCommandHandler(table::getRaw)).withParam(OptionType.STRING, "path", // 
    "Path to identify which key.").withLegacyWarning(// 
    "dataRaw").withCustomSetup(builder -> {
        return // 
        builder.setChunkingFilter(// 
        ChunkingFilter.NONE);
    }).create();
    bot.startAsync().awaitRunning();
    hostingChannelID = configJson.getString("hosting_channel_id");
    ServiceFinder.addService(this);
    ServiceFinder.addService(WatchdogReporter.class, new WatchdogReporter() {

        @Override
        public void notifyInactive(String label) {
            CommandReporting reporting = new CommandReporting("Watchdog Reporter", null, null);
            reporting.addWarning(label + " has gone inactive!");
            bot.submitReport(reporting);
        }

        @Override
        public void notifyReactive(String label) {
            CommandReporting reporting = new CommandReporting("Watchdog Reporter", null, null);
            reporting.addWarning(label + " is now active again!");
            bot.submitReport(reporting);
        }
    });
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) Arrays(java.util.Arrays) EventReply(com.demod.dcba.EventReply) URL(java.net.URL) FBSR(com.demod.fbsr.FBSR) Permission(net.dv8tion.jda.api.Permission) SlashCommandHandler(com.demod.dcba.SlashCommandHandler) Field(net.dv8tion.jda.api.entities.MessageEmbed.Field) TextChannel(net.dv8tion.jda.api.entities.TextChannel) DataTable(com.demod.factorio.DataTable) RenderUtils(com.demod.fbsr.RenderUtils) JSONException(org.json.JSONException) Matcher(java.util.regex.Matcher) JSONObject(org.json.JSONObject) Map(java.util.Map) ZipEntry(java.util.zip.ZipEntry) WebUtils(com.demod.fbsr.WebUtils) Message(net.dv8tion.jda.api.entities.Message) BufferedImage(java.awt.image.BufferedImage) DataPrototype(com.demod.factorio.prototype.DataPrototype) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) Collectors(java.util.stream.Collectors) Config(com.demod.factorio.Config) BlueprintEntity(com.demod.fbsr.BlueprintEntity) List(java.util.List) FactorioData(com.demod.factorio.FactorioData) MessageCommandEvent(com.demod.dcba.MessageCommandEvent) Entry(java.util.Map.Entry) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) BlueprintStringData(com.demod.fbsr.BlueprintStringData) ZipOutputStream(java.util.zip.ZipOutputStream) Blueprint(com.demod.fbsr.Blueprint) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WatchdogReporter(com.demod.fbsr.app.WatchdogService.WatchdogReporter) ImmutableList(com.google.common.collect.ImmutableList) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) SlashCommandEvent(com.demod.dcba.SlashCommandEvent) SimpleEntry(java.util.AbstractMap.SimpleEntry) Attachment(net.dv8tion.jda.api.entities.Message.Attachment) MapVersion(com.demod.fbsr.MapVersion) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) CommandReporting(com.demod.dcba.CommandReporting) DCBA(com.demod.dcba.DCBA) IOException(java.io.IOException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Utils(com.demod.factorio.Utils) DiscordBot(com.demod.dcba.DiscordBot) LuaValue(org.luaj.vm2.LuaValue) AutoCompleteHandler(com.demod.dcba.AutoCompleteHandler) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) ArrayDeque(java.util.ArrayDeque) BlueprintFinder(com.demod.fbsr.BlueprintFinder) ChunkingFilter(net.dv8tion.jda.api.utils.ChunkingFilter) JSONArray(org.json.JSONArray) DataTable(com.demod.factorio.DataTable) CommandReporting(com.demod.dcba.CommandReporting) WatchdogReporter(com.demod.fbsr.app.WatchdogService.WatchdogReporter)

Aggregations

DataTable (com.demod.factorio.DataTable)9 FactorioData (com.demod.factorio.FactorioData)8 Utils (com.demod.factorio.Utils)8 BufferedImage (java.awt.image.BufferedImage)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Optional (java.util.Optional)8 ImmutableList (com.google.common.collect.ImmutableList)7 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7 LuaValue (org.luaj.vm2.LuaValue)7 DataPrototype (com.demod.factorio.prototype.DataPrototype)6 IOException (java.io.IOException)6 SimpleEntry (java.util.AbstractMap.SimpleEntry)6 Collectors (java.util.stream.Collectors)6 JSONArray (org.json.JSONArray)6 JSONException (org.json.JSONException)6 CommandReporting (com.demod.dcba.CommandReporting)5 BlueprintEntity (com.demod.fbsr.BlueprintEntity)5 RenderUtils (com.demod.fbsr.RenderUtils)5