Java Code Examples for net.dv8tion.jda.core.entities.User#getIdLong()

The following examples show how to use net.dv8tion.jda.core.entities.User#getIdLong() . 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: SongCommand.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PlayerManager manager = FlareBot.instance().getMusicManager();
    if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
        Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
        EmbedBuilder eb = MessageUtils.getEmbed(sender)
                .addField("Current Song", getLink(track), false)
                .setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg");
        if (track.getTrack().getInfo().isStream)
            eb.addField("Amount Played", "Issa livestream ;)", false);
        else
            eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true)
                    .addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()),
                            FormatUtils.formatDuration(track.getTrack().getDuration())), false);
        ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);
        buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId())) {
                if (manager.getPlayer(guild.getGuild().getId()).getPaused()) {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).play();
                    }
                } else {
                    if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) {
                        manager.getPlayer(guild.getGuild().getId()).setPaused(true);
                    }
                }
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> {
            if (manager.hasPlayer(guild.getGuildId()) &&
                    getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) {
                manager.getPlayer(guild.getGuildId()).stop();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
            if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) {
                Command cmd = FlareBot.getCommandManager().getCommand("skip", user);
                if (cmd != null)
                    cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user));
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> {
            updateSongMessage(user, message1, message1.getTextChannel());
        }));
        ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup);
    } else {
        channel.sendMessage(MessageUtils.getEmbed(sender)
                .addField("Current song", "**No song playing right now!**", false)
                .build()).queue();
    }
}
 
Example 2
Source File: PaginationUtil.java    From FlareBot with MIT License 4 votes vote down vote up
/**
 * Sends a paged message
 *
 * @param textChannel The channel to send it to
 * @param list        The {@link PaginationList} to use
 * @param page        The starting page
 * @param sender      The member who requested the button
 */
public static void sendPagedMessage(TextChannel textChannel, PaginationList list, int page, User sender, String group) {
    if (page < 0 || page > list.getPages() - 1) {
        MessageUtils.sendErrorMessage("Invalid page: " + (page + 1) + " Total Pages: " + list.getPages(), textChannel);
        return;
    }
    Integer[] pages = new Integer[]{page};
    if (list.getPages() > 1) {
        ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), group);
        buttonGroup.addButton(new ButtonGroup.Button("\u23EE", (ownerID, user, message) -> {
            //Start
            pages[0] = 0;
            message.editMessage(list.getPage(pages[0])).queue();
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23EA", (ownerID, user, message) -> {
            //Prev
            if (pages[0] != 0) {
                pages[0] -= 1;
                message.editMessage(list.getPage(pages[0])).queue();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23E9", (ownerID, user, message) -> {
            //Next
            if (pages[0] + 1 != list.getPages()) {
                pages[0] += 1;
                message.editMessage(list.getPage(pages[0])).queue();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (ownerID, user, message) -> {
            //Last
            pages[0] = list.getPages() - 1;
            message.editMessage(list.getPage(pages[0])).queue();
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u274C", (ownerID, user, message) -> {
            // Delete
            if (user.getIdLong() == ownerID ||
                    message.getGuild().getMember(user).hasPermission(Permission.MANAGE_PERMISSIONS)) {
                message.delete().queue(null, e -> {
                });
            } else {
                MessageUtils.sendErrorMessage("You need to be the sender or have the `Manage Messages` discord permission to do this!", (TextChannel) message.getChannel());
            }
        }));
        ButtonUtil.sendButtonedMessage(textChannel, list.getPage(page), buttonGroup);
    } else {
        textChannel.sendMessage(list.getPage(page)).queue();
    }
}
 
Example 3
Source File: PaginationUtil.java    From FlareBot with MIT License 4 votes vote down vote up
/**
 * Sends an embed paged message the to specified channel.
 * You can build with Embed with {@link PagedEmbedBuilder}.
 *
 * @param pagedEmbed The {@link stream.flarebot.flarebot.util.pagination.PagedEmbedBuilder.PagedEmbed} to use.
 * @param page       The page to start on (0 Indexed).
 * @param channel    The channel to send the paged message to.
 * @param sender     The user who requested the embed
 */
public static void sendEmbedPagedMessage(PagedEmbedBuilder.PagedEmbed pagedEmbed, int page, TextChannel channel, User sender, String group) {
    if (page < 0 || page > pagedEmbed.getPageTotal() - 1) {
        MessageUtils.sendErrorMessage("Invalid page: " + (page + 1) + " Total Pages: " + pagedEmbed.getPageTotal(), channel);
        return;
    }
    if (!pagedEmbed.isSinglePage()) {
        ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), group);
        Integer[] pages = new Integer[]{page};
        buttonGroup.addButton(new ButtonGroup.Button("\u23EE", (ownerID, user, message) -> {
            //Start
            pages[0] = 0;
            message.editMessage(pagedEmbed.getEmbed(pages[0])).queue();
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23EA", (ownerID, user, message) -> {
            //Prev
            if (pages[0] != 0) {
                pages[0] -= 1;
                message.editMessage(pagedEmbed.getEmbed(pages[0])).queue();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23E9", (ownerID, user, message) -> {
            //Next
            if (pages[0] + 1 != pagedEmbed.getPageTotal()) {
                pages[0] += 1;
                message.editMessage(pagedEmbed.getEmbed(pages[0])).queue();
            }
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (ownerID, user, message) -> {
            //Last
            pages[0] = pagedEmbed.getPageTotal() - 1;
            message.editMessage(pagedEmbed.getEmbed(pages[0])).queue();
        }));
        buttonGroup.addButton(new ButtonGroup.Button("\u274C", (ownerID, user, message) -> {
            // Delete
            if (user.getIdLong() == ownerID ||
                    message.getGuild().getMember(user).hasPermission(Permission.MANAGE_PERMISSIONS)) {
                message.delete().queue(null, e -> {
                });
            } else {
                MessageUtils.sendErrorMessage("You need to be the sender or have the `Manage Messages` discord permission to do this!", (TextChannel) message.getChannel());
            }
        }));
        ButtonUtil.sendButtonedMessage(channel, pagedEmbed.getEmbed(page), buttonGroup);
    } else {
        channel.sendMessage(pagedEmbed.getEmbed(page)).queue();
    }
}
 
Example 4
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);
}