essential-actions

Clone or download

Rename channel label to 'Host Channel' for unhost action

Modified Files

package unhost;
package unhost;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.Twirk;
import com.gikk.twirk.TwirkBuilder;
import com.gikk.twirk.TwirkBuilder;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import connect.chat.TwitchChatCredentials;
import connect.chat.TwitchChatCredentials;
public class UnhostAction extends NormalAction
public class UnhostAction extends NormalAction
{
{
private final String channelNameKey = "channel_name_uh";
private final String channelNameKey = "channel_name_uh";
private Twirk twirk;
private Twirk twirk;
public UnhostAction()
public UnhostAction()
{
{
setName("Unhost");
setName("Unhost");
setCategory("Twitch Chat");
setCategory("Twitch Chat");
setVisibilityInServerSettingsPane(false);
setVisibilityInServerSettingsPane(false);
setAuthor("j4ckofalltrades");
setAuthor("j4ckofalltrades");
setVersion(new Version(1, 0, 0));
setVersion(new Version(1, 0, 0));
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
setHelpLink("https://github.com/stream-pi/essentialactions#twitch-chat-integration");
}
}
@Override
@Override
public void initProperties() throws MinorException
public void initProperties() throws MinorException
{
{
Property channel = new Property(channelNameKey, Type.STRING);
Property channel = new Property(channelNameKey, Type.STRING);
channel.setDisplayName("Channel");
channel.setDisplayName("Host Channel");
channel.setDefaultValueStr("channel_name");
channel.setDefaultValueStr("channel_name");
channel.setCanBeBlank(false);
channel.setCanBeBlank(false);
addClientProperties(channel);
addClientProperties(channel);
}
}
@Override
@Override
public void onActionClicked() throws MinorException
public void onActionClicked() throws MinorException
{
{
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
final TwitchChatCredentials.ChatCredentials credentials = TwitchChatCredentials.getCredentials();
credentials.ensureCredentialsInitialized();
credentials.ensureCredentialsInitialized();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
final String channel = getClientProperties().getSingleProperty(channelNameKey).getStringValue();
try
try
{
{
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk = new TwirkBuilder(channel, credentials.getNickname(), credentials.getOauthToken()).build();
twirk.connect();
twirk.connect();
twirk.channelMessage("/unhost");
twirk.channelMessage("/unhost");
} catch (Exception ex)
} catch (Exception ex)
{
{
throw new MinorException(
throw new MinorException(
"Failed to cancel channel hosting",
"Failed to cancel channel hosting",
"Could not cancel channel hosting, please try again.");
"Could not cancel channel hosting, please try again.");
}
}
}
}
@Override
@Override
public void onShutDown() throws MinorException
public void onShutDown() throws MinorException
{
{
if (twirk != null) {
if (twirk != null) {
try
try
{
{
twirk.disconnect();
twirk.disconnect();
} catch (Exception ex) {
} catch (Exception ex) {
throw new MinorException("Twitch connection error", "Please try again.");
throw new MinorException("Twitch connection error", "Please try again.");
}
}
}
}
}
}
}
}