Java Code Examples for net.dv8tion.jda.core.EmbedBuilder#setColor()

The following examples show how to use net.dv8tion.jda.core.EmbedBuilder#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StopCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: PagedEmbedBuilder.java    From FlareBot with MIT License 6 votes vote down vote up
/**
 * Gets the {@link MessageEmbed} for a specified page.
 *
 * @param page The page to get an embed.
 * @return the {@link MessageEmbed} page.
 */
public MessageEmbed getEmbed(int page) {
    EmbedBuilder pageEmbed = new EmbedBuilder().setColor(ColorUtils.FLAREBOT_BLUE);
    if (title != null)
        pageEmbed.setTitle(title);
    if(useGroups) {
        int start = groupsPerPage * (page);
        int end = Math.min(start + groupsPerPage, groupTotal);
        int num = start;
        List<PaginationList<T>.PageGroup> groups = list.getGroups().subList(start, end);
        for (PaginationList.PageGroup group : groups) {
            pageEmbed.addField(groupPrefix + num, group.getGroupAsString(), false);
            num++;
        }
    } else {
        pageEmbed.setDescription((hasCodeBlock ? "```" + codeBlock + "\n" : "") + list.getPage(page) + (hasCodeBlock ? "\n```" : ""));
    }
    if (pageCounts) {
        pageEmbed.addField("Page", String.valueOf(page + 1), true);
        pageEmbed.addField("Total Pages", String.valueOf(pageTotal), true);
    }
    pageEmbed.setColor(color);
    return pageEmbed.build();
}
 
Example 3
Source File: MessageUtils.java    From FlareBot with MIT License 6 votes vote down vote up
public static void sendMessage(MessageType type, EmbedBuilder builder, TextChannel channel, long autoDeleteDelay) {
    if (builder.build().getColor() == null)
        builder.setColor(type.getColor());
    if (type == MessageType.ERROR) {
        if (flareHeart == null)
            flareHeart = Getters.getEmoteById(386550693294768129L);
        builder.setDescription(builder.build().getDescription() + "\n\nIf you need more support join our " +
                "[Support Server](" + Constants.INVITE_URL + ")! Our staff can support on any issue you may have! "
                + (flareHeart == null ? "<3" : flareHeart.getAsMention()));
    }

    if (type != MessageType.WARNING && type != MessageType.ERROR && builder.getFields().isEmpty()) {
        Optional<String> globalMsg = getGlobalMessage();
        if ((!lastGlobalMsg.containsKey(channel.getIdLong())
                || System.currentTimeMillis() - lastGlobalMsg.get(channel.getIdLong()) >= GLOBAL_MSG_DELAY)
                && globalMsg.isPresent()) {
            lastGlobalMsg.put(channel.getIdLong(), System.currentTimeMillis());

            builder.setDescription(builder.build().getDescription() + "\n\n" + globalMsg.get());
        }
    }
    if (autoDeleteDelay > 0)
        sendAutoDeletedMessage(builder.build(), autoDeleteDelay, channel);
    else
        sendMessage(builder.build(), channel);
}
 
