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.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(TwitchChatCredentials.HELP_LINK);
}
}
@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 clearchat;
package clearchat;
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.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 ClearChatAction extends NormalAction
public class ClearChatAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_cc";
private final String channelNameKey = "channel_name_cc";
private Twirk twirk;
private Twirk twirk;
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
setName("Clear Chat");
setName("Clear 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(TwitchChatCredentials.HELP_LINK);
}
}
@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);
addClientProperties(channelName);
addClientProperties(channelName);
}
}
@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();
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("/clear");
twirk.channelMessage("/clear");
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
String.format("Could not clear chat for '%s' channel, please try again.", channel)
String.format("Could not clear chat for '%s' channel, please try again.", 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 emote_only;
package emote_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.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class EmoteOnlyAction extends ToggleAction
public class EmoteOnlyAction extends ToggleAction
{
{
private final String channelNameKey = "channel_name_eo";
private final String channelNameKey = "channel_name_eo";
private Twirk twirk;
private Twirk twirk;
public EmoteOnlyAction()
public EmoteOnlyAction()
{
{
setName("Toggle Emote-Only Chat");
setName("Toggle Emote-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(TwitchChatCredentials.HELP_LINK);
}
}
@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 MinorException
public void onToggleOn() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/emoteonly");
twirk.channelMessage("/emoteonly");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(false);
setCurrentStatus(false);
throw new MinorException("Failed to enable emote-only mode.", "Please try again.");
throw new MinorException("Failed to enable emote-only mode.", "Please try again.");
}
}
}
}
@Override
@Override
public void onToggleOff() throws MinorException
public void onToggleOff() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/emoteonlyoff");
twirk.channelMessage("/emoteonlyoff");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(true);
setCurrentStatus(true);
throw new MinorException("Failed to disable emote-only mode.", "Please try again.");
throw new MinorException("Failed to disable emote-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.getEmoteOnlyMode() == 1);
setCurrentStatus(roomstate.getEmoteOnlyMode() == 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 MinorException("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 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 followers_only;
package followers_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.ListValue;
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.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.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
public class FollowersOnlyAction extends ToggleAction
public class FollowersOnlyAction extends ToggleAction
{
{
private final String channelNameKey = "channel_name_fo";
private final String channelNameKey = "channel_name_fo";
private final String durationKey = "duration_fo";
private final String durationKey = "duration_fo";
private final ArrayList<ListValue> durations;
private final ArrayList<ListValue> durations;
private Twirk twirk;
private Twirk twirk;
public FollowersOnlyAction()
public FollowersOnlyAction()
{
{
setName("Toggle Followers-Only Chat");
setName("Toggle Followers-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(TwitchChatCredentials.HELP_LINK);
durations = new ArrayList<>();
durations = new ArrayList<>();
durations.addAll(Arrays.asList(
durations.addAll(Arrays.asList(
new ListValue("all"),
new ListValue("all"),
new ListValue("30m"),
new ListValue("30m"),
new ListValue("2h"),
new ListValue("2h"),
new ListValue("2d"),
new ListValue("2d"),
new ListValue("1w"),
new ListValue("1w"),
new ListValue("3mo")
new ListValue("3mo")
));
));
}
}
@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("Follow Duration");
duration.setDisplayName("Follow Duration");
duration.setListValue(durations);
duration.setListValue(durations);
addClientProperties(channelName, duration);
addClientProperties(channelName, duration);
}
}
@Override
@Override
public void onToggleOn() throws MinorException
public void onToggleOn() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
final String followerDuration = durations.get(getClientProperties().getSingleProperty(durationKey)
final String followerDuration = durations.get(getClientProperties().getSingleProperty(durationKey)
.getSelectedIndex()).getName().toString();
.getSelectedIndex()).getName().toString();
if (followerDuration.equals("all"))
if (followerDuration.equals("all"))
{
{
twirk.channelMessage("/followers");
twirk.channelMessage("/followers");
} else {
} else {
twirk.channelMessage(String.format("/followers %s", followerDuration));
twirk.channelMessage(String.format("/followers %s", followerDuration));
}
}
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(false);
setCurrentStatus(false);
throw new MinorException("Failed to enable followers only mode.", "Please try again.");
throw new MinorException("Failed to enable followers only mode.", "Please try again.");
}
}
}
}
@Override
@Override
public void onToggleOff() throws MinorException
public void onToggleOff() throws MinorException
{
{
try
try
{
{
connectToChannel();
connectToChannel();
twirk.channelMessage("/followersoff");
twirk.channelMessage("/followersoff");
} catch (Exception ex)
} catch (Exception ex)
{
{
setCurrentStatus(true);
setCurrentStatus(true);
throw new MinorException("Failed to disable followers only mode.", "Please try again.");
throw new MinorException("Failed to disable followers 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.getFollowersMode() == 1);
setCurrentStatus(roomstate.getFollowersMode() == 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 MinorException("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 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.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(TwitchChatCredentials.HELP_LINK);
}
}
@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.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(TwitchChatCredentials.HELP_LINK);
}
}
@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.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;
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(TwitchChatCredentials.HELP_LINK);
}
}
@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 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 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 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 MinorException(
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 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 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.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.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
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;
public SetColorAction()
public SetColorAction()
{
{
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(TwitchChatCredentials.HELP_LINK);
colors = new ArrayList<>();
colors = new ArrayList<>();
colors.addAll(
colors.addAll(
Arrays.asList(
Arrays.asList(
new ListValue("Blue"),
new ListValue("Blue"),
new ListValue("Coral"),
new ListValue("Coral"),
new ListValue("DodgerBlue", "Dodger Blue"),
new ListValue("DodgerBlue", "Dodger Blue"),
new ListValue("SpringGreen", "Spring Green"),
new ListValue("SpringGreen", "Spring Green"),
new ListValue("YellowGreen", "Yellow Green"),
new ListValue("YellowGreen", "Yellow Green"),
new ListValue("Green"),
new ListValue("Green"),
new ListValue("OrangeRed", "Orange Red"),
new ListValue("OrangeRed", "Orange Red"),
new ListValue("Red"),
new ListValue("Red"),
new ListValue("GoldenRod", "Golden Rod"),
new ListValue("GoldenRod", "Golden Rod"),
new ListValue("HotPink", "Hot Pink"),
new ListValue("HotPink", "Hot Pink"),
new ListValue("CadetBlue", "Cadet Blue"),
new ListValue("CadetBlue", "Cadet Blue"),
new ListValue("SeaGreen", "Sea Green"),
new ListValue("SeaGreen", "Sea Green"),
new ListValue("Chocolate"),
new ListValue("Chocolate"),
new ListValue("BlueViolet", "Blue Violet"),
new ListValue("BlueViolet", "Blue Violet"),
new ListValue("Firebrick")
new ListValue("Firebrick")
)
)
);
);
}
}
private final ArrayList<ListValue> colors;
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);
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 = colors.get(getClientProperties().getSingleProperty(usernameColorKey).getSelectedIndex()).getName().toString();
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 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.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(TwitchChatCredentials.HELP_LINK);
}
}
@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 MinorException
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 MinorException("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 MinorException
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 MinorException("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 MinorException("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 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.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.ArrayList;
import java.util.Arrays;
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(TwitchChatCredentials.HELP_LINK);
durations = new ArrayList<>();
durations = new ArrayList<>();
durations.addAll(Arrays.asList(
durations.addAll(Arrays.asList(
new ListValue("30"),
new ListValue("30"),
new ListValue("60"),
new ListValue("60"),
new ListValue("90"),
new ListValue("90"),
new ListValue("120"),
new ListValue("120"),
new ListValue("150"),
new ListValue("150"),
new ListValue("180")
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(durations);
duration.setListValue(durations);
addClientProperties(channelName, duration);
addClientProperties(channelName, duration);
}
}
private final ArrayList<ListValue> durations;
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 = durations.get(getClientProperties().getSingleProperty(durationKey).getSelectedIndex()).getName().toString();
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.");
}
}
}
}
}
}
}
}
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.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(TwitchChatCredentials.HELP_LINK);
}
}
@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 MinorException
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 MinorException("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 MinorException
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 MinorException("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 MinorException("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 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 connect;
package connect;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.ControlType;
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 connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
public class TwitchChatConnectAction extends NormalAction
public class TwitchChatConnectAction extends NormalAction
{
{
private static final String ACCESS_TOKEN_KEY = "twitch_chat_access_token";
private static final String ACCESS_TOKEN_KEY = "twitch_chat_access_token";
private static final String NICKNAME_KEY = "twitch_chat_nickname";
private static final String NICKNAME_KEY = "twitch_chat_nickname";
private final Button clearCredentialsBtn;
private final Button clearCredentialsBtn;
public TwitchChatConnectAction()
public TwitchChatConnectAction()
{
{
setName("Twitch Chat Plugin");
setName("Twitch Chat Plugin");
setCategory("Twitch Chat");
setCategory("Twitch Chat");
setVisibilityInPluginsPane(false);
setVisibilityInPluginsPane(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(TwitchChatCredentials.HELP_LINK);
clearCredentialsBtn = new Button("Clear Twitch chat credentials");
clearCredentialsBtn = new Button("Clear Twitch chat credentials");
onClearCredentials();
onClearCredentials();
setServerSettingsButtonBar(clearCredentialsBtn);
setServerSettingsButtonBar(clearCredentialsBtn);
}
}
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property twitchNicknameProp = new Property(NICKNAME_KEY, Type.STRING);
Property twitchNicknameProp = new Property(NICKNAME_KEY, Type.STRING);
twitchNicknameProp.setDisplayName("Twitch Username");
twitchNicknameProp.setDisplayName("Twitch Username");
Property twitchAccessTokenProp = new Property(ACCESS_TOKEN_KEY, Type.STRING);
Property twitchAccessTokenProp = new Property(ACCESS_TOKEN_KEY, Type.STRING);
twitchAccessTokenProp.setControlType(ControlType.TEXT_FIELD_MASKED);
twitchAccessTokenProp.setControlType(ControlType.TEXT_FIELD_MASKED);
twitchAccessTokenProp.setDisplayName("Access Token");
twitchAccessTokenProp.setDisplayName("Access Token");
addServerProperties(twitchNicknameProp, twitchAccessTokenProp);
addServerProperties(twitchNicknameProp, twitchAccessTokenProp);
}
}
@Override
@Override
public void initAction() throws MinorException
public void initAction() throws MinorException
{
{
clearCredentialsBtn.setDisable(isEmptyCredentials());
clearCredentialsBtn.setDisable(isEmptyCredentials());
TwitchChatCredentials.setCredentials(
TwitchChatCredentials.setCredentials(
new TwitchChatCredentials.ChatCredentials()
new TwitchChatCredentials.ChatCredentials()
.setOauthToken(getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue())
.setOauthToken(getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue())
.setNickname(getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue()));
.setNickname(getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue()));
}
}
private boolean isEmptyCredentials() throws MinorException {
private boolean isEmptyCredentials() throws MinorException {
final String twitchNickname = getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue();
final String twitchNickname = getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue();
final String twitchChatOauthToken = getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue();
final String twitchChatOauthToken = getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue();
return (twitchNickname == null || twitchNickname.isEmpty()) &&
return (twitchNickname == null || twitchNickname.isEmpty()) &&
(twitchChatOauthToken == null || twitchChatOauthToken.isEmpty());
(twitchChatOauthToken == null || twitchChatOauthToken.isEmpty());
}
}
private void onClearCredentials()
private void onClearCredentials()
{
{
clearCredentialsBtn.setOnAction(action ->
clearCredentialsBtn.setOnAction(action ->
{
{
try
try
{
{
getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).setStringValue("");
getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).setStringValue("");
getServerProperties().getSingleProperty(NICKNAME_KEY).setStringValue("");
getServerProperties().getSingleProperty(NICKNAME_KEY).setStringValue("");
saveServerProperties();
saveServerProperties();
new StreamPiAlert(
new StreamPiAlert(
"Twitch chat credentials cleared",
"Twitch chat credentials cleared",
"To revoke token access, disconnect \"Twitch Chat OAuth Token Generator\" from your Twitch settings (https://www.twitch.tv/settings/connections).",
"To revoke token access, disconnect \"Twitch Chat OAuth Token Generator\" from your Twitch settings (https://www.twitch.tv/settings/connections).",
StreamPiAlertType.INFORMATION)
StreamPiAlertType.INFORMATION)
.show();
.show();
} catch (Exception e)
} catch (Exception e)
{
{
new StreamPiAlert(
new StreamPiAlert(
"Failed to save chat credentials",
"Failed to save chat credentials",
"An error has occurred while clearing chat credentials, please try again.",
"An error has occurred while clearing chat credentials, please try again.",
StreamPiAlertType.WARNING)
StreamPiAlertType.WARNING)
.show();
.show();
}
}
});
});
}
}
}
}
package connect.chat;
package connect.chat;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
public final class TwitchChatCredentials
public final class TwitchChatCredentials
{
{
public static final String HELP_LINK = "https://github.com/stream-pi/essential-actions/blob/master/twitch/README.md";
private static ChatCredentials credentials;
private static ChatCredentials credentials;
public static ChatCredentials getCredentials()
public static ChatCredentials getCredentials()
{
{
return credentials;
return credentials;
}
}
public static void setCredentials(ChatCredentials chatCredentials)
public static void setCredentials(ChatCredentials chatCredentials)
{
{
credentials = chatCredentials;
credentials = chatCredentials;
}
}
public static class ChatCredentials
public static class ChatCredentials
{
{
String nickname;
String nickname;
String oauthToken;
String oauthToken;
public void ensureCredentialsInitialized() throws MinorException
public void ensureCredentialsInitialized() throws MinorException
{
{
final String twitchNickname = nickname;
final String twitchNickname = nickname;
boolean isNicknameInitialized = twitchNickname != null && !twitchNickname.isEmpty();
boolean isNicknameInitialized = twitchNickname != null && !twitchNickname.isEmpty();
final String twitchChatOauthToken = oauthToken;
final String twitchChatOauthToken = oauthToken;
boolean isTokenInitialized = twitchChatOauthToken != null && !twitchChatOauthToken.isEmpty();
boolean isTokenInitialized = twitchChatOauthToken != null && !twitchChatOauthToken.isEmpty();
if (!isNicknameInitialized && !isTokenInitialized)
if (!isNicknameInitialized && !isTokenInitialized)
{
{
throw new MinorException(
throw new MinorException(
"Twitch Chat config uninitialized\n" +
"Twitch Chat config uninitialized\n" +
"Please check that the Twitch Chat plugin configuration is correct.");
"Please check that the Twitch Chat plugin configuration is correct.");
}
}
}
}
public String getNickname()
public String getNickname()
{
{
return nickname;
return nickname;
}
}
public ChatCredentials setNickname(String nickname)
public ChatCredentials setNickname(String nickname)
{
{
this.nickname = nickname;
this.nickname = nickname;
return this;
return this;
}
}
public String getOauthToken()
public String getOauthToken()
{
{
return oauthToken;
return oauthToken;
}
}
public ChatCredentials setOauthToken(String oauthToken)
public ChatCredentials setOauthToken(String oauthToken)
{
{
this.oauthToken = oauthToken;
this.oauthToken = oauthToken;
return this;
return this;
}
}
}
}
}
}
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.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;
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(TwitchChatCredentials.HELP_LINK);
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelNameKey, Type.STRING);
Property channel = new Property(channelNameKey, Type.STRING);
channel.setDisplayName("Host Channel");
channel.setDisplayName("Host Channel");
channel.setDefaultValueStr("channel_name");
channel.setDefaultValueStr("channel_name");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
addClientProperties(channel);
addClientProperties(channel);
}
}
@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();
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 MinorException(
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 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 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.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;
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(TwitchChatCredentials.HELP_LINK);
}
}
@Override
@Override
public void initProperties() throws MinorException
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 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();
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 MinorException(
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 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 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.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;
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(TwitchChatCredentials.HELP_LINK);
}
}
@Override
@Override
public void initProperties() throws MinorException
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 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 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 MinorException(
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 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.");
}
}
}
}
}
}
}
}