From: Jordan Duabe <1442368+j4ckofalltrades@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:20:01 +0530 Subject: Implement Twitch chat unhost action --- Implement Twitch chat unhost action --- --- 'a/README.md' +++ b/README.md @@ -25,7 +25,7 @@ Set of trusted, pre-bundled actions and The first step is to acquire an OAuth token from https://twitchapps.com/tmi/, the generated OAuth token should look something like `oauth:xxxxx`. -In the Stream-Pi Server's Plugin page enter your Twitch username, and the generated token then click on `Save Twitch chat credentials` button. You should then be able to use the pre-bundled Twitch chat actions. +In the Stream-Pi Server's Plugin page enter your Twitch username, and the generated token then click on `Save Twitch Chat credentials` button. You should then be able to use the pre-bundled Twitch chat actions. ### Supported actions (see [Chat Commands](https://help.twitch.tv/s/article/chat-commands?language=en_US) for full documentation) @@ -48,9 +48,9 @@ In the Stream-Pi Server's Plugin page en - Run commercial (TBA) - Host (TBA) -- Unhost (TBA) +- Unhost - Raid (TBA) -- Unraid (TBA) +- Unraid - Add stream marker (TBA) ### Running locally --- 'a/build.sh' +++ b/build.sh @@ -105,6 +105,9 @@ twitchchat() { cd ../unraid && mvn clean install package mv target/twitch-unraid-1.0.0.jar ../$FOLD/twitch-unraid.jar + + cd ../unhost && mvn clean install package + mv target/twitch-unhost-1.0.0.jar ../$FOLD/twitch-unhost.jar popd || exit } --- /dev/null +++ b/twitch/unhost/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + com.stream-pi + twitch-unhost + 1.0.0 + + + 11 + 11 + 1.0.0 + 1.0.0 + 1.0.0 + 0.6.3 + + + + + jitpack.io + https://jitpack.io + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + test-jar + package + + test-jar + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + + + + + + + + com.stream-pi + util + ${streamPiUtilVersion} + + + + com.stream-pi + action-api + ${streamPiActionApiVersion} + + + + com.github.gikkman + Java-Twirk + ${javaTwirkVersion} + + + + com.stream-pi + twitch-chat-connect + ${streamPiTwitchChatConnectVersion} + + + + --- /dev/null +++ b/twitch/unhost/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module com.stream_pi.twitch.unhostaction { + 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 unhost.UnhostAction; +} --- /dev/null +++ b/twitch/unhost/src/main/java/unhost/UnhostAction.java @@ -0,0 +1,79 @@ +package unhost; + +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 UnhostAction extends NormalAction +{ + + private final String channelNameKey = "channel_name_ua"; + + private Twirk twirk; + + public UnhostAction() + { + setName("Unhost"); + 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(channelNameKey, Type.STRING); + channel.setDisplayName("Channel"); + channel.setDefaultValueStr("channel_name"); + channel.setCanBeBlank(false); + + addClientProperties(channel); + } + + @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(channelNameKey).getStringValue(); + + try + { + twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build(); + twirk.connect(); + twirk.channelMessage("/unhost"); + } catch (Exception ex) + { + throw new StreamPiException( + "Failed to cancel channel raid", + "Could not send cancel channel raid, please try again."); + } + } + + @Override + public void onShutDown() throws Exception + { + if (twirk != null) { + try + { + twirk.disconnect(); + } catch (Exception ex) { + throw new StreamPiException("Twitch connection error", "Please try again."); + } + } + } +}