Archiviert
1
0

Add SteamwarDiscordBot presence

Dieser Commit ist enthalten in:
yoyosource 2021-07-28 15:54:57 +02:00
Ursprung 2c46d2e6a3
Commit a07c82bc13
2 geänderte Dateien mit 25 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bungeecore.bot; package de.steamwar.bungeecore.bot;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener; import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener;
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
@ -27,14 +28,18 @@ import lombok.Getter;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ActivityFlag; import net.dv8tion.jda.api.entities.ActivityFlag;
import net.dv8tion.jda.api.entities.RichPresence; import net.dv8tion.jda.api.entities.RichPresence;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.entities.SelfUserImpl;
import net.md_5.bungee.api.ProxyServer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.concurrent.TimeUnit;
public class SteamwarDiscordBot { public class SteamwarDiscordBot {
@ -50,7 +55,7 @@ public class SteamwarDiscordBot {
public SteamwarDiscordBot() { public SteamwarDiscordBot() {
INSTANCE = this; INSTANCE = this;
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN); JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
builder.setActivity(new RichPresence() { /*builder.setActivity(new RichPresence() {
@Override @Override
public long getApplicationIdLong() { public long getApplicationIdLong() {
return 869611389818400779L; return 869611389818400779L;
@ -154,7 +159,8 @@ public class SteamwarDiscordBot {
public Emoji getEmoji() { public Emoji getEmoji() {
return null; return null;
} }
}); });*/
builder.setStatus(OnlineStatus.ONLINE); builder.setStatus(OnlineStatus.ONLINE);
try { try {
jda = builder.build(); jda = builder.build();
@ -166,12 +172,28 @@ public class SteamwarDiscordBot {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::activity, 30, 0, TimeUnit.SECONDS);
DiscordRolesMessage.sendMessage(); DiscordRolesMessage.sendMessage();
DiscordRulesMessage.sendMessage(); DiscordRulesMessage.sendMessage();
new RolesInteractionButtonListener(); new RolesInteractionButtonListener();
} }
private int index = 0;
private void activity() {
switch (index) {
case 0:
jda.getPresence().setActivity(Activity.playing("SteamWar.de"));
break;
case 1:
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.DEFAULT, "Online: " + BungeeCore.get().getProxy().getOnlineCount()));
index = 0;
return;
}
index++;
}
public void addListener(ListenerAdapter listenerAdapter) { public void addListener(ListenerAdapter listenerAdapter) {
jda.addEventListener(listenerAdapter); jda.addEventListener(listenerAdapter);
} }

Datei anzeigen

@ -42,7 +42,7 @@ public class DiscordRulesMessage {
EmbedBuilder builder = new EmbedBuilder(); EmbedBuilder builder = new EmbedBuilder();
builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get()); builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get());
builder.setColor(Color.CYAN); builder.setColor(Color.GRAY);
builder.setAuthor("SteamWar", "https://www.steamwar.de"); builder.setAuthor("SteamWar", "https://www.steamwar.de");
builder.setTitle(SteamwarDiscordBotConfig.RULES_TITLE); builder.setTitle(SteamwarDiscordBotConfig.RULES_TITLE);