essential-actions

Clone or download

Update twitch-chat-connect action module name

Modified Files

module com.stream_pi.twitch.sendchannelmsgaction {
module com.stream_pi.twitch.sendchannelmsgaction {
requires com.stream_pi.util;
requires com.stream_pi.util;
requires com.stream_pi.action_api;
requires com.stream_pi.action_api;
requires com.stream_pi.twitchconnectaction;
requires com.stream_pi.twitchchatconnectaction;
requires Java.Twirk;
requires Java.Twirk;
provides com.stream_pi.action_api.normalaction.NormalAction with sendchannelmsg.SendChannelMessageAction;
provides com.stream_pi.action_api.normalaction.NormalAction with sendchannelmsg.SendChannelMessageAction;
}
}
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.normalaction.NormalAction;
import com.stream_pi.action_api.normalaction.NormalAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
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 SendChannelMessageAction extends NormalAction
public class SendChannelMessageAction extends NormalAction
{
{
private static final String TWITCH_CHANNEL_NAME_KEY = "twitch_channel_name";
private static final String TWITCH_CHANNEL_NAME_KEY = "twitch_channel_name";
private static final String TWITCH_CHANNEL_MSG_KEY = "twitch_channel_msg";
private static final String TWITCH_CHANNEL_MSG_KEY = "twitch_channel_msg";
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");
setHelpLink("https://github.com/stream-pi/essentialactions");
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws Exception
{
{
Property channelName = new Property(TWITCH_CHANNEL_NAME_KEY, Type.STRING);
Property channelName = new Property(TWITCH_CHANNEL_NAME_KEY, 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(TWITCH_CHANNEL_MSG_KEY, Type.STRING);
Property channelMessage = new Property(TWITCH_CHANNEL_MSG_KEY, 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 initAction() throws Exception
{
{
}
}
@Override
@Override
public void onActionClicked() throws Exception
public void onActionClicked() throws Exception
{
{
TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
if (!isChatCredentialsInitialized(credentials))
if (!isChatCredentialsInitialized(credentials))
{
{
throw new StreamPiException("Twitch Chat uninitialized.","Please check that the Twitch Chat plugin configuration is correct.");
throw new StreamPiException("Twitch Chat uninitialized.","Please check that the Twitch Chat plugin configuration is correct.");
}
}
final String channel = getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue();
final String channel = getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue();
final String message = getClientProperties().getSingleProperty(TWITCH_CHANNEL_MSG_KEY).getStringValue();
final String message = getClientProperties().getSingleProperty(TWITCH_CHANNEL_MSG_KEY).getStringValue();
try
try
{
{
twirk = new TwirkBuilder(
twirk = new TwirkBuilder(
getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue(),
getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue(),
credentials.getNickname(),
credentials.getNickname(),
credentials.getOauthToken())
credentials.getOauthToken())
.build();
.build();
twirk.connect();
twirk.connect();
twirk.channelMessage(message);
twirk.channelMessage(message);
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new StreamPiException(
throw new StreamPiException(
"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)
);
);
}
}
}
}
private boolean isChatCredentialsInitialized(TwitchChatCredentials.ChatCredentials credentials)
private boolean isChatCredentialsInitialized(TwitchChatCredentials.ChatCredentials credentials)
{
{
if (credentials == null)
if (credentials == null)
{
{
return false;
return false;
}
}
final String twitchNickname = credentials.getNickname();
final String twitchNickname = credentials.getNickname();
boolean isNicknameInitialized = twitchNickname != null &&
boolean isNicknameInitialized = twitchNickname != null &&
!twitchNickname.isEmpty() &&
!twitchNickname.isEmpty() &&
!twitchNickname.equalsIgnoreCase("twitch_nickname");
!twitchNickname.equalsIgnoreCase("twitch_nickname");
final String twitchChatOauthToken = credentials.getOauthToken();
final String twitchChatOauthToken = credentials.getOauthToken();
boolean isTokenInitialized = twitchChatOauthToken != null &&
boolean isTokenInitialized = twitchChatOauthToken != null &&
!twitchChatOauthToken.isEmpty() &&
!twitchChatOauthToken.isEmpty() &&
!twitchChatOauthToken.equalsIgnoreCase("twitch_oauth_token");
!twitchChatOauthToken.equalsIgnoreCase("twitch_oauth_token");
return isNicknameInitialized && isTokenInitialized;
return isNicknameInitialized && isTokenInitialized;
}
}
@Override
@Override
public void onShutDown() throws Exception
public void onShutDown() throws Exception
{
{
twirk.close();
twirk.close();
}
}
}
}
import connect.TwitchChatConnectAction;
module com.stream_pi.twitchchatconnectaction {
module com.stream_pi.twitchconnectaction {
requires com.stream_pi.action_api;
requires com.stream_pi.action_api;
requires com.stream_pi.util;
requires com.stream_pi.util;
requires Java.Twirk;
requires Java.Twirk;
exports connect.chat;
exports connect.chat;
provides com.stream_pi.action_api.normalaction.NormalAction with TwitchChatConnectAction;
provides com.stream_pi.action_api.normalaction.NormalAction with connect.TwitchChatConnectAction;
}
}