essential-actions

Clone or download

[OBS] - [Set Replay Buffer] - refactored to work with new API

[Twitch] - [Set Colour, Set Commercial] - Refactored UI

Modified Files

package setreplaybuffer;
package setreplaybuffer;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import com.stream_pi.action_api.actionproperty.property.ListValue;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import mother.motherconnection.MotherConnection;
import mother.motherconnection.MotherConnection;
import net.twasi.obsremotejava.OBSRemoteController;
import net.twasi.obsremotejava.OBSRemoteController;
import net.twasi.obsremotejava.callbacks.Callback;
import net.twasi.obsremotejava.callbacks.Callback;
import net.twasi.obsremotejava.requests.StartReplayBuffer.StartReplayBufferResponse;
import net.twasi.obsremotejava.requests.StartReplayBuffer.StartReplayBufferResponse;
public class SetReplayBuffer extends NormalAction
public class SetReplayBuffer extends NormalAction
{
{
public SetReplayBuffer()
public SetReplayBuffer()
{
{
setName("Set Replay Buffer");
setName("Set Replay Buffer");
setCategory("OBS");
setCategory("OBS");
setVisibilityInServerSettingsPane(false);
setVisibilityInServerSettingsPane(false);
setAuthor("rnayabed");
setAuthor("rnayabed");
setVersion(MotherConnection.VERSION);
setVersion(MotherConnection.VERSION);
states = new ArrayList<>();
states = new ArrayList<>();
states.add("Start");
states.addAll(Arrays.asList(
states.add("Stop");
new ListValue("Start"),
states.add("Save");
new ListValue("Stop"),
new ListValue("Save")
));
}
}
private final ArrayList<String> states;
private final ArrayList<ListValue> states;
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property replayStatusActionProperty = new Property("replay_status", Type.LIST);
Property replayStatusActionProperty = new Property("replay_status", Type.LIST);
replayStatusActionProperty.setListValue(states);
replayStatusActionProperty.setListValue(states);
replayStatusActionProperty.setDisplayName("Replay Buffer State");
replayStatusActionProperty.setDisplayName("Replay Buffer State");
Property autoConnectProperty = new Property("auto_connect", Type.BOOLEAN);
Property autoConnectProperty = new Property("auto_connect", Type.BOOLEAN);
autoConnectProperty.setDefaultValueBoolean(true);
autoConnectProperty.setDefaultValueBoolean(true);
autoConnectProperty.setDisplayName("Auto Connect if not connected");
autoConnectProperty.setDisplayName("Auto Connect if not connected");
addClientProperties(replayStatusActionProperty, autoConnectProperty);
addClientProperties(replayStatusActionProperty, autoConnectProperty);
}
}
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
String state = states.get(getClientProperties().getSingleProperty("replay_status").getSelectedIndex());
String state = states.get(getClientProperties().getSingleProperty("replay_status").getSelectedIndex()).getName().toString();
if (MotherConnection.getRemoteController() == null)
if (MotherConnection.getRemoteController() == null)
{
{
boolean autoConnect = getClientProperties().getSingleProperty(
boolean autoConnect = getClientProperties().getSingleProperty(
"auto_connect"
"auto_connect"
).getBoolValue();
).getBoolValue();
if(autoConnect)
if(autoConnect)
{
{
MotherConnection.connect(()->setReplayBuffer(state));
MotherConnection.connect(()->setReplayBuffer(state));
}
}
else
else
{
{
MotherConnection.showOBSNotRunningError();
MotherConnection.showOBSNotRunningError();
}
}
}
}
else
else
{
{
setReplayBuffer(state);
setReplayBuffer(state);
}
}
}
}
private void errorThrow(String status, String error)
private void errorThrow(String status, String error)
{
{
if(status.equals("error"))
if(status.equals("error"))
{
{
new StreamPiAlert("OBS", error, StreamPiAlertType.ERROR).show();
new StreamPiAlert("OBS", error, StreamPiAlertType.ERROR).show();
}
}
}
}
private void setReplayBuffer(String state)
private void setReplayBuffer(String state)
{
{
OBSRemoteController controller = MotherConnection.getRemoteController();
OBSRemoteController controller = MotherConnection.getRemoteController();
switch (state)
switch (state)
{
{
case "Start":
case "Start":
controller.startReplayBuffer(startReplayBufferResponse -> errorThrow(startReplayBufferResponse.getStatus(), startReplayBufferResponse.getError()));
controller.startReplayBuffer(startReplayBufferResponse -> errorThrow(startReplayBufferResponse.getStatus(), startReplayBufferResponse.getError()));
break;
break;
case "Stop":
case "Stop":
controller.stopReplayBuffer(stopReplayBufferResponse -> errorThrow(stopReplayBufferResponse.getStatus(), stopReplayBufferResponse.getError()));
controller.stopReplayBuffer(stopReplayBufferResponse -> errorThrow(stopReplayBufferResponse.getStatus(), stopReplayBufferResponse.getError()));
break;
break;
case "Save":
case "Save":
controller.saveReplayBuffer(saveReplayBufferResponse -> errorThrow(saveReplayBufferResponse.getStatus(), saveReplayBufferResponse.getError()));
controller.saveReplayBuffer(saveReplayBufferResponse -> errorThrow(saveReplayBufferResponse.getStatus(), saveReplayBufferResponse.getError()));
break;
break;
}
}
}
}
}
}
package setcolor;
package setcolor;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.TwirkBuilder;
import com.stream_pi.action_api.actionproperty.property.ListProperty;
import com.stream_pi.action_api.actionproperty.property.ListProperty;
import com.stream_pi.action_api.actionproperty.property.ListValue;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SetColorAction extends NormalAction
public class SetColorAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_sc";
private final String channelNameKey = "channel_name_sc";
private final String usernameColorKey = "username_color_sc";
private final String usernameColorKey = "username_color_sc";
private Twirk twirk;
private Twirk twirk;
@Override
public SetColorAction()
public void initProperties()
{
{
setName("Set Color");
setName("Set Color");
setCategory("Twitch Chat");
setCategory("Twitch Chat");
setVisibilityInServerSettingsPane(false);
setVisibilityInServerSettingsPane(false);
setAuthor("j4ckofalltrades");
setAuthor("j4ckofalltrades");
setVersion(new Version(1, 0, 0));
setVersion(new Version(1, 0, 0));
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
colors = new ArrayList<>();
colors.addAll(
Arrays.asList(
new ListValue("Blue"),
new ListValue("Coral"),
new ListValue("DodgerBlue", "Dodger Blue"),
new ListValue("SpringGreen", "Spring Green"),
new ListValue("YellowGreen", "Yellow Green"),
new ListValue("Green"),
new ListValue("OrangeRed", "Orange Red"),
new ListValue("Red"),
new ListValue("GoldenRod", "Golden Rod"),
new ListValue("HotPink", "Hot Pink"),
new ListValue("CadetBlue", "Cadet Blue"),
new ListValue("SeaGreen", "Sea Green"),
new ListValue("Chocolate"),
new ListValue("BlueViolet", "Blue Violet"),
new ListValue("Firebrick")
)
);
}
}
private final ArrayList<ListValue> colors;
@Override
@Override
public void initAction() throws MinorException
public void initAction() throws MinorException
{
{
Property channelName = new Property(channelNameKey, Type.STRING);
Property channelName = new Property(channelNameKey, Type.STRING);
channelName.setDisplayName("Channel Name");
channelName.setDisplayName("Channel Name");
channelName.setDefaultValueStr("channel_name");
channelName.setDefaultValueStr("channel_name");
channelName.setCanBeBlank(false);
channelName.setCanBeBlank(false);
ListProperty usernameColor = new ListProperty(usernameColorKey);
ListProperty usernameColor = new ListProperty(usernameColorKey);
usernameColor.setDisplayName("Color");
usernameColor.setDisplayName("Color");
usernameColor.setListValue(colors);
addClientProperties(channelName, usernameColor);
addClientProperties(channelName, usernameColor);
}
}
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
credentials.ensureCredentialsInitialized();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String color = getClientProperties().getSingleProperty(usernameColorKey).getStringValue();
final String color = colors.get(getClientProperties().getSingleProperty(usernameColorKey).getSelectedIndex()).getName().toString();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.connect();
twirk.channelMessage(String.format("/color %s", color));
twirk.channelMessage(String.format("/color %s", color));
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
"Failed to change username color",
"Failed to change username color",
String.format("Could not change username color to '%s' for '%s' channel, please try again.",
String.format("Could not change username color to '%s' for '%s' channel, please try again.",
color, channel)
color, channel)
);
);
}
}
}
}
@Override
@Override
public void onShutDown() throws MinorException
public void onShutDown() throws MinorException
{
{
if (twirk != null) {
if (twirk != null) {
try
try
{
{
twirk.disconnect();
twirk.disconnect();
} catch (Exception ex) {
} catch (Exception ex) {
throw new MinorException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package startcommercial;
package startcommercial;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.TwirkBuilder;
import com.stream_pi.action_api.actionproperty.property.ListValue;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.List;
public class StartCommercialAction extends NormalAction
public class StartCommercialAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_sca";
private final String channelNameKey = "channel_name_sca";
private final String durationKey = "duration_sca";
private final String durationKey = "duration_sca";
private Twirk twirk;
private Twirk twirk;
public StartCommercialAction()
public StartCommercialAction()
{
{
setName("Start commercial");
setName("Start commercial");
setCategory("Twitch Chat");
setCategory("Twitch Chat");
setVisibilityInServerSettingsPane(false);
setVisibilityInServerSettingsPane(false);
setAuthor("j4ckofalltrades");
setAuthor("j4ckofalltrades");
setVersion(new Version(1, 0, 0));
setVersion(new Version(1, 0, 0));
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
durations = new ArrayList<>();
durations.addAll(Arrays.asList(
new ListValue("30"),
new ListValue("60"),
new ListValue("90"),
new ListValue("120"),
new ListValue("150"),
new ListValue("180")
));
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property channelName = new Property(channelNameKey, Type.STRING);
Property channelName = new Property(channelNameKey, Type.STRING);
channelName.setDisplayName("Channel Name");
channelName.setDisplayName("Channel Name");
channelName.setDefaultValueStr("channel_name");
channelName.setDefaultValueStr("channel_name");
channelName.setCanBeBlank(false);
channelName.setCanBeBlank(false);
Property duration = new Property(durationKey, Type.LIST);
Property duration = new Property(durationKey, Type.LIST);
duration.setDisplayName("Duration");
duration.setDisplayName("Duration");
duration.setListValue(List.of(
duration.setListValue(durations);
String.valueOf(30),
String.valueOf(60),
String.valueOf(90),
String.valueOf(120),
String.valueOf(150),
String.valueOf(180)));
addClientProperties(channelName, duration);
addClientProperties(channelName, duration);
}
}
private final ArrayList<ListValue> durations;
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
credentials.ensureCredentialsInitialized();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String duration = getClientProperties().getSingleProperty(durationKey).getStringValue();
final String duration = durations.get(getClientProperties().getSingleProperty(durationKey).getSelectedIndex()).getName().toString();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.connect();
twirk.channelMessage(String.format("/commercial %s", duration));
twirk.channelMessage(String.format("/commercial %s", duration));
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
"Failed to start commercial", "Could not start commercial, please try again.");
"Failed to start commercial", "Could not start commercial, please try again.");
}
}
}
}
@Override
@Override
public void onShutDown() throws MinorException
public void onShutDown() throws MinorException
{
{
if (twirk != null) {
if (twirk != null) {
try
try
{
{
twirk.disconnect();
twirk.disconnect();
} catch (Exception ex) {
} catch (Exception ex) {
throw new MinorException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}