Example 4
Source File: AudioPlayerLoadResultHandler.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
	for (Iterator<AudioTrack> iterator = audioPlaylist.getTracks().iterator(); iterator.hasNext();) {
		AudioTrack audioTrack = iterator.next();
		if (audioTrack == null) {
			continue;
		}
		
		Audio audio = new Audio(getTextChannel(), getMember(), audioTrack);
		DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().add(audio);
		if (DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack() == null) {
			DiscordBot.getInstance().getDiscord().getAudioQueue().playNext();
		} else {
			LogHelper.debug("'" + audio.getAudioTrack().getInfo().title + "' Has been added to the queue.");
		}
		audio = null;
	}
	LogHelper.debug(audioPlaylist.getTracks().size() + " Songs have been added to the queue.");
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.SUCCESS);
	embedBuilder.setTitle(audioPlaylist.getTracks().size() + " Songs have been added to the queue.", null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example 5
Source File: VolumeCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@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()) {
		try {
			int volume = Integer.parseInt(arguments.get(0));
			if (volume > 100 || volume < 0) {
				volume = DiscordBot.getInstance().getDiscord().getAudioPlayer().getVolume();
			}
			
			DiscordBot.getInstance().getDiscord().getAudioPlayer().setVolume(volume);
			embedBuilder.setColor(DiscordUtil.SUCCESS);
		} catch (NumberFormatException ex) {
			embedBuilder.setColor(DiscordUtil.ERROR);
			embedBuilder.setTitle("Invalid volume!", null);
			DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
			return;
		}
	}
	
	embedBuilder.setTitle("Volume - " + DiscordBot.getInstance().getDiscord().getAudioPlayer().getVolume(), null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example 6
Source File: HelpCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@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);
	embedBuilder.setTitle("Commands", null);
	
	for (Iterator<ICommand> iterator = DiscordBot.getInstance().getDiscord().getCommand().getRegisteredCommands().iterator(); iterator.hasNext();) {
		ICommand command = iterator.next();
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("Description - " + command.getDescription() + "\n");
		stringBuilder.append("Usage - " + command.getUsage() + "\n");
		
		if (command.getAliases() != null && !command.getAliases().isEmpty()) {
			stringBuilder.append("Aliases - " + String.join(", ", command.getAliases()));
		}
		embedBuilder.addField(command.getName(), stringBuilder.toString(), false);
	}
	
	embedBuilder.setFooter("<> = Required Argument, [] = Optional Argument", null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example 7
Source File: ServerCommand.java    From DiscordBlueBot with MIT License 6 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) {
    EmbedBuilder builder = new EmbedBuilder();
    builder.setAuthor("Server Info", null, "http://i.imgur.com/880AyL6.png");
    builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor()));
    builder.setThumbnail(event.getGuild().getIconUrl());
    builder.addField("Name", event.getGuild().getName(), true);
    builder.addBlankField(true);
    builder.addField("Owner", event.getGuild().getOwner().getUser().getName() + "#" + event.getGuild().getOwner().getUser().getDiscriminator() , true);
    builder.addField("Server ID", event.getGuild().getId(), true);
    builder.addField("Region", event.getGuild().getRegion().name(), true);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a");
    builder.addField("Creation Date", event.getGuild().getCreationTime().format(formatter), true);
    builder.addField("Total Members", String.valueOf(event.getGuild().getMembers().size()), true);
    int online = 0;
    for(Member member : event.getGuild().getMembers()) {
        if(!member.getOnlineStatus().equals(OnlineStatus.OFFLINE)) {
            ++online;
        }
    }
    builder.addField("Online Members", String.valueOf(online), true);

    event.getTextChannel().sendMessage(builder.build()).queue();
}
 
Example 8
Source File: QuickPollCommand.java    From DiscordBlueBot with MIT License 6 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) {
    String query = "";
    for (String arg : args) {
        query += arg + " ";
    }
    EmbedBuilder builder = new EmbedBuilder();
    builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor()));
    builder.setAuthor(event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " created a poll", null, event.getAuthor().getAvatarUrl());
    builder.addField("", ":grey_question: Question : " + "**" + query + "**", false);
    builder.setFooter("Vote by adding a reaction below !", null);

    event.getMessage().delete().queue();
    event.getTextChannel().sendMessage(builder.build()).queue();

    //Now retrieves the last message from BlueBot to add reactions
    List<Message> history = event.getTextChannel().getHistory().retrievePast(10).complete(); //arbitrary ammount
    for (Message msg : history) {
        if(msg.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
            msg.addReaction("\uD83D\uDC4D").queue();
            msg.addReaction("\ud83d\udc4e").queue();
            msg.addReaction("\uD83E\uDD37").queue();
            break;
        }
    }
}
 
Example 9
Source File: DonateCommand.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    EmbedBuilder builder = MessageUtils.getEmbed(sender);
    builder.setColor(Color.CYAN);
    builder.setDescription("Thank for you taking the time to see how you can donate to the project! This project relies heavily upon user donations so every little helps! \uD83D\uDE0A");
    builder.addField("Patreon", "The most common way to donate is through our [Patreon page](https://www.patreon.com/flarebot)! Through here you can donate the amount you want and also get rewarded for it!", false);
    builder.addField("PayPal", "If you cannot donate through Patreon or don't like the idea of a monthly subscription then this option is for you! Simply join our [support server](" + Constants.INVITE_URL + ") and our amazing staff will assist you in doing this!\n\nShould you want to donate anonymously or you don't want to receive a reward, you can simply send money to `[email protected]` via PayPal to donate!", false);
    channel.sendMessage(builder.build()).queue();
}
 
