--- /dev/null
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class OutputState extends AbstractState {
+
+ private final Optional<String> plainTextOutput;
+ private final Optional<String> htmlOutput;
+
+ public OutputState() {
+ this(Optional.<String>empty(), Optional.<String>empty());
+ }
+
+ public OutputState(Optional<String> plainTextOutput, Optional<String> htmlOutput) {
+ this.plainTextOutput = plainTextOutput;
+ this.htmlOutput = htmlOutput;
+ }
+
+ public Optional<String> plainTextOutput() {
+ return plainTextOutput;
+ }
+
+ public Optional<String> htmlOutput() {
+ return htmlOutput;
+ }
+
+}
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.
*/
@Override
public Output output(Reaction reaction) {
- return new DefaultOutput("true").addText("text/plain", "true").addText("text/html", "<div>true</div>");
+ 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", "<div>true</div>");
}
}