Search in sources :

Example 11 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project MMDBot by MinecraftModDevelopment.

the class CmdCommunityChannel method execute.

/**
 * Execute.
 *
 * @param event The {@link SlashCommandEvent CommandEvent} that triggered this Command.
 */
@Override
protected void execute(final SlashCommandEvent event) {
    if (!Utils.checkCommand(this, event)) {
        return;
    }
    final var guild = event.getGuild();
    final var author = guild.getMember(event.getUser());
    if (author == null) {
        return;
    }
    Member user = event.getOption("user").getAsMember();
    String channel = event.getOption("channel").getAsString();
    final var categoryID = MMDBot.getConfig().getCommunityChannelCategory();
    final var category = guild.getCategoryById(categoryID);
    if (categoryID == 0 || category == null) {
        MMDBot.LOGGER.warn("Community channel category is incorrectly configured");
        event.reply("Community channel category is incorrectly configured. Please contact the bot maintainers.").queue();
        return;
    }
    final Set<Permission> ownerPermissions = MMDBot.getConfig().getCommunityChannelOwnerPermissions();
    if (ownerPermissions.isEmpty()) {
        MMDBot.LOGGER.warn("Community channel owner permissions is incorrectly configured");
        event.reply("Channel owner permissions is incorrectly configured. Please contact the bot maintainers.").queue();
        return;
    }
    final Set<Permission> diff = Sets.difference(ownerPermissions, event.getGuild().getSelfMember().getPermissions());
    if (!diff.isEmpty()) {
        MMDBot.LOGGER.warn("Cannot assign permissions to channel owner due to insufficient permissions: {}", diff);
        event.reply("Cannot assign certain permissions to channel owner due to insufficient permissions; " + "continuing anyway...").queue();
        ownerPermissions.removeIf(diff::contains);
    }
    final List<Emote> emote = new ArrayList<>(4);
    emote.addAll(guild.getEmotesByName("mmd1", true));
    emote.addAll(guild.getEmotesByName("mmd2", true));
    emote.addAll(guild.getEmotesByName("mmd3", true));
    emote.addAll(guild.getEmotesByName("mmd4", true));
    // Flavor text: if the emotes are available, use them, else just use plain MMD
    final var emoteText = emote.size() == 4 ? emote.stream().map(Emote::getAsMention).collect(Collectors.joining()) : "";
    final var flavorText = emoteText.isEmpty() ? "MMD" : emoteText;
    MMDBot.LOGGER.info("Creating new community channel for {} ({}), named \"{}\" (command issued by {} ({}))", user.getEffectiveName(), user.getUser().getName(), channel, author.getEffectiveName(), author.getUser().getName());
    category.createTextChannel(channel).flatMap(ch -> category.modifyTextChannelPositions().sortOrder(Comparator.comparing(GuildChannel::getName)).map($ -> ch)).flatMap(ch -> ch.putPermissionOverride(user).setAllow(ownerPermissions).map($ -> ch)).flatMap(ch -> ch.sendMessage(new MessageBuilder().appendFormat("Welcome %s to your new community channel, %s!%n", user.getAsMention(), ch.getAsMention()).append('\n').append("Please adhere to the Code of Conduct of the server").appendFormat(" (which can be visited from the <#%s> channel),", MMDBot.getConfig().getChannel("info.rules")).append(" specifically the Channel Policy section.").append('\n').append('\n').appendFormat("Thank you, and enjoy your new home here at %s!", flavorText).build()).map($ -> ch)).queue(c -> event.reply("Successfully created community channel at " + c.getAsMention() + "!").queue());
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) Utils(com.mcmoddev.mmdbot.utilities.Utils) Permission(net.dv8tion.jda.api.Permission) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) Set(java.util.Set) Member(net.dv8tion.jda.api.entities.Member) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayList(java.util.ArrayList) SlashCommandEvent(com.jagrosh.jdautilities.command.SlashCommandEvent) MMDBot(com.mcmoddev.mmdbot.MMDBot) List(java.util.List) SlashCommand(com.jagrosh.jdautilities.command.SlashCommand) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Comparator(java.util.Comparator) Emote(net.dv8tion.jda.api.entities.Emote) EnumSet(java.util.EnumSet) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Emote(net.dv8tion.jda.api.entities.Emote) Permission(net.dv8tion.jda.api.Permission) ArrayList(java.util.ArrayList) Member(net.dv8tion.jda.api.entities.Member)

