-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
317 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/de/rettichlp/shantybot/commands/CommandsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.rettichlp.shantybot.commands; | ||
|
||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.SelfUser; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
import static de.rettichlp.shantybot.ShantyBot.discordBot; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class CommandsCommand extends CommandBase { | ||
|
||
public CommandsCommand(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void onCommand(SlashCommandInteractionEvent event) { | ||
SelfUser botUser = discordBot.getSelfUser(); | ||
EmbedBuilder embedBuilder = new EmbedBuilder() | ||
.setTitle("ShantyBot Befehle") | ||
.setAuthor(botUser.getName(), null, botUser.getAvatarUrl()); | ||
|
||
requireNonNull(event.getGuild()).retrieveCommands().queue(commands -> { | ||
commands.stream() | ||
.filter(command -> command.getApplicationId().equals(botUser.getId())) | ||
.forEach(command -> embedBuilder.addField("/" + command.getName(), command.getDescription(), false)); | ||
|
||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue(); | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/de/rettichlp/shantybot/commands/IpCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.rettichlp.shantybot.commands; | ||
|
||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
import static de.rettichlp.shantybot.ShantyBot.api; | ||
import static de.rettichlp.shantybot.common.services.UtilService.sendSelfDeletingMessage; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class IpCommand extends CommandBase { | ||
|
||
public IpCommand(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void onCommand(SlashCommandInteractionEvent event) { | ||
if (api.apiNotReachable()) { | ||
sendSelfDeletingMessage(event, "Die [API](https://api.mcsrvstat.us/3/shantytown.eu) ist aktuell nicht erreichbar. Bitte versuche es später erneut."); | ||
return; | ||
} | ||
|
||
String version = ofNullable(api.getVersion()) | ||
.map(s -> " und ist aktuell auf der Version **" + s + "**.") | ||
.orElse("."); | ||
|
||
String maintenance = api.isMaintenance() ? "\n⚠️ Aktuell sind Wartungsarbeiten!" : ""; | ||
|
||
String offline = ofNullable(api.isOffline()).map(b -> b ? "\n⛔ Der Server ist aktuell offline!" : "").orElse(""); | ||
|
||
event.reply("ShantyTown hat die IP **[shantytown.eu](https://shantytown.eu/)**%s%s%s" .formatted(version, maintenance, offline)).queue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/de/rettichlp/shantybot/commands/PlayersCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.rettichlp.shantybot.commands; | ||
|
||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
import static de.rettichlp.shantybot.ShantyBot.api; | ||
import static de.rettichlp.shantybot.common.services.UtilService.sendSelfDeletingMessage; | ||
import static java.util.Objects.nonNull; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class PlayersCommand extends CommandBase { | ||
|
||
public PlayersCommand(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void onCommand(SlashCommandInteractionEvent event) { | ||
if (api.apiNotReachable()) { | ||
sendSelfDeletingMessage(event, "Die [API](https://api.mcsrvstat.us/3/shantytown.eu) ist aktuell nicht erreichbar. Bitte versuche es später erneut."); | ||
return; | ||
} | ||
|
||
String maxPlayers = ofNullable(api.getMaxPlayers()) | ||
.map(s -> " von **" + s + "**") | ||
.orElse(""); | ||
|
||
String areString = api.getOnlinePlayers() == 1 ? "ist" : "sind"; | ||
String playerString = (nonNull(api.getMaxPlayers()) && api.getMaxPlayers() != 1) ? "Spielern" : "Spieler"; | ||
|
||
event.reply("Aktuell %s **%d**%s %s online." .formatted(areString, api.getOnlinePlayers(), maxPlayers, playerString)).queue(); | ||
} | ||
} |
Oops, something went wrong.