Search in sources :

Example 26 with Member

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

the class VoteSkipCommand method getSkipPercentage.

private float getSkipPercentage(Guild guild, GuildPlayer player) {
    List<Member> vcMembers = player.getHumanUsersInCurrentVC();
    int votes = 0;
    for (Member vcMember : vcMembers) {
        if (hasVoted(guild, vcMember)) {
            votes++;
        }
    }
    float percentage = votes * 1.0f / vcMembers.size();
    if (Float.isNaN(percentage)) {
        return 0f;
    } else {
        return percentage;
    }
}
Also used : Member(net.dv8tion.jda.core.entities.Member)

Example 27 with Member

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

the class HistoryCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isHistoryQueueEmpty()) {
        context.reply(context.i18n("npNotInHistory"));
        return;
    }
    int page = 1;
    if (context.hasArguments()) {
        try {
            page = Integer.valueOf(context.args[0]);
        } catch (NumberFormatException e) {
            page = 1;
        }
    }
    int tracksCount = player.getTrackCountInHistory();
    int maxPages = (int) Math.ceil(((double) tracksCount - 1d)) / PAGE_SIZE + 1;
    page = Math.max(page, 1);
    page = Math.min(page, maxPages);
    int i = (page - 1) * PAGE_SIZE;
    int listEnd = (page - 1) * PAGE_SIZE + PAGE_SIZE;
    listEnd = Math.min(listEnd, tracksCount);
    int numberLength = Integer.toString(listEnd).length();
    List<AudioTrackContext> sublist = player.getTracksInHistory(i, listEnd);
    MessageBuilder mb = CentralMessaging.getClearThreadLocalMessageBuilder().append(context.i18n("listShowHistory")).append("\n").append(MessageFormat.format(context.i18n("listPageNum"), page, maxPages)).append("\n").append("\n");
    for (AudioTrackContext atc : sublist) {
        String status = " ";
        Member member = atc.getMember();
        String username = member != null ? member.getEffectiveName() : context.guild.getSelfMember().getEffectiveName();
        mb.append("[" + TextUtils.forceNDigits(i + 1, numberLength) + "]", MessageBuilder.Formatting.BLOCK).append(status).append(context.i18nFormat("listAddedBy", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.escapeAndDefuse(username), TextUtils.formatTime(atc.getEffectiveDuration()))).append("\n");
        if (i == listEnd) {
            break;
        }
        i++;
    }
    context.reply(mb.build());
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) Member(net.dv8tion.jda.core.entities.Member)

Example 28 with Member

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

the class ListCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.reply(context.i18n("npNotPlaying"));
        return;
    }
    MessageBuilder mb = CentralMessaging.getClearThreadLocalMessageBuilder();
    int page = 1;
    if (context.hasArguments()) {
        try {
            page = Integer.valueOf(context.args[0]);
        } catch (NumberFormatException e) {
            page = 1;
        }
    }
    int tracksCount = player.getTrackCount();
    int maxPages = (int) Math.ceil(((double) tracksCount - 1d)) / PAGE_SIZE + 1;
    page = Math.max(page, 1);
    page = Math.min(page, maxPages);
    int i = (page - 1) * PAGE_SIZE;
    int listEnd = (page - 1) * PAGE_SIZE + PAGE_SIZE;
    listEnd = Math.min(listEnd, tracksCount);
    int numberLength = Integer.toString(listEnd).length();
    List<AudioTrackContext> sublist = player.getTracksInRange(i, listEnd);
    if (player.isShuffle()) {
        mb.append(context.i18n("listShowShuffled"));
        mb.append("\n");
        if (player.getRepeatMode() == RepeatMode.OFF)
            mb.append("\n");
    }
    if (player.getRepeatMode() == RepeatMode.SINGLE) {
        mb.append(context.i18n("listShowRepeatSingle"));
        mb.append("\n");
    } else if (player.getRepeatMode() == RepeatMode.ALL) {
        mb.append(context.i18n("listShowRepeatAll"));
        mb.append("\n");
    }
    mb.append(context.i18nFormat("listPageNum", page, maxPages));
    mb.append("\n");
    mb.append("\n");
    for (AudioTrackContext atc : sublist) {
        String status = " ";
        if (i == 0) {
            // Escaped play and pause emojis
            status = player.isPlaying() ? " \\▶" : " \\\u23F8";
        }
        Member member = atc.getMember();
        String username = member != null ? member.getEffectiveName() : context.guild.getSelfMember().getEffectiveName();
        mb.append("[" + TextUtils.forceNDigits(i + 1, numberLength) + "]", MessageBuilder.Formatting.BLOCK).append(status).append(context.i18nFormat("listAddedBy", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.escapeAndDefuse(username), TextUtils.formatTime(atc.getEffectiveDuration()))).append("\n");
        if (i == listEnd) {
            break;
        }
        i++;
    }
    // Now add a timestamp for how much is remaining
    String timestamp = TextUtils.formatTime(player.getTotalRemainingMusicTimeMillis());
    long streams = player.getStreamsCount();
    long numTracks = tracksCount - streams;
    String desc;
    if (numTracks == 0) {
        // We are only listening to streams
        desc = context.i18nFormat(streams == 1 ? "listStreamsOnlySingle" : "listStreamsOnlyMultiple", streams, streams == 1 ? context.i18n("streamSingular") : context.i18n("streamPlural"));
    } else {
        desc = context.i18nFormat(numTracks == 1 ? "listStreamsOrTracksSingle" : "listStreamsOrTracksMultiple", numTracks, numTracks == 1 ? context.i18n("trackSingular") : context.i18n("trackPlural"), timestamp, streams == 0 ? "" : context.i18nFormat("listAsWellAsLiveStreams", streams, streams == 1 ? context.i18n("streamSingular") : context.i18n("streamPlural")));
    }
    mb.append("\n").append(desc);
    context.reply(mb.build());
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) Member(net.dv8tion.jda.core.entities.Member)

