essential-actions

Clone or download

Implement Twitch host channel action

Modified Files

M build.sh
+3 −0
--- 'a/build.sh'
+++ b/build.sh
@@ -111,6 +111,9 @@ twitchchat() {
cd ../add-stream-marker && mvn clean install package
mv target/twitch-add-stream-marker-1.0.0.jar ../$FOLD/twitch-add-stream-marker.jar
+
+ cd ../host-channel && mvn clean install package
+ mv target/twitch-host-channel-1.0.0.jar ../$FOLD/twitch-host-channel.jar
popd || exit
}
--- /dev/null
+++ b/twitch/host-channel/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-host-channel</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/host-channel/src/main/java/hostchannel/HostChannelAction.java
@@ -0,0 +1,86 @@
+package hostchannel;
+
+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 HostChannelAction extends NormalAction
+{
+
+ private final String channelKey = "channel_hc";
+ private final String channelToHostKey = "channel_to_host_hc";
+
+ private Twirk twirk;
+
+ public HostChannelAction()
+ {
+ setName("Host Channel");
+ 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 Exception
+ {
+ Property channel = new Property(channelKey, Type.STRING);
+ channel.setDisplayName("Channel");
+ channel.setDefaultValueStr("channel");
+ channel.setCanBeBlank(false);
+
+ Property channelToHost = new Property(channelToHostKey, Type.STRING);
+ channelToHost.setDisplayName("Channel to host");
+ channelToHost.setDefaultValueStr("channel_to_host");
+ channelToHost.setCanBeBlank(false);
+
+ addClientProperties(channel, channelToHost);
+ }
+
+ @Override
+ public void initAction() throws Exception
+ {
+
+ }
+
+ @Override
+ public void onActionClicked() throws Exception
+ {
+ final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
+ credentials.ensureCredentialsInitialized();
+
+ final String channel = getClientProperties().getSingleProperty(channelKey).getStringValue();
+ final String channelToHost = getClientProperties().getSingleProperty(channelToHostKey).getStringValue();
+
+ try
+ {
+ twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
+ twirk.connect();
+ twirk.channelMessage(String.format("/host %s", channelToHost));
+ } catch (Exception ex)
+ {
+ throw new StreamPiException(
+ "Failed to host channel",
+ String.format("Could not host channel '%s', please try again.", channelToHost));
+ }
+ }
+
+ @Override
+ public void onShutDown() throws Exception
+ {
+ if (twirk != null) {
+ try
+ {
+ twirk.disconnect();
+ } catch (Exception ex) {
+ throw new StreamPiException("Twitch connection error", "Please try again.");
+ }
+ }
+ }
+}
--- /dev/null
+++ b/twitch/host-channel/src/main/java/module-info.java
@@ -0,0 +1,9 @@
+module com.stream_pi.twitch.hostchannelaction {
+ 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 hostchannel.HostChannelAction;
+}