essential-actions

Clone or download

Merge pull request #58 from j4ckofalltrades/issue-57

Followers-only toggle action

Modified Files

M README.md
+3 −1
--- 'a/README.md'
+++ b/README.md
@@ -10,6 +10,8 @@ Set of trusted, essential actions and in
## Actions Help Guide
- [Hotkey](hotkeyaction/README.md)
+- [Media Keys](mediakeyaction/README.md)
+- [OBS](obssuite/README.md)
- [Run Command](runcommandaction/README.md)
- [Twitch Chat](twitch/README.md)
@@ -20,7 +22,7 @@ Plugins directory (`$HOME/Stream-Pi/Serv
### Linux/Mac
-Build all actions by executing `make build-all` from the command line or specific actions i.e. `make twitch`.
+Build all actions by executing `make build-all` from the command line or specific actions i.e. `make twitch-talk`.
### Windows
M build.sh
+3 −0
--- 'a/build.sh'
+++ b/build.sh
@@ -129,6 +129,9 @@ twitch() {
cd ../emote-only && mvn clean -Dmaven.test.skip package
mv target/twitch-emote-only-*.jar ../../$FOLD/twitch-emote-only.jar
+ cd ../followers-only && mvn clean -Dmaven.test.skip package
+ mv target/twitch-followers-only-*.jar ../../$FOLD/twitch-followers-only.jar
+
popd || exit
}
M twitch/README.md
+1 −4
--- 'a/twitch/README.md'
+++ b/twitch/README.md
@@ -28,11 +28,8 @@ You should then be able to use the pre-b
- Add stream marker
- Toggle slow mode
- Toggle subs-only mode
-
-### TODO
-
- Toggle followers-only mode
## Running locally
-Copy the `Java-Twirk` from the `Dependencies` directory and the `twitch-xxx-action` jar files from the `PreBuiltPlugins` directory to your Stream-Pi server plugins' directory.
\ No newline at end of file
+Copy the `twitch-api-java` from the `Dependencies` directory and the `twitch-xxx-action` jar files from the `PreBuiltPlugins` directory to your Stream-Pi server plugins' directory.
\ No newline at end of file
--- /dev/null
+++ b/twitch/followers-only/pom.xml
@@ -0,0 +1,85 @@
+<?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-followers-only</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>
+ <streamPiTwitchChatConnectVersion>1.0.0</streamPiTwitchChatConnectVersion>
+ <twitchApiVersion>0.7.1</twitchApiVersion>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ <repository>
+ <id>sonatype-snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</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>action-api</artifactId>
+ <version>${streamPiActionApiVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.github.j4ckofalltrades</groupId>
+ <artifactId>twitch-api-java</artifactId>
+ <version>${twitchApiVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.stream-pi</groupId>
+ <artifactId>twitch-chat-connect</artifactId>
+ <version>${streamPiTwitchChatConnectVersion}</version>
+ </dependency>
+ </dependencies>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>sonatype-snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
--- /dev/null
+++ b/twitch/followers-only/src/main/java/followers_only/FollowersOnlyAction.java
@@ -0,0 +1,154 @@
+package followers_only;
+
+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.ListValue;
+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.version.Version;
+import connect.chat.TwitchChatCredentials;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class FollowersOnlyAction extends ToggleAction
+{
+
+ private final String channelNameKey = "channel_name_fo";
+ private final String durationKey = "duration_fo";
+ private final ArrayList<ListValue> durations;
+
+ private Twirk twirk;
+
+ public FollowersOnlyAction()
+ {
+ setName("Toggle Followers-Only Chat");
+ setCategory("Twitch Chat");
+ setVisibilityInServerSettingsPane(false);
+ setAuthor("j4ckofalltrades");
+ setVersion(new Version(1, 0, 0));
+ setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
+
+ durations = new ArrayList<>();
+ durations.addAll(Arrays.asList(
+ new ListValue("all"),
+ new ListValue("30m"),
+ new ListValue("2h"),
+ new ListValue("2d"),
+ new ListValue("1w"),
+ new ListValue("3mo")
+ ));
+ }
+
+
+ @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 duration = new Property(durationKey, Type.LIST);
+ duration.setDisplayName("Follow Duration");
+ duration.setListValue(durations);
+
+ addClientProperties(channelName, duration);
+ }
+
+ @Override
+ public void onToggleOn() throws MinorException
+ {
+ try
+ {
+ connectToChannel();
+ final String followerDuration = durations.get(getClientProperties().getSingleProperty(durationKey)
+ .getSelectedIndex()).getName().toString();
+
+ if (followerDuration.equals("all"))
+ {
+ twirk.channelMessage("/followers");
+ } else {
+ twirk.channelMessage(String.format("/followers %s", followerDuration));
+ }
+ } catch (Exception ex)
+ {
+ setCurrentStatus(false);
+ throw new MinorException("Failed to enable followers only mode.", "Please try again.");
+ }
+ }
+
+ @Override
+ public void onToggleOff() throws MinorException
+ {
+ try
+ {
+ connectToChannel();
+ twirk.channelMessage("/followersoff");
+ } catch (Exception ex)
+ {
+ setCurrentStatus(true);
+ throw new MinorException("Failed to disable followers only 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.getFollowersMode() == 1);
+ } catch (MinorException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ twirk.connect();
+ } catch (Exception ex)
+ {
+ throw new MinorException("Failed to connect to Twitch",
+ String.format("Could not connect to '%s' channel.", channel));
+ }
+ }
+
+ @Override
+ public void onShutDown() throws MinorException
+ {
+ if (twirk != null)
+ {
+ try
+ {
+ twirk.disconnect();
+ } catch (Exception ex)
+ {
+ throw new MinorException("Twitch connection error", "Please try again.");
+ }
+ }
+ }
+}
--- /dev/null
+++ b/twitch/followers-only/src/main/java/module-info.java
@@ -0,0 +1,9 @@
+module com.stream_pi.twitch.followersonlyaction {
+ requires com.stream_pi.util;
+ requires com.stream_pi.action_api;
+
+ requires com.stream_pi.twitchchatconnectaction;
+ requires twitch.api.java;
+
+ provides com.stream_pi.action_api.externalplugin.ExternalPlugin with followers_only.FollowersOnlyAction;
+}