Search in sources :

Example 1 with Trick

use of com.mcmoddev.mmdbot.utilities.tricks.Trick in project MMDBot by MinecraftModDevelopment.

the class CmdAddTrick method execute.

@Override
protected void execute(final SlashCommandEvent event) {
    if (!Utils.checkCommand(this, event)) {
        return;
    }
    if (!event.isFromGuild()) {
        event.deferReply(true).setContent("This command only works in a guild!").queue();
        return;
    }
    if (!Utils.memberHasRole(event.getMember(), MMDBot.getConfig().getRole("bot_maintainer"))) {
        event.deferReply(true).setContent("Only Bot Maintainers can use this command.").queue();
        return;
    }
    Trick trick = trickType.createFromCommand(event);
    Optional<Trick> originalTrick = Tricks.getTricks().stream().filter(t -> t.getNames().stream().anyMatch(n -> trick.getNames().contains(n))).findAny();
    originalTrick.ifPresentOrElse(original -> {
        Tricks.replaceTrick(original, trick);
        event.reply("Updated trick!").mentionRepliedUser(false).setEphemeral(true).queue();
    }, () -> {
        Tricks.addTrick(trick);
        event.reply("Added trick!").mentionRepliedUser(false).setEphemeral(true).queue();
    });
}
Also used : GistUtils(com.mcmoddev.mmdbot.gist.GistUtils) Command(com.jagrosh.jdautilities.command.Command) Utils(com.mcmoddev.mmdbot.utilities.Utils) IOException(java.io.IOException) CommandEvent(com.jagrosh.jdautilities.command.CommandEvent) Trick(com.mcmoddev.mmdbot.utilities.tricks.Trick) SlashCommandEvent(com.jagrosh.jdautilities.command.SlashCommandEvent) MMDBot(com.mcmoddev.mmdbot.MMDBot) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) Tricks(com.mcmoddev.mmdbot.utilities.tricks.Tricks) ScriptTrick(com.mcmoddev.mmdbot.utilities.tricks.ScriptTrick) Optional(java.util.Optional) Trick(com.mcmoddev.mmdbot.utilities.tricks.Trick) ScriptTrick(com.mcmoddev.mmdbot.utilities.tricks.ScriptTrick)

Aggregations

Command (com.jagrosh.jdautilities.command.Command)1 CommandEvent (com.jagrosh.jdautilities.command.CommandEvent)1 SlashCommand (com.jagrosh.jdautilities.command.SlashCommand)1 SlashCommandEvent (com.jagrosh.jdautilities.command.SlashCommandEvent)1 MMDBot (com.mcmoddev.mmdbot.MMDBot)1 GistUtils (com.mcmoddev.mmdbot.gist.GistUtils)1 Utils (com.mcmoddev.mmdbot.utilities.Utils)1 ScriptTrick (com.mcmoddev.mmdbot.utilities.tricks.ScriptTrick)1 Trick (com.mcmoddev.mmdbot.utilities.tricks.Trick)1 Tricks (com.mcmoddev.mmdbot.utilities.tricks.Tricks)1 IOException (java.io.IOException)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1