essential-actions
Clone or download
Modified Files
package setreplaybuffer;
public enum ReplayBufferState
{
START, STOP, SAVE
}
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.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 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()
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 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);
Property usernameColor = new Property(usernameColorKey, Type.STRING);
ListProperty usernameColor = new ListProperty(usernameColorKey);
usernameColor.setDisplayName("Color");
usernameColor.setDisplayName("Color");
usernameColor.setDefaultValueStr("color");
usernameColor.setCanBeBlank(false);
addClientProperties(channelName, usernameColor);
addClientProperties(channelName, usernameColor);
}
}
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
credentials.ensureCredentialsInitialized();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String color = getClientProperties().getSingleProperty(usernameColorKey).getStringValue();
final String color = 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 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.");
}
}
}
}
}
}
}
}