Example 12 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project Bean by Xirado.

the class InteractionCommandHandler method handleUserContextCommand.

public void handleUserContextCommand(@NotNull UserContextInteractionEvent event) {
    if (!event.isFromGuild())
        return;
    Guild guild = event.getGuild();
    Member member = event.getMember();
    UserContextCommand command = null;
    if (registeredGuildCommands.containsKey(guild.getIdLong())) {
        List<UserContextCommand> guildCommands = registeredGuildCommands.get(guild.getIdLong()).stream().filter(cmd -> cmd instanceof UserContextCommand).map(cmd -> (UserContextCommand) cmd).toList();
        UserContextCommand guildCommand = guildCommands.stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
        if (guildCommand != null)
            command = guildCommand;
    }
    if (command == null) {
        UserContextCommand globalCommand = getRegisteredUserContextCommands().stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
        if (globalCommand != null)
            command = globalCommand;
    }
    if (command == null)
        return;
    List<Permission> neededPermissions = command.getRequiredUserPermissions();
    List<Permission> neededBotPermissions = command.getRequiredBotPermissions();
    if (neededPermissions != null && !member.hasPermission((GuildChannel) event.getChannel(), neededPermissions)) {
        event.reply(LocaleLoader.ofGuild(guild).get("general.no_perms", String.class)).queue();
        return;
    }
    if (neededBotPermissions != null && !event.getGuild().getSelfMember().hasPermission((GuildChannel) event.getChannel(), neededBotPermissions)) {
        event.reply(LocaleLoader.ofGuild(guild).get("general.no_bot_perms1", String.class)).queue();
        return;
    }
    if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_VC)) {
        GuildVoiceState guildVoiceState = member.getVoiceState();
        if (guildVoiceState == null || !guildVoiceState.inAudioChannel()) {
            event.replyEmbeds(EmbedUtil.errorEmbed("You are not connected to a voice-channel!")).queue();
            return;
        }
    }
    if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_SAME_VC)) {
        GuildVoiceState voiceState = member.getVoiceState();
        AudioManager manager = event.getGuild().getAudioManager();
        if (manager.isConnected()) {
            if (!manager.getConnectedChannel().equals(voiceState.getChannel())) {
                event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in " + manager.getConnectedChannel().getAsMention() + "to do this!")).setEphemeral(true).queue();
                return;
            }
        }
    }
    UserContextCommand finalCommand = command;
    Runnable r = () -> {
        try {
            finalCommand.executeCommand(event);
            Metrics.COMMANDS.labels("success").inc();
        } catch (Exception e) {
            Metrics.COMMANDS.labels("failed").inc();
            LinkedDataObject translation = event.getGuild() == null ? LocaleLoader.getForLanguage("en_US") : LocaleLoader.ofGuild(event.getGuild());
            if (event.isAcknowledged())
                event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
                }, ex -> {
                });
            else
                event.replyEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
                }, ex -> {
                });
            LOGGER.error("Could not execute user-context-menu-command", e);
            EmbedBuilder builder = new EmbedBuilder().setTitle("An error occurred while executing a user-context-command!").addField("Guild", event.getGuild() == null ? "None (Direct message)" : event.getGuild().getIdLong() + " (" + event.getGuild().getName() + ")", true).addField("Channel", event.getGuild() == null ? "None (Direct message)" : event.getChannel().getName(), true).addField("User", event.getUser().getAsMention() + " (" + event.getUser().getAsTag() + ")", true).addField("Command", event.getName(), false).setColor(EmbedUtil.ERROR_COLOR);
            event.getJDA().openPrivateChannelById(Bean.OWNER_ID).flatMap(c -> c.sendMessageEmbeds(builder.build()).content("```fix\n" + ExceptionUtils.getStackTrace(e) + "\n```")).queue();
        }
    };
    Bean.getInstance().getCommandExecutor().submit(r);
}
Also used : LocaleLoader(at.xirado.bean.translation.LocaleLoader) MessageContextInteractionEvent(net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent) Permission(net.dv8tion.jda.api.Permission) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Util(at.xirado.bean.misc.Util) Member(net.dv8tion.jda.api.entities.Member) Command(net.dv8tion.jda.api.interactions.commands.Command) ArrayList(java.util.ArrayList) at.xirado.bean.command.slashcommands.moderation(at.xirado.bean.command.slashcommands.moderation) UserContextInteractionEvent(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent) Guild(net.dv8tion.jda.api.entities.Guild) at.xirado.bean.command.slashcommands.music(at.xirado.bean.command.slashcommands.music) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) Map(java.util.Map) GenericCommand(at.xirado.bean.command.GenericCommand) SlashCommand(at.xirado.bean.command.SlashCommand) EmbedUtil(at.xirado.bean.misc.EmbedUtil) UserContextCommand(at.xirado.bean.command.context.UserContextCommand) MockContextMenuCommand(at.xirado.bean.command.context.message.MockContextMenuCommand) Logger(org.slf4j.Logger) at.xirado.bean.command.slashcommands(at.xirado.bean.command.slashcommands) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Metrics(at.xirado.bean.misc.Metrics) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) MessageContextCommand(at.xirado.bean.command.context.MessageContextCommand) CommandAutoCompleteInteractionEvent(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CommandFlag(at.xirado.bean.command.CommandFlag) at.xirado.bean.command.slashcommands.leveling(at.xirado.bean.command.slashcommands.leveling) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) CommandListUpdateAction(net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction) Bean(at.xirado.bean.Bean) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) SlapContextMenuCommand(at.xirado.bean.command.context.user.SlapContextMenuCommand) LinkedDataObject(at.xirado.bean.data.LinkedDataObject) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) UserContextCommand(at.xirado.bean.command.context.UserContextCommand) LinkedDataObject(at.xirado.bean.data.LinkedDataObject) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Guild(net.dv8tion.jda.api.entities.Guild) AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Permission(net.dv8tion.jda.api.Permission) Member(net.dv8tion.jda.api.entities.Member)

