Skip to content

Commit

Permalink
ShardManager replaced by DefaultShardManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Strafbefehl committed Nov 12, 2023
1 parent 7dc1989 commit 0b3dae6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions src/main/java/rystudio/strafbefehl/vinyl/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.sharding.DefaultShardManager;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
Expand Down Expand Up @@ -44,9 +45,8 @@ public class Core extends ListenerAdapter {

public JDA jda;
private boolean running;
private ShardManager shardManager;

private DefaultShardManagerBuilder builder;
private DefaultShardManager defaultShardManager; // Ändern Sie dies zu DefaultShardManager

private MySQL mySQL;

Expand Down Expand Up @@ -78,7 +78,7 @@ public class Core extends ListenerAdapter {
public Core(DefaultShardManagerBuilder builder) throws IOException {
config = new Config();
this.logger = new Logger(this);
this.builder = builder;
this.builder = builder; // Diese Zeile kann entfernt werden, da builder bereits als Parameter übergeben wird
loadIntents();

this.slashCommands = new SlashCommands(this);
Expand All @@ -88,7 +88,6 @@ public Core(DefaultShardManagerBuilder builder) throws IOException {
getGatewayIntents().add(GatewayIntent.MESSAGE_CONTENT);
}

builder = DefaultShardManagerBuilder.create(this.config.getToken(), gatewayIntents);
builder.addEventListeners(slashCommands);
}

Expand All @@ -110,7 +109,7 @@ public Core(String token, boolean usePrefixCommands, DefaultShardManagerBuilder
}

public List<JDA> buildJDAs(int shardCount) throws InterruptedException {
if (running && shardManager != null) {
if (running && defaultShardManager != null) {
stopBot();
}

Expand All @@ -126,8 +125,8 @@ public List<JDA> buildJDAs(int shardCount) throws InterruptedException {
builder.setShardsTotal(shardCount);
builder.setShards(i, shardCount - 1);

ShardManager shardManager = builder.build(); // Build the ShardManager instance
jdaList.add(shardManager.getShardById(i)); // Add the JDA instance to the list
defaultShardManager = (DefaultShardManager) builder.build(); // Cast zu DefaultShardManager
jdaList.add(defaultShardManager.getShardById(i)); // Add the JDA instance to the list
jdaList.get(i).awaitReady().getPresence().setActivity(Activity.listening("Shard: " + String.valueOf(i)));

jdaList.get(i).addEventListener(this);
Expand Down Expand Up @@ -162,12 +161,12 @@ public List<JDA> buildJDAs(int shardCount) throws InterruptedException {


public void stopBot() {
if (!running || shardManager == null) {
if (!running || defaultShardManager == null) {
return;
}
shardManager.shutdown();
defaultShardManager.shutdown();
running = false;
shardManager = null;
defaultShardManager = null;
}


Expand Down Expand Up @@ -257,8 +256,8 @@ public void onGuildLeave(GuildLeaveEvent event) {
}


public ShardManager getShardManager() {
return shardManager;
public DefaultShardManager getDefaultShardManager() {
return defaultShardManager;
}

private void loadIntents() {
Expand Down Expand Up @@ -431,8 +430,8 @@ public Core registerListeners(ListenerAdapter... listeners) {
if (List.of(listeners).isEmpty()) {
return this;
} else {
if (this.shardManager == null) {
this.shardManager = DefaultShardManagerBuilder.createDefault(this.config.getToken()).build();
if (this.defaultShardManager == null) {
this.defaultShardManager = (DefaultShardManager) DefaultShardManagerBuilder.createDefault(this.config.getToken()).build();
// Configure any other settings for the shardManager if needed
}

Expand All @@ -441,7 +440,7 @@ public Core registerListeners(ListenerAdapter... listeners) {

for (int var4 = 0; var4 < var3; ++var4) {
ListenerAdapter listener = var2[var4];
this.shardManager.addEventListener(listener);
this.defaultShardManager.addEventListener(listener);
Logger.log(LogType.LISTENERS, "Registered listener: " + listener.getClass().getSimpleName());
}

Expand Down

0 comments on commit 0b3dae6

Please sign in to comment.