Example 10
Source File: MessageUtils.java    From FlareBot with MIT License 5 votes vote down vote up
public static EmbedBuilder getEmbed() {
    if (cachedJDA == null || cachedJDA.getStatus() != JDA.Status.CONNECTED)
        cachedJDA = flareBot.getClient();

    EmbedBuilder defaultEmbed = new EmbedBuilder().setColor(ColorUtils.FLAREBOT_BLUE);

    // We really need to PR getAuthor and things into EmbedBuilder.
    if (cachedJDA != null) {
        defaultEmbed.setAuthor("FlareBot", "https://flarebot.stream", cachedJDA.getSelfUser().getEffectiveAvatarUrl());
    }

    return defaultEmbed.setColor(ColorUtils.FLAREBOT_BLUE);
}
 
Example 11
Source File: JoinCommand.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@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.ERROR);
		embedBuilder.setTitle("Invalid arguments!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	List<VoiceChannel> voiceChannels = member.getGuild().getVoiceChannelsByName(arguments.get(0), false);
	if (voiceChannels.size() < 1) {
		embedBuilder.setColor(DiscordUtil.ERROR);
		embedBuilder.setTitle("Unable to find specified voice channel!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	if (member.getGuild().getAudioManager().getConnectedChannel() != null) {
		member.getGuild().getAudioManager().closeAudioConnection();
	}
	
	try {
		member.getGuild().getAudioManager().openAudioConnection(voiceChannels.get(0));
		embedBuilder.setColor(DiscordUtil.SUCCESS);
		embedBuilder.setTitle("Joined channel '" + voiceChannels.get(0).getName() + "'.", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
	} catch (RuntimeException ex) {
		embedBuilder.setColor(DiscordUtil.ERROR);
		embedBuilder.addField("Cannot join channel '" + voiceChannels.get(0).getName() + "'!", ex.getMessage(), false);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
	}
}
 
Example 12
Source File: AudioQueue.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public void playNext() {
	Audio audio = getNext();
	if (audio == null) {
		DiscordBot.getInstance().getDiscord().getAudioPlayer().playTrack(null);
		return;
	}
	
	DiscordBot.getInstance().getDiscord().getAudioPlayer().playTrack(audio.getAudioTrack());
	
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(audio.getTextChannel().getJDA().getSelfUser().getName(), null, audio.getTextChannel().getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	embedBuilder.addField("Now playing", audio.getAudioTrack().getInfo().title, false);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(audio.getTextChannel(), embedBuilder.build(), true);
}
 
Example 13
Source File: AudioPlayerLoadResultHandler.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@Override
public void loadFailed(FriendlyException exception) {
	LogHelper.error("Failed to load - " + exception.getMessage());
	exception.printStackTrace();
	
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.ERROR);
	embedBuilder.addField("Failed to load", exception.getMessage(), false);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example 14
Source File: EmbedCmd.java    From Selfbot with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(String args, MessageReceivedEvent event) {
    if(args==null || args.isEmpty())
    {
        reply("Embeds:\n"
                + "`{title:`TEXT`|`URL`}` or `{title:`TEXT`}`\n"
                + "`{author:`NAME`|`IMAGE`|`URL`}` or `{author:`NAME`|`IMAGE`}` or `{author:`NAME`}`\n"
                + "`{thumbnail:`IMAGE`}`\n"
                + "`{field:`NAME`|`VALUE`|`true/false`}` or `{field:`NAME`|`VALUE`}` *can include multiple fields\n"
                + "`{image:`IMAGE`}`\n"
                + "`{color:`#HEX`}` or `{color:name}`\n"
                + "`{footer:`TEXT`|`IMAGE`}` or `{footer:`TEXT`}`\n"
                + "`{timestamp:`ISO`}` or `{timestamp}` *current time if nothing included\n"
                + "Any remaining text goes into the description", event);
        return;
    }
    EmbedBuilder builder = new EmbedBuilder();
    if(event.getGuild()!=null)
        builder.setColor(event.getGuild().getSelfMember().getColor());
    parser.put("builder", builder);
    try {
        String descr = parser.parse(args).trim();
        if(!descr.isEmpty())
            builder.setDescription(descr);
        reply(builder.build(), event);
    } catch(Exception e) {
        reply(Constants.FAILURE+" Error: "+e, event);
    }
}
 
Example 15
Source File: ListCmd.java    From Selfbot with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(String args, MessageReceivedEvent event) {
    Collection<String> list = emojis.getEmojiList();
    if(list.isEmpty())
    {
        tempReply("No custom emojis!", event);
        return;
    }
    
    EmbedBuilder builder = new EmbedBuilder();
    if(event.getGuild()!=null)
        builder.setColor(event.getGuild().getSelfMember().getColor());
    builder.setAuthor("Custom Emojis:", null, null);
    
    StringBuilder sbuilder = new StringBuilder();
    for(String ename: list)
    {
        String next = "\n`:"+ename+":` \u27A1 `"+emojis.getEmoji(ename)+"`";
        if(sbuilder.length()+next.length()>1985)
        {
            reply(builder.setDescription(sbuilder.toString().trim()).build(),event);
            builder.setAuthor(null,null,null);
            sbuilder = new StringBuilder();
        }
        sbuilder.append(next);
    }
    
    builder.setDescription(sbuilder.toString().trim());
    reply(builder.build(), event);
}
 
Example 16
Source File: RepeatCommand.java    From DiscordBot with Apache License 2.0 4 votes vote down vote up
@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;
	}
}
 
Example 17
Source File: MultiPollCommand.java    From DiscordBlueBot with MIT License 4 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) {
    String query = "";
    String subject;
    String choicesList = "";
    ArrayList<String> choices = new ArrayList<>();
    Pattern subjectRegex = Pattern.compile("\\((.*?)\\)");
    Pattern choiceRegex = Pattern.compile("\\[(.*?)]");

    for (String arg : args) {
        query += arg + " ";
    }

    Matcher subjectMatcher = subjectRegex.matcher(query);
    Matcher choiceMatcher = choiceRegex.matcher(query);

    while (choiceMatcher.find()) {
        choices.add(choiceMatcher.group(1));
    }

    if (subjectMatcher.find()) {
        subject = subjectMatcher.group(1);
    } else {
        event.getTextChannel().sendMessage("Please provide a poll question/subject.").queue();
        return;
    }

    if(choices.size() < 2 || choices.size() > 10) { //At least 2 options and max 10
        event.getTextChannel().sendMessage("You can only propose from 2 to 10 options.").queue();
        return;
    }

    EmbedBuilder builder = new EmbedBuilder();
    builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor()));
    builder.setAuthor(event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " created a poll", null, event.getAuthor().getAvatarUrl());
    builder.addField("", "Question : " + "**" + subject + "**", true);

    for(int i = 0; i < choices.size(); ++i) {
        if(i == 9) {
            choicesList = choicesList + "\uD83D\uDD1F " + choices.get(i); //Keycap 10 case
            break;
        }
        choicesList = choicesList + (i+1) + "⃣ " + choices.get(i) + "\n"; //damn these emojis made me mad
    }
    builder.addField("", choicesList, false);
    builder.setFooter("Vote by adding a reaction below !", null);

    event.getMessage().delete().queue();
    event.getTextChannel().sendMessage(builder.build()).queue();

    //Now retrieves the last message from BlueBot to add reactions
    List<Message> history = event.getTextChannel().getHistory().retrievePast(10).complete(); //arbitrary ammount
    for (Message msg : history) {
        if(msg.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
            for(int i = 0; i < choices.size(); ++i) {
                if(i == 9) {
                    msg.addReaction("\uD83D\uDD1F").queue(); //Keycap 10 case
                    break;
                }
                msg.addReaction(i+1 + "⃣").queue(); //damn these emojis made me mad
            }
            break;
        }
    }
}
 
