Skip to content

Commit

Permalink
Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rettichlp committed Aug 7, 2024
2 parents ae9f627 + 6ace4d3 commit b77df50
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 11 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ This bot was created for the Minecraft Server ShantyTown (shantytown.eu) to prov
Features are focused on the Minecraft server, so this bot won't work properly on other servers.
For this reason the sourcecode is public, so you can steal the code and modify it for your own server ;) .

<!-- TOC -->
* [ShantyBot](#shantybot)
* [Permissions](#permissions)
* [General Permissions](#general-permissions)
* [Activities regarding permissions](#activities-regarding-permissions)
* [Commands](#commands)
<!-- TOC -->

## Permissions

The bot needs the following permissions to work properly:

### General Permissions

The bot will ask for these permissions:

| Permission | Usage |
|----------------------|-----------------------------------------------------------------------|
| Add Reactions | Currently no usages - potential for upcoming features |
Expand All @@ -23,3 +35,18 @@ The bot needs the following permissions to work properly:
| Speak | Required for the music bot |
| Use Slash Commands | Required for the music bot and other features |

### Activities regarding permissions

With these permissions the bot has access to following activities:

![](https://private-user-images.githubusercontent.com/97811064/355839024-aa4e9f31-4852-4d71-b57c-fc3d3a416472.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMwMzgxNTMsIm5iZiI6MTcyMzAzNzg1MywicGF0aCI6Ii85NzgxMTA2NC8zNTU4MzkwMjQtYWE0ZTlmMzEtNDg1Mi00ZDcxLWI1N2MtZmMzZDNhNDE2NDcyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODA3VDEzMzczM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUwMmFiMTU5ODdlOThhYTFlY2U3YjgzOGM1ZTJkZWQxMWMxNDZiNjk0YjBiNDIzYjgyNzNiNDA4ZGMzZWNhOGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.QGpqYJL29ol7zK5hJ_FRYgvAkj1T7mwmYmmNUiGxFo4)

## Commands

The bot provides the following slash commands:

| Command | Description |
|----------------------------------|-----------------------------------------------------------------------|
| `/löschen` `amount` | Deletes the last \<amount> messages in the current channel |
| `/play` `search query` or `link` | Searches for a song on YouTube or via link (YouTube, Soundcloud, ...) |
| `/version` | Shows the current version of the bot |
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>de.rettichlp</groupId>
<artifactId>shantybot</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>ShantyBot</name>
Expand Down Expand Up @@ -40,6 +40,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
Expand All @@ -49,6 +53,13 @@
<scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.dv8tion/JDA -->
<dependency>
<groupId>net.dv8tion</groupId>
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/de/rettichlp/shantybot/ShantyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import de.rettichlp.shantybot.buttons.ResumeButton;
import de.rettichlp.shantybot.buttons.SkipButton;
import de.rettichlp.shantybot.buttons.StopButton;
import de.rettichlp.shantybot.commands.CommandsCommand;
import de.rettichlp.shantybot.commands.DeleteMessageCommand;
import de.rettichlp.shantybot.commands.MusicPlayCommand;
import de.rettichlp.shantybot.commands.IpCommand;
import de.rettichlp.shantybot.commands.MusicCommand;
import de.rettichlp.shantybot.commands.PlayersCommand;
import de.rettichlp.shantybot.commands.VersionCommand;
import de.rettichlp.shantybot.common.api.API;
import de.rettichlp.shantybot.common.configuration.DiscordBotProperties;
import de.rettichlp.shantybot.common.lavaplayer.AudioPlayerManager;
import de.rettichlp.shantybot.listeners.GuildMemberListener;
Expand Down Expand Up @@ -41,6 +45,7 @@ public class ShantyBot implements WebMvcConfigurer {
public static JDA discordBot;
public static DiscordBotProperties discordBotProperties;
public static AudioPlayerManager audioPlayerManager;
public static API api;

public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext context = run(ShantyBot.class, args);
Expand All @@ -53,6 +58,8 @@ public static void main(String[] args) throws InterruptedException {
getRuntime().addShutdownHook(new Thread(() -> ofNullable(discordBot).ifPresent(JDA::shutdown)));

log.info("Discord bot started in {}ms", currentTimeMillis() - discordBotStartTime);

api = new API();
}

private static void startDiscordBot() throws InterruptedException {
Expand All @@ -61,8 +68,11 @@ private static void startDiscordBot() throws InterruptedException {
.disableCache(MEMBER_OVERRIDES) // Disable parts of the cache
.enableIntents(MESSAGE_CONTENT, GUILD_MEMBERS, GUILD_MESSAGES, GUILD_VOICE_STATES)
.addEventListeners(
new CommandsCommand("befehle"),
new DeleteMessageCommand("löschen"),
new MusicPlayCommand("play"),
new IpCommand("ip"),
new MusicCommand("musik"),
new PlayersCommand("spieler"),
new VersionCommand("version")
)
.addEventListeners(
Expand All @@ -79,12 +89,16 @@ private static void startDiscordBot() throws InterruptedException {
.build().awaitReady();

discordBot.getGuilds().forEach(guild -> guild.updateCommands().addCommands(
slash("play", "Lässt den Bot Deinen Channel betreten und die angegebene Musik spielen")
.addOption(STRING, "link", "Link oder Name des Songs", true),
slash("version", "Zeigt die aktuelle Version des ShantyBots"),
slash("löschen", "Löscht die angegebene Menge an Nachrichten (optional eines bestimmten Nutzers)")
.addOption(INTEGER, "anzahl", "Anzahl der Nachrichten, die gelöscht werden sollen", true)
.setDefaultPermissions(enabledFor(MESSAGE_MANAGE))
.setDefaultPermissions(enabledFor(MESSAGE_MANAGE)),

slash("befehle", "Zeigt alle verfügbaren Befehle des ShantyBots"),
slash("ip", "Zeigt die IP, Version und zusätzliche Informationen über den Minecraft Server"),
slash("musik", "Lässt den Bot Deinen Channel betreten und die angegebene Musik spielen")
.addOption(STRING, "link", "Link oder Name des Songs", true),
slash("spieler", "Zeigt die Anzahl der Spieler die gerade auf dem Minecraft Server sind"),
slash("version", "Zeigt die aktuelle Version des ShantyBots")
).queue());

audioPlayerManager = new AudioPlayerManager();
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/de/rettichlp/shantybot/commands/CommandsCommand.java
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 src/main/java/de/rettichlp/shantybot/commands/IpCommand.java
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

public class MusicPlayCommand extends CommandBase {
public class MusicCommand extends CommandBase {

public MusicPlayCommand(String name) {
public MusicCommand(String name) {
super(name);
}

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/de/rettichlp/shantybot/commands/PlayersCommand.java
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();
}
}
Loading

0 comments on commit b77df50

Please sign in to comment.