Improve presence updater

This commit is contained in:
Vankka 2025-02-14 22:25:50 +02:00
parent f7dcd69b77
commit e39abde2bb
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB

View File

@ -27,6 +27,7 @@ import com.discordsrv.common.config.main.PresenceUpdaterConfig;
import com.discordsrv.common.core.logging.NamedLogger;
import com.discordsrv.common.core.module.type.AbstractModule;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.events.StatusChangeEvent;
import java.time.Duration;
@ -52,12 +53,14 @@ public class PresenceUpdaterModule extends AbstractModule<DiscordSRV> {
}
public void serverStarted() {
logger().debug("Server started");
serverState.set(ServerState.STARTED);
setPresenceOrSchedule();
}
@Subscribe(priority = EventPriorities.EARLIEST)
public void onDiscordSRVShuttingDown(DiscordSRVShuttingDownEvent event) {
logger().debug("Plugin shutting down");
serverState.set(ServerState.STOPPING);
setPresenceOrSchedule();
}
@ -89,7 +92,10 @@ public class PresenceUpdaterModule extends AbstractModule<DiscordSRV> {
// Guess not
return;
}
jda.getPresence().setPresence(config.status, config.activity(null, discordSRV));
Activity newActivity = config.activity(null, discordSRV);
logger().debug("Changing activity to " + newActivity);
jda.getPresence().setPresence(config.status, newActivity);
}
private void setPresenceOrSchedule() {
@ -98,6 +104,11 @@ public class PresenceUpdaterModule extends AbstractModule<DiscordSRV> {
future.cancel(true);
}
if (discordSRV.isServerStarted() && serverState.get() == ServerState.PRE_START) {
logger().debug("Server is started, changing to STARTED state");
serverState.set(ServerState.STARTED);
}
PresenceUpdaterConfig config = discordSRV.config().presenceUpdater;
if (config instanceof PresenceUpdaterConfig.Server) {
PresenceUpdaterConfig.Server serverConfig = (PresenceUpdaterConfig.Server) config;