Example 13 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project Bean by Xirado.

the class InteractionCommandHandler method handleMessageContextCommand.

public void handleMessageContextCommand(@NotNull MessageContextInteractionEvent event) {
    if (!event.isFromGuild())
        return;
    Guild guild = event.getGuild();
    Member member = event.getMember();
    MessageContextCommand command = null;
    if (registeredGuildCommands.containsKey(guild.getIdLong())) {
        List<MessageContextCommand> guildCommands = registeredGuildCommands.get(guild.getIdLong()).stream().filter(cmd -> cmd instanceof MessageContextCommand).map(cmd -> (MessageContextCommand) cmd).toList();
        MessageContextCommand guildCommand = guildCommands.stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
        if (guildCommand != null)
            command = guildCommand;
    }
    if (command == null) {
        MessageContextCommand globalCommand = getRegisteredMessageContextCommands().stream().filter(cmd -> cmd.getData().getName().equalsIgnoreCase(event.getName())).findFirst().orElse(null);
        if (globalCommand != null)
            command = globalCommand;
    }
    if (command == null)
        return;
    List<Permission> neededPermissions = command.getRequiredUserPermissions();
    List<Permission> neededBotPermissions = command.getRequiredBotPermissions();
    if (neededPermissions != null && !member.hasPermission((GuildChannel) event.getChannel(), neededPermissions)) {
        event.reply(LocaleLoader.ofGuild(guild).get("general.no_perms", String.class)).queue();
        return;
    }
    if (neededBotPermissions != null && !event.getGuild().getSelfMember().hasPermission((GuildChannel) event.getChannel(), neededBotPermissions)) {
        event.reply(LocaleLoader.ofGuild(guild).get("general.no_bot_perms1", String.class)).queue();
        return;
    }
    if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_VC)) {
        GuildVoiceState guildVoiceState = member.getVoiceState();
        if (guildVoiceState == null || !guildVoiceState.inAudioChannel()) {
            event.replyEmbeds(EmbedUtil.errorEmbed("You are not connected to a voice-channel!")).queue();
            return;
        }
    }
    if (command.getCommandFlags().contains(CommandFlag.MUST_BE_IN_SAME_VC)) {
        GuildVoiceState voiceState = member.getVoiceState();
        AudioManager manager = event.getGuild().getAudioManager();
        if (manager.isConnected()) {
            if (!manager.getConnectedChannel().equals(voiceState.getChannel())) {
                event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in " + manager.getConnectedChannel().getAsMention() + "to do this!")).setEphemeral(true).queue();
                return;
            }
        }
    }
    MessageContextCommand finalCommand = command;
    Runnable r = () -> {
        try {
            finalCommand.executeCommand(event);
            Metrics.COMMANDS.labels("success").inc();
        } catch (Exception e) {
            Metrics.COMMANDS.labels("failed").inc();
            LinkedDataObject translation = event.getGuild() == null ? LocaleLoader.getForLanguage("en_US") : LocaleLoader.ofGuild(event.getGuild());
            if (event.isAcknowledged())
                event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
                }, ex -> {
                });
            else
                event.replyEmbeds(EmbedUtil.errorEmbed(translation.getString("general.unknown_error_occured"))).setEphemeral(true).queue(s -> {
                }, ex -> {
                });
            LOGGER.error("Could not execute message-context-menu-command", e);
            EmbedBuilder builder = new EmbedBuilder().setTitle("An error occurred while executing a message-context-command!").addField("Guild", event.getGuild() == null ? "None (Direct message)" : event.getGuild().getIdLong() + " (" + event.getGuild().getName() + ")", true).addField("Channel", event.getGuild() == null ? "None (Direct message)" : event.getChannel().getName(), true).addField("User", event.getUser().getAsMention() + " (" + event.getUser().getAsTag() + ")", true).addField("Command", event.getName(), false).setColor(EmbedUtil.ERROR_COLOR);
            event.getJDA().openPrivateChannelById(Bean.OWNER_ID).flatMap(c -> c.sendMessageEmbeds(builder.build()).content("```fix\n" + ExceptionUtils.getStackTrace(e) + "\n```")).queue();
        }
    };
    Bean.getInstance().getCommandExecutor().submit(r);
}
Also used : LocaleLoader(at.xirado.bean.translation.LocaleLoader) MessageContextInteractionEvent(net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent) Permission(net.dv8tion.jda.api.Permission) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Util(at.xirado.bean.misc.Util) Member(net.dv8tion.jda.api.entities.Member) Command(net.dv8tion.jda.api.interactions.commands.Command) ArrayList(java.util.ArrayList) at.xirado.bean.command.slashcommands.moderation(at.xirado.bean.command.slashcommands.moderation) UserContextInteractionEvent(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent) Guild(net.dv8tion.jda.api.entities.Guild) at.xirado.bean.command.slashcommands.music(at.xirado.bean.command.slashcommands.music) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) Map(java.util.Map) GenericCommand(at.xirado.bean.command.GenericCommand) SlashCommand(at.xirado.bean.command.SlashCommand) EmbedUtil(at.xirado.bean.misc.EmbedUtil) UserContextCommand(at.xirado.bean.command.context.UserContextCommand) MockContextMenuCommand(at.xirado.bean.command.context.message.MockContextMenuCommand) Logger(org.slf4j.Logger) at.xirado.bean.command.slashcommands(at.xirado.bean.command.slashcommands) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Metrics(at.xirado.bean.misc.Metrics) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) MessageContextCommand(at.xirado.bean.command.context.MessageContextCommand) CommandAutoCompleteInteractionEvent(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CommandFlag(at.xirado.bean.command.CommandFlag) at.xirado.bean.command.slashcommands.leveling(at.xirado.bean.command.slashcommands.leveling) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) CommandListUpdateAction(net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction) Bean(at.xirado.bean.Bean) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) SlapContextMenuCommand(at.xirado.bean.command.context.user.SlapContextMenuCommand) LinkedDataObject(at.xirado.bean.data.LinkedDataObject) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) LinkedDataObject(at.xirado.bean.data.LinkedDataObject) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Guild(net.dv8tion.jda.api.entities.Guild) MessageContextCommand(at.xirado.bean.command.context.MessageContextCommand) AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Permission(net.dv8tion.jda.api.Permission) Member(net.dv8tion.jda.api.entities.Member)

