Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make commandPrefixes non-final in builders #523

Merged
merged 1 commit into from Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions chat/src/main/java/com/github/twitch4j/chat/TwitchChat.java
Expand Up @@ -279,13 +279,13 @@ public class TwitchChat implements ITwitchChat {
* @param maxJoinRetries Maximum join retries per channel
* @param chatJoinTimeout Minimum milliseconds to wait after a join attempt
*/
public TwitchChat(EventManager eventManager, CredentialManager credentialManager, OAuth2Credential chatCredential, String baseUrl, boolean sendCredentialToThirdPartyHost, List<String> commandPrefixes, Integer chatQueueSize, Bucket ircMessageBucket, Bucket ircWhisperBucket, Bucket ircJoinBucket, Bucket ircAuthBucket, ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, Collection<String> botOwnerIds, boolean removeChannelOnJoinFailure, int maxJoinRetries, long chatJoinTimeout) {
public TwitchChat(EventManager eventManager, CredentialManager credentialManager, OAuth2Credential chatCredential, String baseUrl, boolean sendCredentialToThirdPartyHost, Collection<String> commandPrefixes, Integer chatQueueSize, Bucket ircMessageBucket, Bucket ircWhisperBucket, Bucket ircJoinBucket, Bucket ircAuthBucket, ScheduledThreadPoolExecutor taskExecutor, long chatQueueTimeout, ProxyConfig proxyConfig, boolean autoJoinOwnChannel, boolean enableMembershipEvents, Collection<String> botOwnerIds, boolean removeChannelOnJoinFailure, int maxJoinRetries, long chatJoinTimeout) {
this.eventManager = eventManager;
this.credentialManager = credentialManager;
this.chatCredential = chatCredential;
this.baseUrl = baseUrl;
this.sendCredentialToThirdPartyHost = sendCredentialToThirdPartyHost;
this.commandPrefixes = commandPrefixes;
this.commandPrefixes = new ArrayList<>(commandPrefixes);
this.botOwnerIds = botOwnerIds;
this.ircCommandQueue = new ArrayBlockingQueue<>(chatQueueSize, true);
this.ircMessageBucket = ircMessageBucket;
Expand Down
Expand Up @@ -23,12 +23,11 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
Expand Down Expand Up @@ -110,7 +109,9 @@ public class TwitchChatBuilder {
/**
* IRC Command Handlers
*/
protected final List<String> commandPrefixes = new ArrayList<>();
@Setter
@Accessors(chain = true)
protected Set<String> commandPrefixes = new HashSet<>();

/**
* Size of the ChatQueue
Expand Down
Expand Up @@ -124,7 +124,7 @@ public class TwitchClientBuilder {
/**
* IRC Command Handlers
*/
protected final Set<String> commandPrefixes = new HashSet<>();
protected Set<String> commandPrefixes = new HashSet<>();

/**
* Enabled: PubSub
Expand Down Expand Up @@ -412,10 +412,10 @@ public TwitchClient build() {
.withScheduledThreadPoolExecutor(scheduledThreadPoolExecutor)
.withBaseUrl(chatServer)
.withChatQueueTimeout(chatQueueTimeout)
.withCommandTriggers(commandPrefixes)
.withProxyConfig(proxyConfig)
.setBotOwnerIds(botOwnerIds)
.withMaxJoinRetries(chatMaxJoinRetries)
.setBotOwnerIds(botOwnerIds)
.setCommandPrefixes(commandPrefixes)
.build();
}

Expand Down
Expand Up @@ -139,7 +139,7 @@ public class TwitchClientPoolBuilder {
/**
* IRC Command Handlers
*/
protected final Set<String> commandPrefixes = new HashSet<>();
protected Set<String> commandPrefixes = new HashSet<>();

/**
* Enabled: PubSub
Expand Down Expand Up @@ -438,7 +438,7 @@ public TwitchClientPool build() {
.withBaseUrl(chatServer)
.withChatQueueTimeout(chatQueueTimeout)
.withMaxJoinRetries(chatMaxJoinRetries)
.withCommandTriggers(commandPrefixes)
.setCommandPrefixes(commandPrefixes)
.setBotOwnerIds(botOwnerIds)
)
.build();
Expand All @@ -455,10 +455,10 @@ public TwitchClientPool build() {
.withScheduledThreadPoolExecutor(scheduledThreadPoolExecutor)
.withBaseUrl(chatServer)
.withChatQueueTimeout(chatQueueTimeout)
.withCommandTriggers(commandPrefixes)
.withProxyConfig(proxyConfig)
.withMaxJoinRetries(chatMaxJoinRetries)
.setBotOwnerIds(botOwnerIds)
.setCommandPrefixes(commandPrefixes)
.build();
}

Expand Down
15 changes: 15 additions & 0 deletions twitch4j/src/test/java/com/github/twitch4j/TwitchClientTest.java
Expand Up @@ -9,8 +9,10 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ScheduledThreadPoolExecutor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Slf4j
Expand All @@ -34,6 +36,19 @@ public void buildTwitch4J() {
.build();
}

@Test
@DisplayName("Ensure builder calls don't reset command triggers")
public void buildCommandPrefix() {
TwitchClientBuilder b1 = TwitchClientBuilder.builder().withEnableChat(true);
assertTrue(b1.getCommandPrefixes().isEmpty());

TwitchClientBuilder b2 = b1.withCommandTrigger("!");
assertEquals(1, b2.getCommandPrefixes().size());

TwitchClientBuilder b3 = b2.withEnablePubSub(true);
assertEquals(1, b3.getCommandPrefixes().size());
}

@Test
@DisplayName("Test if the Twitch4J ThreadPool is closed on shutdown")
public void testScheduledThreadPoolExecutorShutdown() {
Expand Down