From: David ‘Bombe’ Roden Date: Thu, 31 Jul 2014 11:13:58 +0000 (+0200) Subject: Output the current state if it’s an output state. X-Git-Tag: v2~221 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=25498e98e693701ee9bb7109fb194b3d87e2edd5;p=rhynodge.git Output the current state if it’s an output state. --- diff --git a/src/main/java/net/pterodactylus/rhynodge/states/OutputState.java b/src/main/java/net/pterodactylus/rhynodge/states/OutputState.java new file mode 100644 index 0000000..68a951d --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/states/OutputState.java @@ -0,0 +1,37 @@ +package net.pterodactylus.rhynodge.states; + +import java.util.Optional; + +import net.pterodactylus.rhynodge.State; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * {@link State} implementation that can expose itself as plain text and/or + * HTML. + * + * @author David ‘Bombe’ Roden + */ +public class OutputState extends AbstractState { + + private final Optional plainTextOutput; + private final Optional htmlOutput; + + public OutputState() { + this(Optional.empty(), Optional.empty()); + } + + public OutputState(Optional plainTextOutput, Optional htmlOutput) { + this.plainTextOutput = plainTextOutput; + this.htmlOutput = htmlOutput; + } + + public Optional plainTextOutput() { + return plainTextOutput; + } + + public Optional htmlOutput() { + return htmlOutput; + } + +} diff --git a/src/main/java/net/pterodactylus/rhynodge/triggers/AlwaysTrigger.java b/src/main/java/net/pterodactylus/rhynodge/triggers/AlwaysTrigger.java index b9ec39a..b916237 100644 --- a/src/main/java/net/pterodactylus/rhynodge/triggers/AlwaysTrigger.java +++ b/src/main/java/net/pterodactylus/rhynodge/triggers/AlwaysTrigger.java @@ -22,6 +22,7 @@ import net.pterodactylus.rhynodge.State; import net.pterodactylus.rhynodge.Trigger; import net.pterodactylus.rhynodge.output.DefaultOutput; import net.pterodactylus.rhynodge.output.Output; +import net.pterodactylus.rhynodge.states.OutputState; /** * {@link Trigger} implementation that always triggers. @@ -58,7 +59,18 @@ public class AlwaysTrigger implements Trigger { */ @Override public Output output(Reaction reaction) { - return new DefaultOutput("true").addText("text/plain", "true").addText("text/html", "
true
"); + DefaultOutput output = new DefaultOutput(reaction.name()); + if (currentState instanceof OutputState) { + OutputState outputState = (OutputState) currentState; + if (outputState.plainTextOutput().isPresent()) { + output = output.addText("text/plain", outputState.plainTextOutput().get()); + } + if (outputState.htmlOutput().isPresent()) { + output = output.addText("text/html", outputState.htmlOutput().get()); + } + return output; + } + return output.addText("text/plain", "true").addText("text/html", "
true
"); } }