Example 14 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project Emolga by TecToast.

the class EmolgaDiktaturCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Guild g = e.getGuild();
    JSONObject members = new JSONObject();
    JSONObject channels = new JSONObject();
    e.getChannel().sendMessage("**Möge die Emolga-Diktatur beginnen!**").queue();
    g.loadMembers().onSuccess(list -> {
        for (Member member : list) {
            if (member.isOwner())
                continue;
            if (member.getId().equals(e.getJDA().getSelfUser().getId()))
                member.modifyNickname("Diktator").queue();
            if (!g.getSelfMember().canInteract(member))
                continue;
            members.put(member.getId(), member.getEffectiveName());
            member.modifyNickname("Emolga-Anhänger").queue();
        }
        for (GuildChannel gc : g.getChannels()) {
            gc.getManager().setName("Emolga-" + gc.getName()).queue();
        }
        getEmolgaJSON().getJSONObject("emolgareset").put(g.getId(), members);
        saveEmolgaJSON();
    });
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) JSONObject(org.jsolf.JSONObject) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member)

Example 15 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project c10ver by Gartham.

the class DungeonGame method startDungeon.

private void startDungeon(ButtonClickEvent e) {
    // This is broken lmao.
    t = e.getMessage();
    // try {
    // Thread.sleep((long) (Math.random() * 3500 + 1500));
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }
    var dungeon = Dungeon.simpleEasyDungeon();
    var initialRoom = dungeon.getInitialRoom();
    var dirsel = new CustomDirsel();
    dirsel.disableDirections();
    for (var d : initialRoom.getConnectionDirectionsUnmodifiable()) dirsel.enable(d);
    var inp = new InputConsumer<ButtonClickEvent>() {

        DungeonRoom currentRoom = initialRoom;

        @Override
        public boolean consume(ButtonClickEvent event, InputProcessor<? extends ButtonClickEvent> processor, InputConsumer<ButtonClickEvent> consumer) {
            if (event.getMessageIdLong() != t.getIdLong())
                return false;
            if (event.getUser().getIdLong() != target.getIdLong()) {
                event.reply("That's not for you. >:(").setEphemeral(true).queue();
                return true;
            }
            if (event.getComponentId().equals("act")) {
                if (currentRoom.isClaimed()) {
                    event.reply("You already collected the loot from this room... (You're not supposed to be able to click that button again!)").setEphemeral(true).queue();
                    return true;
                }
                currentRoom.setClaimed(true);
                var user = clover.getEconomy().getUser(target.getId());
                Receipt receipt;
                var lr = (LootRoom) currentRoom;
                receipt = user.reward(lr.getRewards().autoSetMultipliers(user, channel.getType().isGuild() ? ((GuildChannel) channel).getGuild() : null));
                currentRoom.prepare(dirsel, "act");
                event.editComponents(dirsel.actionRows()).queue();
                t.reply(target.getAsMention() + ", you earned:\n\n" + Utilities.listRewards(receipt)).queue();
            // Resend message? Send ephemeral rewards?
            } else if (event.getComponentId().equals("repeat")) {
                var dsn = new CustomDirsel();
                dsn.disableManaged();
                var s = channel.sendMessageEmbeds(event.getMessage().getEmbeds()).setActionRows(event.getMessage().getActionRows());
                event.editComponents(dsn.actionRows()).queue(x -> s.queue(q -> t = q));
            } else {
                var dir = DirectionSelector.getDirectionSelected(event);
                currentRoom = currentRoom.getRoom(dir);
                if (currentRoom == null) {
                    // Player moved in the wrong direction.
                    event.reply("You are not supposed to be able to click that!").setEphemeral(true).queue();
                    return true;
                // processor.removeInputConsumer(consumer);
                } else if (!currentRoom.isClaimed() && currentRoom instanceof EnemyRoom) {
                    dirsel.reset();
                    dirsel.disableManaged();
                    event.editComponents(dirsel.actionRows()).setContent("**You got into a fight!!!**").setEmbeds(new EmbedBuilder().setColor(new Color(0xFF0000)).setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).queue();
                    channel.sendMessage("The room was full of enemies!").queue(x -> {
                        channel.sendTyping().queue(x0 -> {
                            var room = (EnemyRoom) currentRoom;
                            currentRoom.setClaimed(true);
                            GarmonTeam player = new GarmonTeam(target.getAsTag(), new PlayerFighter(target.getName(), target.getEffectiveAvatarUrl(), BigInteger.valueOf(25), BigInteger.valueOf(100), BigInteger.valueOf(100), BigInteger.valueOf(25), BigInteger.valueOf(5)));
                            var team = room.getEnemies();
                            GarmonBattle battle = new GarmonBattle(player, team);
                            player.setController(new PlayerController(battle, clover, target, channel));
                            team.setController(new CreatureAI(battle, channel));
                            battle.startAsync(true, winner -> {
                                if (winner == player) {
                                    EconomyUser user = clover.getEconomy().getUser(target.getId());
                                    RewardsOperation rewop = RewardsOperation.build(user, channel.getGuild(), BigInteger.valueOf((long) (Math.random() * 142 + 25)), new ItemBunch<>(new VoteToken(gartham.c10ver.economy.items.valuables.VoteToken.Type.NORMAL)));
                                    currentRoom.prepare(dirsel, "act");
                                    channel.sendMessage(target.getAsMention() + ", you won the fight!\nYou earned:\n\n" + Utilities.listRewards(user.reward(rewop))).setEmbeds(new EmbedBuilder().setColor(new Color(0xFF00)).setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).queue(msg -> t = msg);
                                }
                            }, (long) (2000 + Math.random() * 1000));
                        });
                    });
                } else {
                    currentRoom.prepare(dirsel, "act");
                    event.editMessageEmbeds(new EmbedBuilder().setTitle("Room #" + (dungeon.index(currentRoom) + 1)).setDescription("```" + currentRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).setContent("").queue();
                }
            }
            return true;
        }
    };
    clover.getEventHandler().getButtonClickProcessor().registerInputConsumer(inp);
    t.editMessage(new MessageBuilder().setEmbeds(new EmbedBuilder().setTitle("W1-1").setDescription("```" + initialRoom.getRoom().tilemapString() + "```").setFooter("Choose a path.").build()).setActionRows(dirsel.actionRows()).build()).queue();
}
Also used : Color(java.awt.Color) EconomyUser(gartham.c10ver.economy.users.EconomyUser) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) Receipt(gartham.c10ver.economy.users.EconomyUser.Receipt) PlayerController(gartham.c10ver.games.rpg.fighting.battles.app.PlayerController) ItemBunch(gartham.c10ver.economy.items.ItemBunch) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) PlayerFighter(gartham.c10ver.games.rpg.fighting.battles.app.PlayerFighter) Utilities(gartham.c10ver.utils.Utilities) TextChannel(net.dv8tion.jda.api.entities.TextChannel) User(net.dv8tion.jda.api.entities.User) RewardsOperation(gartham.c10ver.economy.RewardsOperation) Button(net.dv8tion.jda.api.interactions.components.Button) InputConsumer(gartham.c10ver.commands.consumers.InputConsumer) GarmonBattle(gartham.c10ver.games.rpg.fighting.battles.app.GarmonBattle) BigInteger(java.math.BigInteger) ActionRow(net.dv8tion.jda.api.interactions.components.ActionRow) GarmonTeam(gartham.c10ver.games.rpg.fighting.battles.app.GarmonTeam) DirectionSelector(gartham.c10ver.response.utils.DirectionSelector) Message(net.dv8tion.jda.api.entities.Message) VoteToken(gartham.c10ver.economy.items.valuables.VoteToken) ButtonBook(gartham.c10ver.response.menus.ButtonBook) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Emoji(net.dv8tion.jda.api.entities.Emoji) List(java.util.List) Action(gartham.apps.garthchat.api.execution.Action) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) InputProcessor(gartham.c10ver.commands.InputProcessor) CreatureAI(gartham.c10ver.games.rpg.fighting.battles.app.CreatureAI) Clover(gartham.c10ver.Clover) Receipt(gartham.c10ver.economy.users.EconomyUser.Receipt) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) PlayerController(gartham.c10ver.games.rpg.fighting.battles.app.PlayerController) Color(java.awt.Color) RewardsOperation(gartham.c10ver.economy.RewardsOperation) GarmonTeam(gartham.c10ver.games.rpg.fighting.battles.app.GarmonTeam) InputProcessor(gartham.c10ver.commands.InputProcessor) GarmonBattle(gartham.c10ver.games.rpg.fighting.battles.app.GarmonBattle) VoteToken(gartham.c10ver.economy.items.valuables.VoteToken) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) EconomyUser(gartham.c10ver.economy.users.EconomyUser) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) InputConsumer(gartham.c10ver.commands.consumers.InputConsumer) PlayerFighter(gartham.c10ver.games.rpg.fighting.battles.app.PlayerFighter) CreatureAI(gartham.c10ver.games.rpg.fighting.battles.app.CreatureAI)

