mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-21 02:31:37 +01:00
Improve presence updater
This commit is contained in:
parent
f7dcd69b77
commit
e39abde2bb
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user