From: Jordan Duabe <1442368+j4ckofalltrades@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:54:16 +0530 Subject: Implement Twitch raid channel action --- Implement Twitch raid channel action --- --- 'a/build.sh' +++ b/build.sh @@ -114,6 +114,9 @@ twitchchat() { cd ../host-channel && mvn clean install package mv target/twitch-host-channel-1.0.0.jar ../$FOLD/twitch-host-channel.jar + + cd ../raid-channel && mvn clean install package + mv target/twitch-raid-channel-1.0.0.jar ../$FOLD/twitch-raid-channel.jar popd || exit } --- /dev/null +++ b/twitch/raid-channel/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + com.stream-pi + twitch-raid-channel + 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/raid-channel/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module com.stream_pi.twitch.raidchannelaction { + 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 raidchannel.RaidChannelAction; +} --- /dev/null +++ b/twitch/raid-channel/src/main/java/raidchannel/RaidChannelAction.java @@ -0,0 +1,86 @@ +package raidchannel; + +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 RaidChannelAction extends NormalAction +{ + + private final String channelKey = "channel_rc"; + private final String channelToRaidKey = "channel_to_raid_rc"; + + private Twirk twirk; + + public RaidChannelAction() + { + setName("Raid 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 channelToRaid = new Property(channelToRaidKey, Type.STRING); + channelToRaid.setDisplayName("Channel to raid"); + channelToRaid.setDefaultValueStr("channel_to_raid"); + channelToRaid.setCanBeBlank(false); + + addClientProperties(channel, channelToRaid); + } + + @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 channelToRaid = getClientProperties().getSingleProperty(channelToRaidKey).getStringValue(); + + try + { + twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build(); + twirk.connect(); + twirk.channelMessage(String.format("/raid %s", channelToRaid)); + } catch (Exception ex) + { + throw new StreamPiException( + "Failed to raid channel", + String.format("Could not raid channel '%s', please try again.", channelToRaid)); + } + } + + @Override + public void onShutDown() throws Exception + { + if (twirk != null) { + try + { + twirk.disconnect(); + } catch (Exception ex) { + throw new StreamPiException("Twitch connection error", "Please try again."); + } + } + } +}