Added version and help commands
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
8acf7c4ff2
commit
c90c28dd60
30
app/src/main/java/xyz/vallat/louis/commands/Aide.java
Normal file
30
app/src/main/java/xyz/vallat/louis/commands/Aide.java
Normal file
@ -0,0 +1,30 @@
|
||||
package xyz.vallat.louis.commands;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.rest.util.Color;
|
||||
import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.App;
|
||||
import xyz.vallat.louis.managers.discord.DiscordManager;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class Aide extends Command {
|
||||
|
||||
public Aide(String name) {
|
||||
super(name, "Un chouette menu d'aide.", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel().flatMap(channel -> channel.createEmbed(embed -> {
|
||||
DiscordManager.getCommands().forEach(c ->
|
||||
embed.addField(c.getName(), c.getDescription() + " Usage: " + c.getUsage(), false));
|
||||
embed.setColor(Color.GREEN)
|
||||
.setTitle(App.NAME)
|
||||
.setDescription("Besoin d'aide ?")
|
||||
.setUrl("https://gitlab.com/lovallat/reminder-bot")
|
||||
.setFooter("Menu d'aide", null)
|
||||
.setTimestamp(Instant.now());
|
||||
})).then().onErrorResume(t -> fatalError(event, t));
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ public class Desinscription extends Command {
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel().flatMap(channel -> {
|
||||
if (event.getMessage().getAuthor().isEmpty() ||
|
||||
StudentManager.deleteFromSnowflake(event.getMessage().getAuthor().get().getId().asString()))
|
||||
!StudentManager.deleteFromSnowflake(event.getMessage().getAuthor().get().getId().asString()))
|
||||
return channel.createMessage("On dirait que je ne t'ai pas dans ma base de données !");
|
||||
return channel.createMessage("C'est bon, tu n'es plus dans ma base de données ! :thumbs_up:");
|
||||
}).then().onErrorResume(t -> fatalError(event, t));
|
||||
|
30
app/src/main/java/xyz/vallat/louis/commands/Version.java
Normal file
30
app/src/main/java/xyz/vallat/louis/commands/Version.java
Normal file
@ -0,0 +1,30 @@
|
||||
package xyz.vallat.louis.commands;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.rest.util.Color;
|
||||
import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.App;
|
||||
import xyz.vallat.louis.managers.discord.DiscordManager;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class Version extends Command {
|
||||
|
||||
public Version(String name) {
|
||||
super(name, "Donne des informations sur la version de ce bot.", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel().flatMap(channel -> channel.createEmbed(embed -> {
|
||||
embed.setColor(Color.GREEN)
|
||||
.setTitle(App.NAME)
|
||||
.setDescription(App.DESCRIPTION)
|
||||
.setUrl("https://gitlab.com/lovallat/reminder-bot")
|
||||
.setTimestamp(Instant.now())
|
||||
.addField("Version", App.VERSION, false);
|
||||
String imageURL = DiscordManager.getClientImage().block();
|
||||
if (imageURL != null) embed.setThumbnail(imageURL);
|
||||
})).then().onErrorResume(t -> fatalError(event, t));
|
||||
}
|
||||
}
|
@ -63,6 +63,7 @@ public final class StudentManager {
|
||||
}
|
||||
|
||||
public static boolean deleteFromSnowflake(String snowflake) {
|
||||
logger.debug("Deleting student {}.", snowflake);
|
||||
try (Connection connection = DBManager.getConnection()) {
|
||||
String sql = "DELETE FROM students WHERE snowflake = ?;";
|
||||
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
|
||||
|
@ -9,10 +9,8 @@ import discord4j.core.object.presence.Activity;
|
||||
import discord4j.core.object.presence.Presence;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.vallat.louis.commands.Command;
|
||||
import xyz.vallat.louis.commands.Desinscription;
|
||||
import xyz.vallat.louis.commands.Inscription;
|
||||
import xyz.vallat.louis.commands.Lien;
|
||||
import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.commands.*;
|
||||
import xyz.vallat.louis.environment.EnvironmentVariables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,6 +28,8 @@ public final class DiscordManager {
|
||||
commands.add(new Inscription(PREFIX + "inscription"));
|
||||
commands.add(new Desinscription(PREFIX + "désincription"));
|
||||
commands.add(new Lien(PREFIX + "lien"));
|
||||
commands.add(new Version(PREFIX + "version"));
|
||||
commands.add(new Aide(PREFIX + "aide"));
|
||||
}
|
||||
|
||||
private DiscordManager() {
|
||||
@ -66,6 +66,11 @@ public final class DiscordManager {
|
||||
registerDiscordCommands();
|
||||
}
|
||||
|
||||
public static Mono<String> getClientImage() {
|
||||
if (discordClient == null) return Mono.empty();
|
||||
return discordClient.getSelf().map(User::getAvatarUrl);
|
||||
}
|
||||
|
||||
public static void onDisconnect() {
|
||||
discordClient.onDisconnect().block();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user