essential-actions
Clone or download
Modified Files
--- 'a/build.sh'
+++ b/build.sh
@@ -122,6 +122,10 @@ twitchchat() {
cd ../subs-only && mvn clean -Dmaven.test.skip package
mv target/twitch-subs-only-*.jar ../../$FOLD/twitch-subs-only.jar
+
+ cd ../slow-mode && mvn clean -Dmaven.test.skip package
+ mv target/twitch-slow-mode-*.jar ../../$FOLD/twitch-slow-mode.jar
+
popd || exit
}
--- /dev/null
+++ b/twitch/slow-mode/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-slow-mode</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-SNAPSHOT</streamPiActionApiVersion>
+ <streamPiUtilVersion>1.0.0-SNAPSHOT</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/slow-mode/src/main/java/module-info.java
@@ -0,0 +1,9 @@
+module com.stream_pi.twitch.slowmodeaction {
+ 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.externalplugin.ExternalPlugin with slow_mode.SlowModeAction;
+}
--- /dev/null
+++ b/twitch/slow-mode/src/main/java/slow_mode/SlowModeAction.java
@@ -0,0 +1,130 @@
+package slow_mode;
+
+import com.gikk.twirk.Twirk;
+import com.gikk.twirk.TwirkBuilder;
+import com.gikk.twirk.events.TwirkListener;
+import com.gikk.twirk.types.roomstate.Roomstate;
+import com.stream_pi.action_api.actionproperty.property.Property;
+import com.stream_pi.action_api.actionproperty.property.Type;
+import com.stream_pi.action_api.externalplugin.ToggleAction;
+import com.stream_pi.util.exception.MinorException;
+import com.stream_pi.util.exception.StreamPiException;
+import com.stream_pi.util.version.Version;
+import connect.chat.TwitchChatCredentials;
+
+public class SlowModeAction extends ToggleAction
+{
+
+ private final String channelNameKey = "channel_name_sm";
+ private final String slowModeDurationKey = "slow_mode_duration";
+
+ private Twirk twirk;
+
+ public SlowModeAction()
+ {
+ setName("Toggle Slow Mode");
+ 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 initProperties() throws MinorException
+ {
+ Property channelName = new Property(channelNameKey, Type.STRING);
+ channelName.setDisplayName("Channel Name");
+ channelName.setDefaultValueStr("channel_name");
+ channelName.setCanBeBlank(false);
+
+ Property durationInSecs = new Property(slowModeDurationKey, Type.INTEGER);
+ durationInSecs.setDefaultValueInt(600);
+ durationInSecs.setDisplayName("Duration (in seconds)");
+
+ addClientProperties(channelName, durationInSecs);
+ }
+
+ @Override
+ public void onToggleOn() throws Exception
+ {
+ try
+ {
+ connectToChannel();
+ final int duration = getClientProperties().getSingleProperty(slowModeDurationKey).getIntValue();
+ twirk.channelMessage(String.format("/slow %d", duration));
+ } catch (Exception ex)
+ {
+ setCurrentStatus(false);
+ throw new StreamPiException("Failed to enable slow mode.", "Please try again.");
+ }
+ }
+
+ @Override
+ public void onToggleOff() throws Exception
+ {
+ try
+ {
+ connectToChannel();
+ twirk.channelMessage("/slowoff");
+ } catch (Exception ex)
+ {
+ setCurrentStatus(true);
+ throw new StreamPiException("Failed to disable slow mode.", "Please try again.");
+ }
+ }
+
+ private void connectToChannel() throws Exception
+ {
+ if (twirk != null) {
+ if (!twirk.isConnected()) {
+ twirk.connect();
+ }
+
+ return;
+ }
+
+ final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
+ credentials.ensureCredentialsInitialized();
+ final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
+
+ try
+ {
+ twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
+ twirk.addIrcListener(new TwirkListener()
+ {
+ @Override
+ public void onRoomstate(Roomstate roomstate)
+ {
+ try
+ {
+ setCurrentStatus(roomstate.getSlowModeTimer() > 0);
+ } catch (MinorException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ twirk.connect();
+ } catch (Exception ex)
+ {
+ throw new StreamPiException("Failed to connect to Twitch",
+ String.format("Could not connect to '%s' channel.", 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.");
+ }
+ }
+ }
+}