Aggregations

GuildChannel (net.dv8tion.jda.api.entities.GuildChannel)16 Guild (net.dv8tion.jda.api.entities.Guild)9 Member (net.dv8tion.jda.api.entities.Member)9 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Permission (net.dv8tion.jda.api.Permission)5 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)4 Bean (at.xirado.bean.Bean)3 CommandFlag (at.xirado.bean.command.CommandFlag)3 GenericCommand (at.xirado.bean.command.GenericCommand)3 SlashCommand (at.xirado.bean.command.SlashCommand)3 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)3 MessageContextCommand (at.xirado.bean.command.context.MessageContextCommand)3 UserContextCommand (at.xirado.bean.command.context.UserContextCommand)3 MockContextMenuCommand (at.xirado.bean.command.context.message.MockContextMenuCommand)3 SlapContextMenuCommand (at.xirado.bean.command.context.user.SlapContextMenuCommand)3 at.xirado.bean.command.slashcommands (at.xirado.bean.command.slashcommands)3 at.xirado.bean.command.slashcommands.leveling (at.xirado.bean.command.slashcommands.leveling)3 at.xirado.bean.command.slashcommands.moderation (at.xirado.bean.command.slashcommands.moderation)3 at.xirado.bean.command.slashcommands.music (at.xirado.bean.command.slashcommands.music)3