essential-actions
Clone or download
Modified Files
package addstreammarker;
package addstreammarker;
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.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.exception.StreamPiException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class AddStreamMarkerAction extends NormalAction
public class AddStreamMarkerAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_asm";
private final String channelNameKey = "channel_name_asm";
private final String descriptionKey = "description_asm";
private final String descriptionKey = "description_asm";
private Twirk twirk;
private Twirk twirk;
public AddStreamMarkerAction()
public AddStreamMarkerAction()
{
{
setName("Add stream marker");
setName("Add stream marker");
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");
}
}
@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 description = new Property(descriptionKey, Type.STRING);
Property description = new Property(descriptionKey, Type.STRING);
description.setDisplayName("Description (Optional, max 140 chars)");
description.setDisplayName("Description (Optional, max 140 chars)");
addClientProperties(channelName, description);
addClientProperties(channelName, description);
}
}
@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 description = getClientProperties().getSingleProperty(descriptionKey).getStringValue();
final String description = getClientProperties().getSingleProperty(descriptionKey).getStringValue();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.connect();
if (description != null && !description.isEmpty()) {
if (description != null && !description.isEmpty()) {
twirk.channelMessage(String.format("/marker %s", description));
twirk.channelMessage(String.format("/marker %s", description));
} else {
} else {
twirk.channelMessage("/marker");
twirk.channelMessage("/marker");
}
}
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
"Failed to add marker to stream\nCould not add stream marker, please try again."
"Failed to add marker to stream\nCould not add stream marker, 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.");
}
}
}
}
}
}
}
}
package hostchannel;
package hostchannel;
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.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.exception.StreamPiException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class HostChannelAction extends NormalAction
public class HostChannelAction extends NormalAction
{
{
private final String channelKey = "channel_hc";
private final String channelKey = "channel_hc";
private final String channelToHostKey = "channel_to_host_hc";
private final String channelToHostKey = "channel_to_host_hc";
private Twirk twirk;
private Twirk twirk;
public HostChannelAction()
public HostChannelAction()
{
{
setName("Host Channel");
setName("Host Channel");
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");
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelKey, Type.STRING);
Property channel = new Property(channelKey, Type.STRING);
channel.setDisplayName("Channel");
channel.setDisplayName("Channel");
channel.setDefaultValueStr("channel");
channel.setDefaultValueStr("channel");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
Property channelToHost = new Property(channelToHostKey, Type.STRING);
Property channelToHost = new Property(channelToHostKey, Type.STRING);
channelToHost.setDisplayName("Channel to host");
channelToHost.setDisplayName("Channel to host");
channelToHost.setDefaultValueStr("channel_to_host");
channelToHost.setDefaultValueStr("channel_to_host");
channelToHost.setCanBeBlank(false);
channelToHost.setCanBeBlank(false);
addClientProperties(channel, channelToHost);
addClientProperties(channel, channelToHost);
}
}
@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(channelKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelKey).getStringValue();
final String channelToHost = getClientProperties().getSingleProperty(channelToHostKey).getStringValue();
final String channelToHost = getClientProperties().getSingleProperty(channelToHostKey).getStringValue();
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("/host %s", channelToHost));
twirk.channelMessage(String.format("/host %s", channelToHost));
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
"Failed to host channel",
"Failed to host channel",
String.format("Could not host channel '%s', please try again.", channelToHost));
String.format("Could not host channel '%s', please try again.", channelToHost));
}
}
}
}
@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 raidchannel;
package raidchannel;
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.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.exception.StreamPiException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class RaidChannelAction extends NormalAction
public class RaidChannelAction extends NormalAction
{
{
private final String channelKey = "channel_rc";
private final String channelKey = "channel_rc";
private final String channelToRaidKey = "channel_to_raid_rc";
private final String channelToRaidKey = "channel_to_raid_rc";
private Twirk twirk;
private Twirk twirk;
public RaidChannelAction()
public RaidChannelAction()
{
{
setName("Raid Channel");
setName("Raid Channel");
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");
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelKey, Type.STRING);
Property channel = new Property(channelKey, Type.STRING);
channel.setDisplayName("Channel");
channel.setDisplayName("Channel");
channel.setDefaultValueStr("channel");
channel.setDefaultValueStr("channel");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
Property channelToRaid = new Property(channelToRaidKey, Type.STRING);
Property channelToRaid = new Property(channelToRaidKey, Type.STRING);
channelToRaid.setDisplayName("Channel to raid");
channelToRaid.setDisplayName("Channel to raid");
channelToRaid.setDefaultValueStr("channel_to_raid");
channelToRaid.setDefaultValueStr("channel_to_raid");
channelToRaid.setCanBeBlank(false);
channelToRaid.setCanBeBlank(false);
addClientProperties(channel, channelToRaid);
addClientProperties(channel, channelToRaid);
}
}
@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(channelKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelKey).getStringValue();
final String channelToRaid = getClientProperties().getSingleProperty(channelToRaidKey).getStringValue();
final String channelToRaid = getClientProperties().getSingleProperty(channelToRaidKey).getStringValue();
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("/raid %s", channelToRaid));
twirk.channelMessage(String.format("/raid %s", channelToRaid));
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(String.format("Could not raid channel '%s', please try again.", channelToRaid));
throw new MinorException(String.format("Could not raid channel '%s', please try again.", channelToRaid));
}
}
}
}
@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 sendchannelmsg;
package sendchannelmsg;
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.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.StreamPiException;
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;
public class SendChannelMessageAction extends NormalAction
public class SendChannelMessageAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_scm";
private final String channelNameKey = "channel_name_scm";
private final String channelMsgKey = "channel_msg_scm";
private final String channelMsgKey = "channel_msg_scm";
private Twirk twirk;
private Twirk twirk;
public SendChannelMessageAction()
public SendChannelMessageAction()
{
{
setName("Send Channel Message");
setName("Send Channel Message");
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");
}
}
@Override
@Override
public void initProperties() throws Exception
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 channelMessage = new Property(channelMsgKey, Type.STRING);
Property channelMessage = new Property(channelMsgKey, Type.STRING);
channelMessage.setDisplayName("Message");
channelMessage.setDisplayName("Message");
channelMessage.setDefaultValueStr("channel_msg");
channelMessage.setDefaultValueStr("channel_msg");
channelMessage.setCanBeBlank(false);
channelMessage.setCanBeBlank(false);
addClientProperties(channelName, channelMessage);
addClientProperties(channelName, channelMessage);
}
}
@Override
@Override
public void initAction() throws Exception
public void onActionClicked() throws MinorException
{
}
@Override
public void onActionClicked() throws Exception
{
{
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 message = getClientProperties().getSingleProperty(channelMsgKey).getStringValue();
final String message = getClientProperties().getSingleProperty(channelMsgKey).getStringValue();
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(message);
twirk.channelMessage(message);
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException(
throw new MinorException(
"Failed to send channel message",
"Failed to send channel message",
String.format("Could not send message '%s' to '%s' channel, please try again.",
String.format("Could not send message '%s' to '%s' channel, please try again.",
channel, message)
channel, message)
);
);
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
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.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.StreamPiException;
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;
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
@Override
public void initProperties() throws Exception
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");
}
}
@Override
@Override
public void initAction() throws Exception
public void initAction() throws Exception
{
{
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 usernameColor = new Property(usernameColorKey, Type.STRING);
Property usernameColor = new Property(usernameColorKey, Type.STRING);
usernameColor.setDisplayName("Color");
usernameColor.setDisplayName("Color");
usernameColor.setDefaultValueStr("color");
usernameColor.setDefaultValueStr("color");
usernameColor.setCanBeBlank(false);
usernameColor.setCanBeBlank(false);
addClientProperties(channelName, usernameColor);
addClientProperties(channelName, usernameColor);
}
}
@Override
@Override
public void onActionClicked() throws Exception
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 = getClientProperties().getSingleProperty(usernameColorKey).getStringValue();
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 StreamPiException(
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 Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package slow_mode;
package slow_mode;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.events.TwirkListener;
import com.gikk.twirk.events.TwirkListener;
import com.gikk.twirk.types.roomstate.Roomstate;
import com.gikk.twirk.types.roomstate.Roomstate;
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.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.StreamPiException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class SlowModeAction extends ToggleAction
public class SlowModeAction extends ToggleAction
{
{
private final String channelNameKey = "channel_name_sm";
private final String channelNameKey = "channel_name_sm";
private final String slowModeDurationKey = "slow_mode_duration";
private final String slowModeDurationKey = "slow_mode_duration";
private Twirk twirk;
private Twirk twirk;
public SlowModeAction()
public SlowModeAction()
{
{
setName("Toggle Slow Mode");
setName("Toggle Slow Mode");
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");
}
}
@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 durationInSecs = new Property(slowModeDurationKey, Type.INTEGER);
Property durationInSecs = new Property(slowModeDurationKey, Type.INTEGER);
durationInSecs.setDefaultValueInt(600);
durationInSecs.setDefaultValueInt(600);
durationInSecs.setDisplayName("Duration (in seconds)");
durationInSecs.setDisplayName("Duration (in seconds)");
addClientProperties(channelName, durationInSecs);
addClientProperties(channelName, durationInSecs);
}
}
@Override
@Override
public void onToggleOn() throws Exception
public void onToggleOn() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
final int duration = getClientProperties().getSingleProperty(slowModeDurationKey).getIntValue();
final int duration = getClientProperties().getSingleProperty(slowModeDurationKey).getIntValue();
twirk.channelMessage(String.format("/slow %d", duration));
twirk.channelMessage(String.format("/slow %d", duration));
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(false);
setCurrentStatus(false);
throw new StreamPiException("Failed to enable slow mode.", "Please try again.");
throw new MinorException("Failed to enable slow mode.", "Please try again.");
}
}
}
}
@Override
@Override
public void onToggleOff() throws Exception
public void onToggleOff() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/slowoff");
twirk.channelMessage("/slowoff");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(true);
setCurrentStatus(true);
throw new StreamPiException("Failed to disable slow mode.", "Please try again.");
throw new MinorException("Failed to disable slow mode.", "Please try again.");
}
}
}
}
private void connectToChannel() throws Exception
private void connectToChannel() throws Exception
{
{
if (twirk != null) {
if (twirk != null) {
if (!twirk.isConnected()) {
if (!twirk.isConnected()) {
twirk.connect();
twirk.connect();
}
}
return;
return;
}
}
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();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.addIrcListener(new TwirkListener()
twirk.addIrcListener(new TwirkListener()
{
{
@Override
@Override
public void onRoomstate(Roomstate roomstate)
public void onRoomstate(Roomstate roomstate)
{
{
try
try
{
{
setCurrentStatus(roomstate.getSlowModeTimer() > 0);
setCurrentStatus(roomstate.getSlowModeTimer() > 0);
} catch (MinorException e)
} catch (MinorException e)
{
{
throw new RuntimeException(e);
throw new RuntimeException(e);
}
}
}
}
});
});
twirk.connect();
twirk.connect();
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException("Failed to connect to Twitch",
throw new MinorException("Failed to connect to Twitch",
String.format("Could not connect to '%s' channel.", channel));
String.format("Could not connect to '%s' channel.", channel));
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("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.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.StreamPiException;
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.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");
}
}
@Override
@Override
public void initProperties() throws Exception
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(List.of(
String.valueOf(30),
String.valueOf(30),
String.valueOf(60),
String.valueOf(60),
String.valueOf(90),
String.valueOf(90),
String.valueOf(120),
String.valueOf(120),
String.valueOf(150),
String.valueOf(150),
String.valueOf(180)));
String.valueOf(180)));
addClientProperties(channelName, duration);
addClientProperties(channelName, duration);
}
}
@Override
@Override
public void initAction() throws Exception
public void onActionClicked() throws MinorException
{
}
@Override
public void onActionClicked() throws Exception
{
{
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 = getClientProperties().getSingleProperty(durationKey).getStringValue();
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 StreamPiException(
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 Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package subs_only;
package subs_only;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.events.TwirkListener;
import com.gikk.twirk.events.TwirkListener;
import com.gikk.twirk.types.roomstate.Roomstate;
import com.gikk.twirk.types.roomstate.Roomstate;
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.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.StreamPiException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class SubsOnlyAction extends ToggleAction
public class SubsOnlyAction extends ToggleAction
{
{
private final String channelNameKey = "channel_name_so";
private final String channelNameKey = "channel_name_so";
private Twirk twirk;
private Twirk twirk;
public SubsOnlyAction()
public SubsOnlyAction()
{
{
setName("Toggle Subs-Only Chat");
setName("Toggle Subs-Only Chat");
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");
}
}
@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);
addClientProperties(channelName);
addClientProperties(channelName);
}
}
@Override
@Override
public void onToggleOn() throws Exception
public void onToggleOn() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/subscribers");
twirk.channelMessage("/subscribers");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(false);
setCurrentStatus(false);
throw new StreamPiException("Failed to enable subscribers only mode.", "Please try again.");
throw new MinorException("Failed to enable subscribers only mode.", "Please try again.");
}
}
}
}
@Override
@Override
public void onToggleOff() throws Exception
public void onToggleOff() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/subscribersoff");
twirk.channelMessage("/subscribersoff");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(true);
setCurrentStatus(true);
throw new StreamPiException("Failed to disable subscribers only mode.", "Please try again.");
throw new MinorException("Failed to disable subscribers only mode.", "Please try again.");
}
}
}
}
private void connectToChannel() throws Exception
private void connectToChannel() throws Exception
{
{
if (twirk != null)
if (twirk != null)
{
{
if (!twirk.isConnected())
if (!twirk.isConnected())
{
{
twirk.connect();
twirk.connect();
}
}
return;
return;
}
}
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();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.addIrcListener(new TwirkListener()
twirk.addIrcListener(new TwirkListener()
{
{
@Override
@Override
public void onRoomstate(Roomstate roomstate)
public void onRoomstate(Roomstate roomstate)
{
{
try
try
{
{
setCurrentStatus(roomstate.getSubMode() == 1);
setCurrentStatus(roomstate.getSubMode() == 1);
} catch (MinorException e)
} catch (MinorException e)
{
{
throw new RuntimeException(e);
throw new RuntimeException(e);
}
}
}
}
});
});
twirk.connect();
twirk.connect();
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException("Failed to connect to Twitch",
throw new MinorException("Failed to connect to Twitch",
String.format("Could not connect to '%s' channel.", channel));
String.format("Could not connect to '%s' channel.", channel));
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package unhost;
package unhost;
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.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.StreamPiException;
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;
public class UnhostAction extends NormalAction
public class UnhostAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_uh";
private final String channelNameKey = "channel_name_uh";
private Twirk twirk;
private Twirk twirk;
public UnhostAction()
public UnhostAction()
{
{
setName("Unhost");
setName("Unhost");
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");
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelNameKey, Type.STRING);
Property channel = new Property(channelNameKey, Type.STRING);
channel.setDisplayName("Channel");
channel.setDisplayName("Channel");
channel.setDefaultValueStr("channel_name");
channel.setDefaultValueStr("channel_name");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
addClientProperties(channel);
addClientProperties(channel);
}
}
@Override
@Override
public void initAction() throws Exception
public void onActionClicked() throws MinorException
{
}
@Override
public void onActionClicked() throws Exception
{
{
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();
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("/unhost");
twirk.channelMessage("/unhost");
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException(
throw new MinorException(
"Failed to cancel channel hosting",
"Failed to cancel channel hosting",
"Could not cancel channel hosting, please try again.");
"Could not cancel channel hosting, please try again.");
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package unraid;
package unraid;
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.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.StreamPiException;
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;
public class UnraidAction extends NormalAction
public class UnraidAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_ur";
private final String channelNameKey = "channel_name_ur";
private Twirk twirk;
private Twirk twirk;
public UnraidAction()
public UnraidAction()
{
{
setName("Unraid");
setName("Unraid");
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");
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelNameKey, Type.STRING);
Property channel = new Property(channelNameKey, Type.STRING);
channel.setDisplayName("Channel");
channel.setDisplayName("Channel");
channel.setDefaultValueStr("channel_name");
channel.setDefaultValueStr("channel_name");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
addClientProperties(channel);
addClientProperties(channel);
}
}
@Override
@Override
public void initAction() throws Exception
public void onActionClicked() throws MinorException
{
}
@Override
public void onActionClicked() throws Exception
{
{
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();
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("/unraid");
twirk.channelMessage("/unraid");
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException(
throw new MinorException(
"Failed to cancel channel raid",
"Failed to cancel channel raid",
"Could not cancel channel raid, please try again.");
"Could not cancel channel raid, please try again.");
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}
package whisper;
package whisper;
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.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.StreamPiException;
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;
public class WhisperAction extends NormalAction
public class WhisperAction extends NormalAction
{
{
private final String usernameKey = "username_wa";
private final String usernameKey = "username_wa";
private final String messageKey = "message_wa";
private final String messageKey = "message_wa";
private Twirk twirk;
private Twirk twirk;
public WhisperAction()
public WhisperAction()
{
{
setName("Whisper");
setName("Whisper");
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");
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws MinorException
{
{
Property usernameProp = new Property(usernameKey, Type.STRING);
Property usernameProp = new Property(usernameKey, Type.STRING);
usernameProp.setDisplayName("Twitch Username");
usernameProp.setDisplayName("Twitch Username");
usernameProp.setDefaultValueStr("username");
usernameProp.setDefaultValueStr("username");
usernameProp.setCanBeBlank(false);
usernameProp.setCanBeBlank(false);
Property messageProp = new Property(messageKey, Type.STRING);
Property messageProp = new Property(messageKey, Type.STRING);
messageProp.setDisplayName("Message");
messageProp.setDisplayName("Message");
messageProp.setDefaultValueStr("message");
messageProp.setDefaultValueStr("message");
messageProp.setCanBeBlank(false);
messageProp.setCanBeBlank(false);
addClientProperties(usernameProp, messageProp);
addClientProperties(usernameProp, messageProp);
}
}
@Override
@Override
public void initAction() throws Exception
public void onActionClicked() throws MinorException
{
}
@Override
public void onActionClicked() throws Exception
{
{
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
credentials.ensureCredentialsInitialized();
final String username = getClientProperties().getSingleProperty(usernameKey).getStringValue();
final String username = getClientProperties().getSingleProperty(usernameKey).getStringValue();
final String message = getClientProperties().getSingleProperty(messageKey).getStringValue();
final String message = getClientProperties().getSingleProperty(messageKey).getStringValue();
try
try
{
{
twirk = new TwirkBuilder(username, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(username, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.connect();
twirk.whisper(username, message);
twirk.whisper(username, message);
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException(
throw new MinorException(
"Failed to send message to user",
"Failed to send message to user",
String.format("Could not send message '%s' to user '%s', please try again.",
String.format("Could not send message '%s' to user '%s', please try again.",
username, message)
username, message)
);
);
}
}
}
}
@Override
@Override
public void onShutDown() throws Exception
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 StreamPiException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}