Search in sources :

Example 76 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project DiscordBot by LXGaming.

the class QueueCommand method execute.

@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
    embedBuilder.setColor(DiscordUtil.DEFAULT);
    if (DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue() == null || DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().isEmpty()) {
        embedBuilder.setTitle("Nothing Queued", null);
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    if (arguments != null && !arguments.isEmpty()) {
        try {
            int index = (Integer.parseInt(arguments.get(0)) - 1);
            if (index > DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().size() || index < 0) {
                throw new NumberFormatException();
            }
            Audio audio = DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().get(index);
            embedBuilder.setColor(DiscordUtil.SUCCESS);
            if (audio != null && audio.getAudioTrack() != null) {
                embedBuilder.setTitle("Queued " + (index + 1) + ". '" + audio.getAudioTrack().getInfo().title + "'.");
            } else {
                embedBuilder.setTitle("Queued " + (index + 1) + ". 'Unknown" + "'.");
            }
            DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        } catch (NumberFormatException ex) {
            embedBuilder.setColor(DiscordUtil.ERROR);
            embedBuilder.setTitle("Supplied value is outside the queue range!", null);
            DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        }
        return;
    }
    StringBuilder stringBuilder = new StringBuilder();
    int count = 1;
    for (Iterator<Audio> iterator = DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().iterator(); iterator.hasNext(); ) {
        Audio audio = iterator.next();
        if (count > 10) {
            break;
        }
        if (audio.hasPlayed()) {
            continue;
        }
        stringBuilder.append("`" + count + ". [ " + DiscordUtil.getTimestamp(audio.getAudioTrack().getInfo().length) + " ]` " + audio.getAudioTrack().getInfo().title + "\n");
        count++;
    }
    if (stringBuilder.toString().trim().equals("")) {
        embedBuilder.setTitle("Nothing Queued", null);
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    count = DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().size() - count;
    if (count > 0) {
        embedBuilder.setFooter("and " + count + " more...", null);
    }
    embedBuilder.addField("Currently Queued", stringBuilder.toString(), false);
    DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Audio(io.github.lxgaming.discordbot.entries.Audio)

Example 77 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project DiscordBot by LXGaming.

the class RepeatCommand method execute.

@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
    embedBuilder.setColor(DiscordUtil.DEFAULT);
    if (arguments == null || arguments.isEmpty()) {
        embedBuilder.setColor(DiscordUtil.DEFAULT);
        embedBuilder.addField("Repeat Song", "" + DiscordBot.getInstance().getDiscord().getAudioQueue().isRepeatSong(), true);
        embedBuilder.addField("Repeat Queue", "" + DiscordBot.getInstance().getDiscord().getAudioQueue().isRepeatQueue(), true);
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    if (arguments.get(0).equalsIgnoreCase("song")) {
        if (DiscordBot.getInstance().getDiscord().getAudioPlayer().isPaused() || DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack() == null) {
            embedBuilder.setColor(DiscordUtil.ERROR);
            embedBuilder.setTitle("No song playing!", null);
            DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
            return;
        }
        if (DiscordBot.getInstance().getDiscord().getAudioQueue().isRepeatSong()) {
            DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatSong(false);
            embedBuilder.setColor(DiscordUtil.WARNING);
            embedBuilder.setTitle("No longer repeating current song.", null);
        } else {
            DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatSong(true);
            embedBuilder.setColor(DiscordUtil.SUCCESS);
            embedBuilder.setTitle("Repeating current song.", null);
        }
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    if (arguments.get(0).equalsIgnoreCase("queue")) {
        if (DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue() == null || DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().isEmpty()) {
            embedBuilder.setColor(DiscordUtil.ERROR);
            embedBuilder.setTitle("No song in queue!", null);
            DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
            return;
        }
        if (DiscordBot.getInstance().getDiscord().getAudioQueue().isRepeatQueue()) {
            DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatQueue(false);
            embedBuilder.setColor(DiscordUtil.WARNING);
            embedBuilder.setTitle("No longer repeating current queue.", null);
        } else {
            DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatQueue(false);
            embedBuilder.setColor(DiscordUtil.SUCCESS);
            embedBuilder.setTitle("Repeating current queue.", null);
        }
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 78 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project DiscordBot by LXGaming.

the class ShuffleCommand method execute.

@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
    embedBuilder.setColor(DiscordUtil.DEFAULT);
    if (DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue() == null || DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().size() < 2) {
        embedBuilder.setColor(DiscordUtil.ERROR);
        embedBuilder.setTitle("The current queue is not big enough to shuffle!", null);
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    Collections.shuffle(DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue(), new Random(System.nanoTime()));
    embedBuilder.setColor(DiscordUtil.SUCCESS);
    embedBuilder.setTitle("Current queue shuffled.", null);
    DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Random(java.util.Random)

Example 79 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project DiscordBot by LXGaming.

the class StopCommand method execute.

@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
    embedBuilder.setColor(DiscordUtil.DEFAULT);
    if (DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack() == null) {
        embedBuilder.setColor(DiscordUtil.ERROR);
        embedBuilder.setTitle("Player is not playing anything!", null);
        DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
        return;
    }
    DiscordBot.getInstance().getDiscord().getAudioPlayer().stopTrack();
    embedBuilder.setColor(DiscordUtil.SUCCESS);
    embedBuilder.setTitle("Track stopped.", null);
    DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 80 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.

the class ImageCmds method getImage.

private static EmbedBuilder getImage(int argsCount, String requestType, String url, String rating, String[] messageArray, GuildMessageReceivedEvent event) {
    EmbedBuilder builder = new EmbedBuilder();
    if (!nsfwCheck(event, false, false))
        return builder.setDescription("Cannot send a lewd image in a non-nsfw channel.");
    String json = Utils.wget(url, event);
    try {
        YandereImageData[] imageData = GsonDataManager.GSON_PRETTY.fromJson(json, YandereImageData[].class);
        List<YandereImageData> filter = new ArrayList<>(Arrays.asList(imageData)).stream().filter(data -> rating.equals(data.rating)).collect(Collectors.toList());
        int get;
        try {
            get = requestType.equals("tags") ? argsCount >= 4 ? number : r.nextInt(filter.size()) : argsCount <= 2 ? Integer.parseInt(messageArray[2]) : r.nextInt(filter.size());
        } catch (IndexOutOfBoundsException e) {
            get = r.nextInt(filter.size());
        } catch (IllegalArgumentException e) {
            if (e.getMessage().equals("bound must be positive"))
                return builder.setDescription("No results found.");
            else
                return builder.setDescription("Query not valid.");
        }
        String AUTHOR = filter.get(get).getAuthor();
        String tags = filter.get(get).getTags().stream().collect(Collectors.joining(", "));
        if (!smallRequest) {
            return builder.setAuthor("Found image", filter.get(get).getFile_url(), null).setDescription("Image uploaded by: " + (AUTHOR == null ? "not found" : AUTHOR) + ", with a rating of: **" + nRating.inverseBidiMap().get(filter.get(get).getRating()) + "**").setImage(filter.get(get).getFile_url()).addField("Height", String.valueOf(filter.get(get).getHeight()), true).addField("Width", String.valueOf(filter.get(get).getWidth()), true).addField("Tags", "``" + (tags == null ? "None" : tags) + "``", false).setFooter("If the image doesn't load, click the title.", null);
        }
        return builder.setAuthor("Found image", filter.get(get).getFile_url(), null).setDescription("Image uploaded by: " + (AUTHOR == null ? "not found" : AUTHOR) + ", with a rating of: **" + nRating.inverseBidiMap().get(filter.get(get).getRating()) + "**").setImage(filter.get(get).getFile_url()).addField("Width", String.valueOf(filter.get(get).getHeight()), true).addField("Height", String.valueOf(filter.get(get).getWidth()), true).addField("Tags", "``" + (tags == null ? "None" : tags) + "``", false).setFooter("If the image doesn't load, click the title.", null);
    } catch (Exception ex) {
        if (ex instanceof NullPointerException)
            return builder.setDescription(EmoteReference.ERROR + "Wrong syntax.");
        return builder.setDescription(EmoteReference.ERROR + "There are no images here, just dust.");
    }
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) Arrays(java.util.Arrays) YandereImageData(net.kodehawa.mantarobot.commands.image.YandereImageData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Utils(net.kodehawa.mantarobot.utils.Utils) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) Module(net.kodehawa.mantarobot.modules.Module) Wallpaper(net.kodehawa.lib.imageboards.konachan.main.entities.Wallpaper) Random(java.util.Random) ArrayList(java.util.ArrayList) Unirest(com.mashape.unirest.http.Unirest) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) OptsCmd.registerOption(net.kodehawa.mantarobot.commands.OptsCmd.registerOption) URLCache(net.kodehawa.mantarobot.utils.cache.URLCache) JSONObject(org.json.JSONObject) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) BidiMap(org.apache.commons.collections4.BidiMap) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) DualHashBidiMap(org.apache.commons.collections4.bidimap.DualHashBidiMap) Category(net.kodehawa.mantarobot.modules.commands.base.Category) GsonDataManager(net.kodehawa.mantarobot.utils.data.GsonDataManager) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) CollectionUtils(br.com.brjdevs.java.utils.collections.CollectionUtils) Rule34(net.kodehawa.lib.imageboards.rule34.Rule34) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) net.kodehawa.lib.imageboards.e621.e621(net.kodehawa.lib.imageboards.e621.e621) Konachan(net.kodehawa.lib.imageboards.konachan.Konachan) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) YandereImageData(net.kodehawa.mantarobot.commands.image.YandereImageData) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)128 Message (net.dv8tion.jda.core.entities.Message)26 List (java.util.List)24 ArrayList (java.util.ArrayList)22 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)22 User (net.dv8tion.jda.core.entities.User)20 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)20 Collectors (java.util.stream.Collectors)19 MantaroData (net.kodehawa.mantarobot.data.MantaroData)19 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)17 Utils (net.kodehawa.mantarobot.utils.Utils)17 TimeUnit (java.util.concurrent.TimeUnit)16 Permission (net.dv8tion.jda.core.Permission)15 Subscribe (com.google.common.eventbus.Subscribe)13 Color (java.awt.Color)13 Guild (net.dv8tion.jda.core.entities.Guild)12 TextChannel (net.dv8tion.jda.core.entities.TextChannel)12 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)12 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)12 java.awt (java.awt)11