Added help command
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
f056308923
commit
f0e16f6b6e
@ -16,7 +16,6 @@ import xyz.vallat.louis.omdb.objects.Movie;
|
||||
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -67,6 +66,10 @@ public abstract class Command {
|
||||
return maxArgs;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected Mono<Void> notEnoughArguments(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(channel -> channel.createMessage("Error, you're missing some arguments.\n" + getUsage()))
|
||||
|
@ -81,7 +81,7 @@ public class Download extends Command {
|
||||
subs.getData().get(0).getContentAsString("cp1252"));
|
||||
SubtitleLineManager.importSubtitleLines(blocks, languageId, movie,
|
||||
event.getGuildId().isPresent() ? event.getGuildId().get() : null,
|
||||
event.getMember().isPresent() ? event.getMessage().getId() : null);
|
||||
event.getMember().isPresent() ? event.getMember().get().getId() : null);
|
||||
embed.setColor(Color.MEDIUM_SEA_GREEN).setDescription("Everything went well. " +
|
||||
"Congratulations and thank you for your contribution!");
|
||||
embed.addField("You imported", blocks.size() + " lines into my database", false);
|
||||
|
29
src/main/java/xyz/vallat/louis/commands/Help.java
Normal file
29
src/main/java/xyz/vallat/louis/commands/Help.java
Normal file
@ -0,0 +1,29 @@
|
||||
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.discord.DiscordManager;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class Help extends Command {
|
||||
|
||||
public Help(String name) {
|
||||
super(name, "I need help. You need help. We all need help at some point.", name, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel().flatMap(messageChannel -> messageChannel.createEmbed(embed -> {
|
||||
embed.setColor(Color.MEDIUM_SEA_GREEN).setTimestamp(Instant.now()).setTitle("Help")
|
||||
.setDescription("This is all the commands I know.");
|
||||
for (Command command : DiscordManager.getCommands())
|
||||
embed.addField(command.getName(),
|
||||
command.getDescription() + " Usage: " + command.getUsage() + ".", false);
|
||||
}
|
||||
)).then();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class ListLangMovie extends Command {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ListLangMovie.class.getCanonicalName());
|
||||
|
||||
public ListLangMovie(String name) {
|
||||
super(name, "List all languages attached to a film title or an IMDB Identifier.",
|
||||
super(name, "List all languages attached to a movie title or an IMDB Identifier.",
|
||||
name + " imdb|title value", 2, 2);
|
||||
}
|
||||
|
||||
|
@ -13,37 +13,42 @@ import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.commands.*;
|
||||
import xyz.vallat.louis.env.EnvironmentVariables;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static xyz.vallat.louis.MovieQuoteBot.PREFIX;
|
||||
|
||||
public final class DiscordManager {
|
||||
private static final List<Command> commands = new ArrayList<>();
|
||||
private static final Logger logger = LoggerFactory.getLogger(DiscordManager.class.getCanonicalName());
|
||||
private static final Map<String, Command> commands = new HashMap<>();
|
||||
private static GatewayDiscordClient discordClient;
|
||||
|
||||
static {
|
||||
commands.put("ping", new Ping(PREFIX + "ping"));
|
||||
commands.put("version", new Version(PREFIX + "version"));
|
||||
commands.put("listLangMovie", new ListLangMovie(PREFIX + "listLangMovie"));
|
||||
commands.put("download", new Download(PREFIX + "download"));
|
||||
commands.put("quote", new Quote(PREFIX + "quote"));
|
||||
commands.add(new ListLangMovie(PREFIX + "listLangMovie"));
|
||||
commands.add(new Download(PREFIX + "download"));
|
||||
commands.add(new Quote(PREFIX + "quote"));
|
||||
commands.add(new Ping(PREFIX + "ping"));
|
||||
commands.add(new Help(PREFIX + "help"));
|
||||
commands.add(new Version(PREFIX + "version"));
|
||||
}
|
||||
|
||||
private DiscordManager() {
|
||||
}
|
||||
|
||||
public static List<Command> getCommands() {
|
||||
return new ArrayList<>(commands);
|
||||
}
|
||||
|
||||
public static void logout() {
|
||||
discordClient.logout().block();
|
||||
}
|
||||
|
||||
private static void registerDiscordCommands() {
|
||||
for (Map.Entry<String, Command> command : commands.entrySet())
|
||||
for (Command command : commands)
|
||||
discordClient.getEventDispatcher().on(MessageCreateEvent.class)
|
||||
.filter(event -> event.getMessage().getAuthor().map(user -> !user.isBot()).orElse(false))
|
||||
.filter(event -> event.getMessage().getContent().split(" ")[0].equals(PREFIX + command.getKey()))
|
||||
.flatMap(event -> command.getValue().execute(event).then())
|
||||
.filter(event -> event.getMessage().getContent().split(" ")[0].equals(command.getName()))
|
||||
.flatMap(event -> command.execute(event).then())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user