essential-actions

Clone or download

Move config initialization check to central location

Modified Files

Binary files /dev/null and b/PreBuiltPlugins/twitch-chat-connect.jar differ
Binary files 'a/PreBuiltPlugins/twitch-send-channel-msg.jar' and b/PreBuiltPlugins/twitch-send-channel-msg.jar differ
--- 'a/twitch/send-channel-msg/pom.xml'
+++ b/twitch/send-channel-msg/pom.xml
@@ -11,8 +11,8 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
- <streamPiActionApiVersion>1.0.0-SNAPSHOT</streamPiActionApiVersion>
- <streamPiUtilVersion>1.0.0-SNAPSHOT</streamPiUtilVersion>
+ <streamPiActionApiVersion>1.0.0</streamPiActionApiVersion>
+ <streamPiUtilVersion>1.0.0</streamPiUtilVersion>
<streamPiTwitchChatConnectVersion>1.0.0</streamPiTwitchChatConnectVersion>
<javaTwirkVersion>0.6.3</javaTwirkVersion>
</properties>
--- 'a/twitch/send-channel-msg/src/main/java/module-info.java'
+++ b/twitch/send-channel-msg/src/main/java/module-info.java
@@ -6,4 +6,4 @@ module com.stream_pi.twitch.sendchannelm
requires Java.Twirk;
provides com.stream_pi.action_api.normalaction.NormalAction with sendchannelmsg.SendChannelMessageAction;
-}
\ No newline at end of file
+}
--- 'a/twitch/send-channel-msg/src/main/java/sendchannelmsg/SendChannelMessageAction.java'
+++ b/twitch/send-channel-msg/src/main/java/sendchannelmsg/SendChannelMessageAction.java
@@ -9,14 +9,13 @@ import com.stream_pi.util.exception.Stre
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
-import static connect.chat.TwitchChatCredentials.DEFAULT_TWITCH_NICKNAME;
-import static connect.chat.TwitchChatCredentials.DEFAULT_TWITCH_TOKEN;
+import java.util.UUID;
public class SendChannelMessageAction extends NormalAction
{
- 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 CHANNEL_NAME_KEY = UUID.randomUUID().toString();
+ private static final String CHANNEL_MSG_KEY = UUID.randomUUID().toString();
private Twirk twirk;
@@ -27,18 +26,18 @@ public class SendChannelMessageAction ex
setVisibilityInServerSettingsPane(false);
setAuthor("j4ckofalltrades");
setVersion(new Version(1, 0, 0));
- setHelpLink("https://github.com/stream-pi/essentialactions");
+ setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
}
@Override
public void initProperties() throws Exception
{
- Property channelName = new Property(TWITCH_CHANNEL_NAME_KEY, Type.STRING);
+ Property channelName = new Property(CHANNEL_NAME_KEY, Type.STRING);
channelName.setDisplayName("Channel Name");
channelName.setDefaultValueStr("channel_name");
channelName.setCanBeBlank(false);
- Property channelMessage = new Property(TWITCH_CHANNEL_MSG_KEY, Type.STRING);
+ Property channelMessage = new Property(CHANNEL_MSG_KEY, Type.STRING);
channelMessage.setDisplayName("Message");
channelMessage.setDefaultValueStr("channel_msg");
channelMessage.setCanBeBlank(false);
@@ -55,22 +54,15 @@ public class SendChannelMessageAction ex
@Override
public void onActionClicked() throws Exception
{
- TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
- if (!isChatCredentialsInitialized(credentials))
- {
- throw new StreamPiException("Twitch Chat uninitialized.","Please check that the Twitch Chat plugin configuration is correct.");
- }
+ final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
+ credentials.ensureCredentialsInitialized();
- final String channel = getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue();
- final String message = getClientProperties().getSingleProperty(TWITCH_CHANNEL_MSG_KEY).getStringValue();
+ final String channel = getClientProperties().getSingleProperty(CHANNEL_NAME_KEY).getStringValue();
+ final String message = getClientProperties().getSingleProperty(CHANNEL_MSG_KEY).getStringValue();
try
{
- twirk = new TwirkBuilder(
- getClientProperties().getSingleProperty(TWITCH_CHANNEL_NAME_KEY).getStringValue(),
- credentials.getNickname(),
- credentials.getOauthToken())
- .build();
+ twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.channelMessage(message);
} catch (Exception ex)
@@ -83,31 +75,9 @@ public class SendChannelMessageAction ex
}
}
- private boolean isChatCredentialsInitialized(TwitchChatCredentials.ChatCredentials credentials)
- {
- if (credentials == null)
- {
- return false;
- }
-
- final String twitchNickname = credentials.getNickname();
- boolean isNicknameInitialized = twitchNickname != null &&
- !twitchNickname.isEmpty() &&
- !twitchNickname.equalsIgnoreCase(DEFAULT_TWITCH_NICKNAME);
-
- final String twitchChatOauthToken = credentials.getOauthToken();
- boolean isTokenInitialized = twitchChatOauthToken != null &&
- !twitchChatOauthToken.isEmpty() &&
- !twitchChatOauthToken.equalsIgnoreCase(DEFAULT_TWITCH_TOKEN);
-
- return isNicknameInitialized && isTokenInitialized;
- }
-
@Override
public void onShutDown() throws Exception
{
twirk.close();
}
}
-
-
--- 'a/twitch/twitch-chat-connect/src/main/java/connect/TwitchChatConnectAction.java'
+++ b/twitch/twitch-chat-connect/src/main/java/connect/TwitchChatConnectAction.java
@@ -13,8 +13,8 @@ import javafx.scene.control.Button;
public class TwitchChatConnectAction extends NormalAction
{
- private static final String TWITCH_ACCESS_TOKEN_KEY = "twitch_access_token";
- private static final String TWITCH_NICKNAME_KEY = "twitch_nickname";
+ private static final String ACCESS_TOKEN_KEY = "twitch_chat_access_token";
+ private static final String NICKNAME_KEY = "twitch_chat_nickname";
private final Button clearCredentialsBtn;
@@ -25,7 +25,7 @@ public class TwitchChatConnectAction ext
setVisibilityInPluginsPane(false);
setAuthor("j4ckofalltrades");
setVersion(new Version(1, 0, 0));
- setHelpLink("https://github.com/Stream-Pi/essentialactions");
+ setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
clearCredentialsBtn = new Button("Clear Twitch chat credentials");
onClearCredentials();
@@ -35,10 +35,10 @@ public class TwitchChatConnectAction ext
@Override
public void initProperties()
{
- Property twitchNicknameProp = new Property(TWITCH_NICKNAME_KEY, Type.STRING);
+ Property twitchNicknameProp = new Property(NICKNAME_KEY, Type.STRING);
twitchNicknameProp.setDisplayName("Twitch Username");
- Property twitchAccessTokenProp = new Property(TWITCH_ACCESS_TOKEN_KEY, Type.STRING);
+ Property twitchAccessTokenProp = new Property(ACCESS_TOKEN_KEY, Type.STRING);
twitchAccessTokenProp.setDisplayName("Access Token");
addServerProperties(twitchNicknameProp, twitchAccessTokenProp);
@@ -51,13 +51,13 @@ public class TwitchChatConnectAction ext
TwitchChatCredentials.setCredentials(
new TwitchChatCredentials.ChatCredentials()
- .setOauthToken(getServerProperties().getSingleProperty(TWITCH_ACCESS_TOKEN_KEY).getStringValue())
- .setNickname(getServerProperties().getSingleProperty(TWITCH_NICKNAME_KEY).getStringValue()));
+ .setOauthToken(getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue())
+ .setNickname(getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue()));
}
private boolean isEmptyCredentials() throws MinorException {
- final String twitchNickname = getServerProperties().getSingleProperty(TWITCH_NICKNAME_KEY).getStringValue();
- final String twitchChatOauthToken = getServerProperties().getSingleProperty(TWITCH_ACCESS_TOKEN_KEY).getStringValue();
+ final String twitchNickname = getServerProperties().getSingleProperty(NICKNAME_KEY).getStringValue();
+ final String twitchChatOauthToken = getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).getStringValue();
return (twitchNickname == null || twitchNickname.isEmpty()) &&
(twitchChatOauthToken == null || twitchChatOauthToken.isEmpty());
}
@@ -68,8 +68,8 @@ public class TwitchChatConnectAction ext
{
try
{
- getServerProperties().getSingleProperty(TWITCH_ACCESS_TOKEN_KEY).setStringValue("");
- getServerProperties().getSingleProperty(TWITCH_NICKNAME_KEY).setStringValue("");
+ getServerProperties().getSingleProperty(ACCESS_TOKEN_KEY).setStringValue("");
+ getServerProperties().getSingleProperty(NICKNAME_KEY).setStringValue("");
saveServerProperties();
new StreamPiAlert(
"Twitch chat credentials cleared",
--- 'a/twitch/twitch-chat-connect/src/main/java/connect/chat/TwitchChatCredentials.java'
+++ b/twitch/twitch-chat-connect/src/main/java/connect/chat/TwitchChatCredentials.java
@@ -1,9 +1,9 @@
package connect.chat;
+import com.stream_pi.util.exception.StreamPiException;
+
public final class TwitchChatCredentials
{
- public static final String DEFAULT_TWITCH_NICKNAME = "twitch_username";
- public static final String DEFAULT_TWITCH_TOKEN = "twitch_token";
private static ChatCredentials credentials;
@@ -22,6 +22,20 @@ public final class TwitchChatCredentials
String nickname;
String oauthToken;
+ public void ensureCredentialsInitialized() throws Exception {
+ final String twitchNickname = nickname;
+ boolean isNicknameInitialized = twitchNickname != null && !twitchNickname.isEmpty();
+
+ final String twitchChatOauthToken = oauthToken;
+ boolean isTokenInitialized = twitchChatOauthToken != null && !twitchChatOauthToken.isEmpty();
+
+ if (!isNicknameInitialized && !isTokenInitialized) {
+ throw new StreamPiException(
+ "Twitch Chat config uninitialized.",
+ "Please check that the Twitch Chat plugin configuration is correct.");
+ }
+ }
+
public String getNickname()
{
return nickname;
--- 'a/twitch/twitch-chat-connect/src/main/java/module-info.java'
+++ b/twitch/twitch-chat-connect/src/main/java/module-info.java
@@ -8,4 +8,4 @@ module com.stream_pi.twitchchatconnectac
exports connect.chat;
provides com.stream_pi.action_api.normalaction.NormalAction with connect.TwitchChatConnectAction;
-}
\ No newline at end of file
+}