Example 18
Source File: VoteUtil.java    From FlareBot with MIT License 4 votes vote down vote up
public static void sendVoteMessage(UUID id, VoteGroup.VoteRunnable voteRunnable, VoteGroup group, long timeout, TextChannel channel, User user, String buttonGroupString, ButtonGroup.Button... optionalButtons) {
    EmbedBuilder votesEmbed = new EmbedBuilder()
            .setDescription("Vote to " + group.getMessageDesc())
            .addField("Yes", "0", true)
            .addField("No", "0", true);
    String messageDesc = group.getMessageDesc();
    votesEmbed.setColor(ColorUtils.FLAREBOT_BLUE);
    group.setVotesEmbed(votesEmbed);
    ButtonGroup buttonGroup = new ButtonGroup(user.getIdLong(), buttonGroupString);

    groupMap.put(id + channel.getGuild().getId(), group);
    runnableMap.put(id + channel.getGuild().getId(), voteRunnable);

    buttonGroup.addButton(new ButtonGroup.Button(355776056092917761L, (owner, user1, message) -> {
        if (group.addVote(VoteGroup.Vote.YES, user1)) {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted yes on " + messageDesc).build(), 2000, channel);
        } else {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
        }
    }));

    buttonGroup.addButton(new ButtonGroup.Button(355776081384570881L, (owner, user1, message) -> {
        if (group.addVote(VoteGroup.Vote.NO, user1)) {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted no on " + messageDesc).build(), 2000, channel);
        } else {
            MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
        }
    }));

    for(ButtonGroup.Button button : optionalButtons) {
        buttonGroup.addButton(button);
    }
    
    Message voteMessage = ButtonUtil.sendReturnedButtonedMessage(channel, votesEmbed.build(), buttonGroup);
    group.setVoteMessage(voteMessage);

    new FlareBotTask("Votes-" + voteMessage.getId()){

        @Override
        public void run() {
            voteRunnable.run(group.won());
            groupMap.remove(group.getMessageDesc() + channel.getGuild().getId());
            runnableMap.remove(group.getMessageDesc() + channel.getGuild().getId());
            channel.deleteMessageById(voteMessage.getId()).queue();
        }

    }.delay(timeout);
}
 
