use of fredboat.commandmeta.MessagingException in project FredBoat by Frederikam.
the class ExportCommand method onInvoke.
@Override
public void onInvoke(@Nonnull CommandContext context) {
GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
if (player == null || player.isQueueEmpty()) {
throw new MessagingException(context.i18n("exportEmpty"));
}
String out = player.getRemainingTracks().stream().map(atc -> atc.getTrack().getInfo().uri).collect(Collectors.joining("\n"));
TextUtils.postToPasteService(out).thenApply(pasteUrl -> {
if (pasteUrl.isPresent()) {
String url = pasteUrl.get() + ".fredboat";
return context.i18nFormat("exportPlaylistResulted", url);
} else {
return context.i18n("exportPlaylistFail") + "\n" + context.i18n("tryLater");
}
}).thenAccept(context::reply);
}
use of fredboat.commandmeta.MessagingException in project FredBoat by Frederikam.
the class VolumeCommand method onInvoke.
@Override
public void onInvoke(@Nonnull CommandContext context) {
if (Launcher.getBotController().getAppConfig().getDistribution().volumeSupported()) {
GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
try {
float volume = Float.parseFloat(context.args[0]) / 100;
volume = Math.max(0, Math.min(1.5f, volume));
context.reply(context.i18nFormat("volumeSuccess", Math.floor(player.getVolume() * 100), Math.floor(volume * 100)));
player.setVolume(volume);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException ex) {
throw new MessagingException(context.i18nFormat("volumeSyntax", 100 * PlayerRegistry.DEFAULT_VOLUME, Math.floor(player.getVolume() * 100)));
}
} else {
String out = context.i18n("volumeApology") + "\n<" + BotConstants.DOCS_DONATE_URL + ">";
context.replyImage("https://fred.moe/1vD.png", out, msg -> CentralMessaging.restService.schedule(() -> CentralMessaging.deleteMessage(msg), 2, TimeUnit.MINUTES));
}
}
use of fredboat.commandmeta.MessagingException in project FredBoat by Frederikam.
the class SetAvatarCommand method onInvoke.
@Override
public void onInvoke(@Nonnull CommandContext context) {
URI imageUrl = null;
try {
if (!context.msg.getAttachments().isEmpty()) {
Attachment attachment = context.msg.getAttachments().get(0);
imageUrl = new URI(attachment.getUrl());
} else if (context.hasArguments()) {
imageUrl = AVATARS.containsKey(context.args[0]) ? AVATARS.get(context.args[0]) : new URI(context.args[0]);
}
} catch (URISyntaxException e) {
context.reply("Not a valid link.");
return;
}
if (imageUrl != null && imageUrl.getScheme() != null) {
if (imageUrl.getScheme().equals("branding")) {
// for branding:resource.png URLs
// clear off the 'scheme'
imageUrl = URI.create(imageUrl.getSchemeSpecificPart());
if (!checkRelativeToBrandingDir(imageUrl)) {
throw new MessagingException("url is not relative");
}
imageUrl = BRANDING_DIR.resolve(imageUrl);
}
Icon avatar;
switch(imageUrl.getScheme()) {
case "http":
case "https":
avatar = fetchRemote(imageUrl);
break;
case "file":
avatar = fetchFile(imageUrl);
break;
default:
throw new MessagingException("Not a readable image");
}
setBotAvatar(context, avatar);
return;
}
// if not handled it's not a proper invocation
HelpCommand.sendFormattedCommandHelp(context);
}
use of fredboat.commandmeta.MessagingException in project FredBoat by Frederikam.
the class GuildPlayer method joinChannel.
public void joinChannel(VoiceChannel targetChannel) throws MessagingException {
if (targetChannel == null) {
throw new MessagingException(I18n.get(getGuild()).getString("playerUserNotInChannel"));
}
if (targetChannel.equals(getCurrentVoiceChannel())) {
// already connected to the channel
return;
}
Guild guild = targetChannel.getGuild();
if (!guild.getSelfMember().hasPermission(targetChannel, Permission.VOICE_CONNECT) && !targetChannel.getMembers().contains(guild.getSelfMember())) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinConnectDenied"));
}
if (!guild.getSelfMember().hasPermission(targetChannel, Permission.VOICE_SPEAK)) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinSpeakDenied"));
}
if (targetChannel.getUserLimit() > 0 && targetChannel.getUserLimit() <= targetChannel.getMembers().size() && !guild.getSelfMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) {
throw new MessagingException(String.format("The channel you want me to join is full!" + // todo i18n
" Please free up some space, or give me the permission to **%s** to bypass the limit.", Permission.VOICE_MOVE_OTHERS.getName()));
}
try {
audioConnectionFacade.openConnection(targetChannel, this);
log.info("Connected to voice channel " + targetChannel);
} catch (Exception e) {
log.error("Failed to join voice channel {}", targetChannel, e);
}
}
Aggregations