Search in sources :

Example 21 with Member

use of net.dv8tion.jda.core.entities.Member in project RoleBotPlus by LeshDev.

the class SupportEvent method onPrivateMessageReceived.

public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) {
    Message msg = e.getMessage();
    EmbedBuilder eB = new EmbedBuilder();
    Role mods = e.getJDA().getGuildById(316125040917872660L).getRoleById(324869706148216832L);
    Role admin = e.getJDA().getGuildById(316125040917872660L).getRoleById(316125448184791040L);
    List<Member> helpUser = e.getJDA().getGuildById(316125040917872660L).getMembersWithRoles(mods, admin);
    String userDisc;
    if (msg.getContentRaw().startsWith(lib.prefix + "support start")) {
        userDisc = e.getAuthor().getDiscriminator();
    }
}
Also used : Role(net.dv8tion.jda.core.entities.Role) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Message(net.dv8tion.jda.core.entities.Message) Member(net.dv8tion.jda.core.entities.Member)

Example 22 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class ArgumentUtil method fuzzyMemberSearch.

public static List<Member> fuzzyMemberSearch(Guild guild, String term, boolean includeBots) {
    ArrayList<Member> list = new ArrayList<>();
    term = term.toLowerCase();
    for (Member mem : guild.getMembers()) {
        if ((mem.getUser().getName().toLowerCase() + "#" + mem.getUser().getDiscriminator()).contains(term) || (mem.getEffectiveName().toLowerCase().contains(term)) || term.contains(mem.getUser().getId())) {
            if (!includeBots && mem.getUser().isBot())
                continue;
            list.add(mem);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Member(net.dv8tion.jda.core.entities.Member)

Example 23 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class GuildPlayer method queue.

public void queue(AudioTrackContext atc) {
    Guild guild = getGuild();
    if (guild != null) {
        Member member = guild.getMemberById(atc.getUserId());
        if (member != null) {
            joinChannel(member);
        }
    }
    audioTrackProvider.add(atc);
    play();
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 24 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class MusicPersistenceHandler method reloadPlaylists.

private void reloadPlaylists(JDA jda) {
    File dir = new File("music_persistence");
    if (appConfig.isMusicDistribution()) {
        log.warn("Music persistence loading is disabled on the MUSIC distribution! Use PATRON or DEVELOPMENT instead" + "How did this call end up in here anyways?");
        return;
    }
    log.info("Began reloading playlists for shard {}", jda.getShardInfo().getShardId());
    if (!dir.exists()) {
        log.info("No music persistence directory found.");
        return;
    }
    File[] files = dir.listFiles();
    if (files == null || files.length == 0) {
        log.info("No files present in music persistence directory");
        return;
    }
    for (File file : files) {
        try {
            Guild guild = jda.getGuildById(file.getName());
            if (guild == null) {
                // only load guilds that are part of this shard
                continue;
            }
            JSONObject data = new JSONObject(FileUtils.readFileToString(file, Charset.forName("UTF-8")));
            boolean isPaused = data.getBoolean("isPaused");
            final JSONArray sources = data.getJSONArray("sources");
            @Nullable VoiceChannel vc = jda.getVoiceChannelById(data.getString("vc"));
            @Nullable TextChannel tc = jda.getTextChannelById(data.getString("tc"));
            float volume = Float.parseFloat(data.getString("volume"));
            RepeatMode repeatMode = data.getEnum(RepeatMode.class, "repeatMode");
            boolean shuffle = data.getBoolean("shuffle");
            GuildPlayer player = playerRegistry.getOrCreate(guild);
            if (tc != null) {
                musicTextChannelProvider.setMusicChannel(tc);
            }
            if (appConfig.getDistribution().volumeSupported()) {
                player.setVolume(volume);
            }
            player.setRepeatMode(repeatMode);
            player.setShuffle(shuffle);
            final boolean[] isFirst = { true };
            List<AudioTrackContext> tracks = new ArrayList<>();
            sources.forEach((Object t) -> {
                JSONObject json = (JSONObject) t;
                byte[] message = Base64.decodeBase64(json.getString("message"));
                Member member = guild.getMemberById(json.getLong("user"));
                if (member == null)
                    // member left the guild meanwhile, set ourselves as the one who added the song
                    member = guild.getSelfMember();
                AudioTrack at;
                try {
                    ByteArrayInputStream bais = new ByteArrayInputStream(message);
                    at = audioPlayerManager.decodeTrack(new MessageInput(bais)).decodedTrack;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (at == null) {
                    log.error("Loaded track that was null! Skipping...");
                    return;
                }
                // Handle split tracks
                AudioTrackContext atc;
                JSONObject split = json.optJSONObject("split");
                if (split != null) {
                    atc = new SplitAudioTrackContext(jdaEntityProvider, at, member, split.getLong("startPos"), split.getLong("endPos"), split.getString("title"));
                    at.setPosition(split.getLong("startPos"));
                    if (isFirst[0]) {
                        isFirst[0] = false;
                        if (data.has("position")) {
                            at.setPosition(split.getLong("startPos") + data.getLong("position"));
                        }
                    }
                } else {
                    atc = new AudioTrackContext(jdaEntityProvider, at, member);
                    if (isFirst[0]) {
                        isFirst[0] = false;
                        if (data.has("position")) {
                            at.setPosition(data.getLong("position"));
                        }
                    }
                }
                tracks.add(atc);
            });
            player.loadAll(tracks);
            if (!isPaused) {
                if (vc != null) {
                    try {
                        player.joinChannel(vc);
                        player.play();
                    } catch (Exception ignored) {
                    }
                }
                if (tc != null) {
                    CentralMessaging.message(tc, MessageFormat.format(I18n.get(guild).getString("reloadSuccess"), sources.length())).send(null);
                }
            }
        } catch (Exception ex) {
            log.error("Error when loading persistence file", ex);
        }
        boolean deleted = file.delete();
        log.info(deleted ? "Deleted persistence file: " + file : "Failed to delete persistence file: " + file);
    }
}
Also used : ArrayList(java.util.ArrayList) MessageInput(com.sedmelluq.discord.lavaplayer.tools.io.MessageInput) Guild(net.dv8tion.jda.core.entities.Guild) SplitAudioTrackContext(fredboat.audio.queue.SplitAudioTrackContext) TextChannel(net.dv8tion.jda.core.entities.TextChannel) RepeatMode(fredboat.definitions.RepeatMode) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Member(net.dv8tion.jda.core.entities.Member) JSONArray(org.json.JSONArray) IOException(java.io.IOException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) GuildPlayer(fredboat.audio.player.GuildPlayer) ByteArrayInputStream(java.io.ByteArrayInputStream) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) SplitAudioTrackContext(fredboat.audio.queue.SplitAudioTrackContext) JSONObject(org.json.JSONObject) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 25 with Member

use of net.dv8tion.jda.core.entities.Member in project FredBoat by Frederikam.

the class VoteSkipCommand method displayVoteList.

private void displayVoteList(CommandContext context, GuildPlayer player) {
    Set<Long> voters = guildSkipVotes.get(context.guild.getIdLong());
    if (voters == null || voters.isEmpty()) {
        context.reply(context.i18n("voteSkipEmbedNoVotes"));
        return;
    }
    // split them up into two fields which makes the info look nicely condensed in the client
    int i = 0;
    StringBuilder field1 = new StringBuilder();
    StringBuilder field2 = new StringBuilder();
    for (Long userId : voters) {
        StringBuilder field = field1;
        if (i++ % 2 == 1)
            field = field2;
        Member member = context.getGuild().getMemberById(userId);
        if (member != null) {
            field.append("| ").append(TextUtils.escapeAndDefuse(member.getEffectiveName())).append("\n");
        }
    }
    EmbedBuilder embed = CentralMessaging.getColoredEmbedBuilder();
    embed.addField("", field1.toString(), true);
    embed.addField("", field2.toString(), true);
    embed.setTitle(context.i18nFormat("voteSkipEmbedVoters", voters.size(), player.getHumanUsersInCurrentVC().size()));
    context.reply(embed.build());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Member(net.dv8tion.jda.core.entities.Member)

Aggregations

Member (net.dv8tion.jda.core.entities.Member)69 Message (net.dv8tion.jda.core.entities.Message)23 Guild (net.dv8tion.jda.core.entities.Guild)22 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)19 User (net.dv8tion.jda.core.entities.User)19 TextChannel (net.dv8tion.jda.core.entities.TextChannel)18 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)10 Permission (net.dv8tion.jda.core.Permission)9 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)9 Role (net.dv8tion.jda.core.entities.Role)8 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Collectors (java.util.stream.Collectors)7 FlareBot (stream.flarebot.flarebot.FlareBot)6 Permission (stream.flarebot.flarebot.permissions.Permission)6 Track (com.arsenarsen.lavaplayerbridge.player.Track)5 GuildPlayer (fredboat.audio.player.GuildPlayer)5 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)5