From 25498e98e693701ee9bb7109fb194b3d87e2edd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 31 Jul 2014 13:13:58 +0200 Subject: [PATCH] =?utf8?q?Output=20the=20current=20state=20if=20it?= =?utf8?q?=E2=80=99s=20an=20output=20state.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/rhynodge/states/OutputState.java | 37 ++++++++++++++++++++++ .../rhynodge/triggers/AlwaysTrigger.java | 14 +++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/pterodactylus/rhynodge/states/OutputState.java 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
"); } } -- 2.7.4