Example 19
Source File: RemoveCommand.java    From DiscordBot with Apache License 2.0 4 votes vote down vote up
@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.ERROR);
		embedBuilder.setTitle("Invalid arguments!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	if (DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue() == null || DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().isEmpty()) {
		embedBuilder.setColor(DiscordUtil.ERROR);
		embedBuilder.setTitle("Queue is empty!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	if (arguments.get(0).equalsIgnoreCase("all")) {
		DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().clear();
		embedBuilder.setColor(DiscordUtil.SUCCESS);
		embedBuilder.setTitle("All songs from queue removed.", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	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().remove(index);
		
		embedBuilder.setColor(DiscordUtil.SUCCESS);
		if (audio != null && audio.getAudioTrack() != null) {
			embedBuilder.setTitle("Removed '" + audio.getAudioTrack().getInfo().title + "'.");
		} else {
			embedBuilder.setTitle("Removed '" + "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;
	}
}
 
Example 20
Source File: ServerInfoCommand.java    From FlareBot with MIT License 4 votes vote down vote up
private void sendGuildInfo(Guild guild, TextChannel channel) {
    EmbedBuilder eb = new EmbedBuilder();
    eb.setTitle(guild.getName());
    eb.setThumbnail(guild.getIconUrl());
    eb.addField("Users", "**Total:** " +
            guild.getMembers().size() + "\n" +
            "\n" +
            "**Online:** " +
            guild.getMembers().stream().filter(member -> !member.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "\n" +
            "\n" +
            "**Owner:** " +
            MessageUtils.getTag(guild.getOwner().getUser()), true);
    String afk = guild.getAfkChannel() == null ? "" :
            "**AFK:**\n" +
                    "Channel: " +
                    guild.getAfkChannel().getName() + "\n" +
                    "\n" +
                    "Timeout: " +
                    FormatUtils.formatTime(guild.getAfkTimeout().getSeconds(), TimeUnit.SECONDS, true, false);
    eb.addField("Channels", "**Text**\n" +
            "Total: " +
            guild.getTextChannels().size() + "\n" +
            "\n" +
            "**Voice**\n" +
            "Total: " +
            guild.getVoiceChannels().size() + "\n" +
            "\n" +
            "Active: " +
            guild.getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getMembers().size() > 0).count() + "\n" +
            "\n" + afk, true);
    eb.addField("Misc info", "**Creation time:** " +
            guild.getCreationTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " UTC\n" +
            "\n" +
            "**Roles:** " +
            guild.getRoles().size() + "\n" +
            "\n" +
            "**Server region:** " +
            guild.getRegion().getName() + "\n" +
            "\n" +
            "**Verification Level:** " +
            GeneralUtils.getVerificationString(guild.getVerificationLevel()), true);
    eb.setFooter("ID: " + guild.getId(), null);
    eb.setColor(Color.CYAN);
    channel.sendMessage(eb.build()).queue();
}