Example 29 with Member

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

the class NowplayingCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player != null && player.isPlaying()) {
        AudioTrackContext atc = player.getPlayingTrack();
        AudioTrack at = atc.getTrack();
        EmbedBuilder builder;
        if (at instanceof YoutubeAudioTrack) {
            builder = getYoutubeEmbed(atc, player, (YoutubeAudioTrack) at);
        } else if (at instanceof SoundCloudAudioTrack) {
            builder = getSoundcloudEmbed(atc, player, (SoundCloudAudioTrack) at);
        } else if (at instanceof HttpAudioTrack && at.getIdentifier().contains("gensokyoradio.net")) {
            // Special handling for GR
            builder = getGensokyoRadioEmbed(context);
        } else if (at instanceof HttpAudioTrack) {
            builder = getHttpEmbed(atc, player, (HttpAudioTrack) at);
        } else if (at instanceof BandcampAudioTrack) {
            builder = getBandcampResponse(atc, player, (BandcampAudioTrack) at);
        } else if (at instanceof TwitchStreamAudioTrack) {
            builder = getTwitchEmbed(atc, (TwitchStreamAudioTrack) at);
        } else if (at instanceof BeamAudioTrack) {
            builder = getBeamEmbed(atc, (BeamAudioTrack) at);
        } else {
            builder = getDefaultEmbed(atc, player, at);
        }
        Member requester = atc.getMember() != null ? atc.getMember() : context.guild.getSelfMember();
        builder = CentralMessaging.addNpFooter(builder, requester);
        context.reply(builder.build());
    } else {
        context.reply(context.i18n("npNotPlaying"));
    }
}
Also used : TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) Member(net.dv8tion.jda.core.entities.Member)

Example 30 with Member

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

the class HardbanCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    Guild guild = context.guild;
    // Ensure we have a search term
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    // was there a target provided?
    Member target = ArgumentUtil.checkSingleFuzzyMemberSearchResult(context, context.args[0]);
    if (target == null)
        return;
    // are we allowed to do that?
    if (!checkHardBanAuthorization(context, target))
        return;
    // putting together a reason
    String plainReason = DiscordUtil.getReasonForModAction(context);
    String auditLogReason = DiscordUtil.formatReasonForAuditLog(plainReason, context.invoker);
    // putting together the action
    RestAction<Void> modAction = guild.getController().ban(target, 7, auditLogReason);
    // on success
    String successOutput = context.i18nFormat("hardbanSuccess", TextUtils.escapeAndDefuse(target.getUser().getName()), target.getUser().getDiscriminator(), target.getUser().getId()) + "\n" + plainReason;
    Consumer<Void> onSuccess = aVoid -> {
        Metrics.successfulRestActions.labels("ban").inc();
        context.replyWithName(successOutput);
    };
    // on fail
    String failOutput = context.i18nFormat("modBanFail", target.getUser());
    Consumer<Throwable> onFail = t -> {
        CentralMessaging.getJdaRestActionFailureHandler(String.format("Failed to ban user %s in guild %s", target.getUser().getId(), guild.getId())).accept(t);
        context.replyWithName(failOutput);
    };
    // issue the mod action
    modAction.queue(onSuccess, onFail);
}
Also used : ArgumentUtil(fredboat.util.ArgumentUtil) CentralMessaging(fredboat.messaging.CentralMessaging) Logger(org.slf4j.Logger) Member(net.dv8tion.jda.core.entities.Member) Command(fredboat.commandmeta.abs.Command) LoggerFactory(org.slf4j.LoggerFactory) CommandContext(fredboat.commandmeta.abs.CommandContext) TextUtils(fredboat.util.TextUtils) IModerationCommand(fredboat.commandmeta.abs.IModerationCommand) RestAction(net.dv8tion.jda.core.requests.RestAction) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) Permission(net.dv8tion.jda.core.Permission) Context(fredboat.messaging.internal.Context) DiscordUtil(fredboat.util.DiscordUtil) HelpCommand(fredboat.command.info.HelpCommand) Metrics(fredboat.feature.metrics.Metrics) Nonnull(javax.annotation.Nonnull) Guild(net.dv8tion.jda.core.entities.Guild) 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