essential-actions

Clone or download

Implement set username color action

Modified Files

Binary files 'a/PreBuiltPlugins/twitch-chat-connect.jar' and b/PreBuiltPlugins/twitch-chat-connect.jar differ
Binary files 'a/PreBuiltPlugins/twitch-clear-chat.jar' and b/PreBuiltPlugins/twitch-clear-chat.jar differ
Binary files 'a/PreBuiltPlugins/twitch-send-channel-msg.jar' and b/PreBuiltPlugins/twitch-send-channel-msg.jar differ
Binary files /dev/null and b/PreBuiltPlugins/twitch-set-color.jar differ
M build.sh
+3 −0
--- 'a/build.sh'
+++ b/build.sh
@@ -96,6 +96,9 @@ twitchchat() {
cd ../clear-chat && mvn clean install package
mv target/twitch-clear-chat-1.0.0.jar ../$FOLD/twitch-clear-chat.jar
+
+ cd ../set-color && mvn clean install package
+ mv target/twitch-set-color-1.0.0.jar ../$FOLD/twitch-set-color.jar
popd || exit
}
--- 'a/twitch/clear-chat/src/main/java/clearchat/ClearChatAction.java'
+++ b/twitch/clear-chat/src/main/java/clearchat/ClearChatAction.java
@@ -9,12 +9,10 @@ import com.stream_pi.util.exception.Stre
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
-import java.util.UUID;
-
public class ClearChatAction extends NormalAction
{
- private static final String CHANNEL_NAME_KEY = UUID.randomUUID().toString();
+ private final String channelNameKey = "channel_name_cc";
private Twirk twirk;
@@ -32,7 +30,7 @@ public class ClearChatAction extends Nor
@Override
public void initAction() throws Exception
{
- Property channelName = new Property(CHANNEL_NAME_KEY, Type.STRING);
+ Property channelName = new Property(channelNameKey, Type.STRING);
channelName.setDisplayName("Channel Name");
channelName.setDefaultValueStr("channel_name");
channelName.setCanBeBlank(false);
@@ -46,7 +44,7 @@ public class ClearChatAction extends Nor
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
- final String channel = getClientProperties().getSingleProperty(CHANNEL_NAME_KEY).getStringValue();
+ final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
try
{
@@ -65,6 +63,13 @@ public class ClearChatAction extends Nor
@Override
public void onShutDown() throws Exception
{
- twirk.close();
+ if (twirk != null) {
+ try
+ {
+ twirk.disconnect();
+ } catch (Exception ex) {
+ throw new StreamPiException("Twitch Connection error", "Please try again.");
+ }
+ }
}
}
--- 'a/twitch/send-channel-msg/src/main/java/sendchannelmsg/SendChannelMessageAction.java'
+++ b/twitch/send-channel-msg/src/main/java/sendchannelmsg/SendChannelMessageAction.java
@@ -9,13 +9,11 @@ import com.stream_pi.util.exception.Stre
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
-import java.util.UUID;
-
public class SendChannelMessageAction extends NormalAction
{
- private static final String CHANNEL_NAME_KEY = UUID.randomUUID().toString();
- private static final String CHANNEL_MSG_KEY = UUID.randomUUID().toString();
+ private final String channelNameKey = "channel_name_scm";
+ private final String channelMsgKey = "channel_msg_scm";
private Twirk twirk;
@@ -32,12 +30,12 @@ public class SendChannelMessageAction ex
@Override
public void initProperties() throws Exception
{
- Property channelName = new Property(CHANNEL_NAME_KEY, Type.STRING);
+ Property channelName = new Property(channelNameKey, Type.STRING);
channelName.setDisplayName("Channel Name");
channelName.setDefaultValueStr("channel_name");
channelName.setCanBeBlank(false);
- Property channelMessage = new Property(CHANNEL_MSG_KEY, Type.STRING);
+ Property channelMessage = new Property(channelMsgKey, Type.STRING);
channelMessage.setDisplayName("Message");
channelMessage.setDefaultValueStr("channel_msg");
channelMessage.setCanBeBlank(false);
@@ -57,8 +55,8 @@ public class SendChannelMessageAction ex
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
- final String channel = getClientProperties().getSingleProperty(CHANNEL_NAME_KEY).getStringValue();
- final String message = getClientProperties().getSingleProperty(CHANNEL_MSG_KEY).getStringValue();
+ final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
+ final String message = getClientProperties().getSingleProperty(channelMsgKey).getStringValue();
try
{
@@ -78,6 +76,13 @@ public class SendChannelMessageAction ex
@Override
public void onShutDown() throws Exception
{
- twirk.close();
+ if (twirk != null) {
+ try
+ {
+ twirk.disconnect();
+ } catch (Exception ex) {
+ throw new StreamPiException("Twitch connection error", "Please try again.");
+ }
+ }
}
}
--- /dev/null
+++ b/twitch/set-color/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.stream-pi</groupId>
+ <artifactId>twitch-set-color</artifactId>
+ <version>1.0.0</version>
+
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <streamPiActionApiVersion>1.0.0</streamPiActionApiVersion>
+ <streamPiUtilVersion>1.0.0</streamPiUtilVersion>
+ <streamPiTwitchChatConnectVersion>1.0.0</streamPiTwitchChatConnectVersion>
+ <javaTwirkVersion>0.6.3</javaTwirkVersion>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.1.0</version>
+ <executions>
+ <execution>
+ <id>test-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <release>11</release>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.stream-pi</groupId>
+ <artifactId>util</artifactId>
+ <version>${streamPiUtilVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.stream-pi</groupId>
+ <artifactId>action-api</artifactId>
+ <version>${streamPiActionApiVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.github.gikkman</groupId>
+ <artifactId>Java-Twirk</artifactId>
+ <version>${javaTwirkVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.stream-pi</groupId>
+ <artifactId>twitch-chat-connect</artifactId>
+ <version>${streamPiTwitchChatConnectVersion}</version>
+ </dependency>
+ </dependencies>
+
+</project>
--- /dev/null
+++ b/twitch/set-color/src/main/java/module-info.java
@@ -0,0 +1,9 @@
+module com.stream_pi.twitch.setcoloraction {
+ requires com.stream_pi.util;
+ requires com.stream_pi.action_api;
+
+ requires com.stream_pi.twitchchatconnectaction;
+ requires Java.Twirk;
+
+ provides com.stream_pi.action_api.normalaction.NormalAction with setcolor.SetColorAction;
+}
--- /dev/null
+++ b/twitch/set-color/src/main/java/setcolor/SetColorAction.java
@@ -0,0 +1,83 @@
+package setcolor;
+
+import com.gikk.twirk.Twirk;
+import com.gikk.twirk.TwirkBuilder;
+import com.stream_pi.action_api.actionproperty.property.Property;
+import com.stream_pi.action_api.actionproperty.property.Type;
+import com.stream_pi.action_api.normalaction.NormalAction;
+import com.stream_pi.util.exception.StreamPiException;
+import com.stream_pi.util.version.Version;
+import connect.chat.TwitchChatCredentials;
+
+public class SetColorAction extends NormalAction
+{
+
+ private final String channelNameKey = "channel_name_sc";
+ private final String usernameColorKey = "username_color_sc";
+
+ private Twirk twirk;
+
+ @Override
+ public void initProperties() throws Exception
+ {
+ setName("Set Color");
+ setCategory("Twitch Chat");
+ setVisibilityInServerSettingsPane(false);
+ setAuthor("j4ckofalltrades");
+ setVersion(new Version(1, 0, 0));
+ setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
+ }
+
+ @Override
+ public void initAction() throws Exception
+ {
+ Property channelName = new Property(channelNameKey, Type.STRING);
+ channelName.setDisplayName("Channel Name");
+ channelName.setDefaultValueStr("channel_name");
+ channelName.setCanBeBlank(false);
+
+ Property usernameColor = new Property(usernameColorKey, Type.STRING);
+ usernameColor.setDisplayName("Color");
+ usernameColor.setDefaultValueStr("color");
+ usernameColor.setCanBeBlank(false);
+
+ addClientProperties(channelName, usernameColor);
+ }
+
+ @Override
+ public void onActionClicked() throws Exception
+ {
+ final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
+ credentials.ensureCredentialsInitialized();
+
+ final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
+ final String color = getClientProperties().getSingleProperty(usernameColorKey).getStringValue();
+
+ try
+ {
+ twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
+ twirk.connect();
+ twirk.channelMessage(String.format("/color %s", color));
+ } catch (Exception ex)
+ {
+ throw new StreamPiException(
+ "Failed to change username color",
+ String.format("Could not change username color to '%s' for '%s' channel, please try again.",
+ color, channel)
+ );
+ }
+ }
+
+ @Override
+ public void onShutDown() throws Exception
+ {
+ if (twirk != null) {
+ try
+ {
+ twirk.disconnect();
+ } catch (Exception ex) {
+ throw new StreamPiException("Twitch connection error", "Please try again.");
+ }
+ }
+ }
+}