Skip to content

Commit

Permalink
Approach for fetching users
Browse files Browse the repository at this point in the history
  • Loading branch information
yannicklamprecht committed May 2, 2022
1 parent 756c829 commit 5a663bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bot/src/main/java/de/chojo/gamejam/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.chojo.gamejam.data.GuildData;
import de.chojo.gamejam.data.JamData;
import de.chojo.gamejam.data.TeamData;
import de.chojo.gamejam.listener.ReadyStateChangeListener;
import de.chojo.gamejam.util.LogNotify;
import de.chojo.jdautil.command.SimpleCommand;
import de.chojo.jdautil.command.dispatching.CommandHub;
Expand All @@ -30,6 +31,7 @@
import de.chojo.sqlutil.updater.SqlType;
import de.chojo.sqlutil.updater.SqlUpdater;
import de.chojo.sqlutil.wrapper.QueryBuilderConfig;
import net.dv8tion.jda.api.hooks.AnnotatedEventManager;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
Expand Down Expand Up @@ -110,6 +112,8 @@ public void start() throws IOException, SQLException, LoginException {

buildCommands();

// shardManager.addEventListener(new ReadyStateChangeListener(shardManager));

Api.create(configuration, shardManager, teamData, jamData);
}

Expand Down Expand Up @@ -142,7 +146,8 @@ private void initBot() throws LoginException {
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_MESSAGES)
.setMemberCachePolicy(MemberCachePolicy.DEFAULT)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.setEventManagerProvider(id -> new AnnotatedEventManager())
.build();
RestAction.setDefaultFailure(throwable -> log.error("Unhandled exception occured: ", throwable));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* Copyright (C) 2022 DevCord Team and Contributor
*/

package de.chojo.gamejam.listener;

import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.ShutdownEvent;
import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReadyStateChangeListener {

private final ShardManager shardManager;
private static final Logger log = LoggerFactory.getLogger(ReadyStateChangeListener.class);

public ReadyStateChangeListener(ShardManager shardManager) {
this.shardManager = shardManager;
}

@SubscribeEvent
public void finishedLoading(ReadyEvent readyEvent){
log.warn("Available Guilds: {}",readyEvent.getGuildAvailableCount());
shardManager.setActivity(Activity.playing("Plugin-Jam-Bot"));
for (Guild guild : shardManager.getGuilds()) {
guild.loadMembers(member -> {
log.warn("Loaded member \"{}\" of guild \"{}\"", member.getEffectiveName(), guild.getName());
});
}
}

@SubscribeEvent
public void shutdown(ShutdownEvent shutdownEvent){
shardManager.setActivity(null);
}
}
1 change: 0 additions & 1 deletion docker/kubernetes/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1

resources:
- namespace.yaml
- ingress.yaml
- database.yaml
- game-jam-bot.yaml

0 comments on commit 5a663bf

Please sign in to comment.