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;
}
}
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());
}
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());
}
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"));
}
}
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);
}
Aggregations