Search in sources :

Example 1 with Attachment

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

the class PlayCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (!context.invoker.getVoiceState().inVoiceChannel()) {
        context.reply(context.i18n("playerUserNotInChannel"));
        return;
    }
    if (!playerLimiter.checkLimitResponsive(context, Launcher.getBotController().getPlayerRegistry()))
        return;
    if (!context.msg.getAttachments().isEmpty()) {
        GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
        for (Attachment atc : context.msg.getAttachments()) {
            player.queue(atc.getUrl(), context);
        }
        player.setPause(false);
        return;
    }
    if (!context.hasArguments()) {
        GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
        handleNoArguments(context, player);
        return;
    }
    if (TextUtils.isSplitSelect(context.rawArgs)) {
        SelectCommand.select(context, videoSelectionCache);
        return;
    }
    String url = StringUtils.strip(context.args[0], "<>");
    // Search youtube for videos and let the user select a video
    if (!url.startsWith("http") && !url.startsWith(FILE_PREFIX)) {
        searchForVideos(context);
        return;
    }
    if (url.startsWith(FILE_PREFIX)) {
        // LocalAudioSourceManager does not manage this itself
        url = url.replaceFirst(FILE_PREFIX, "");
    }
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
    player.queue(url, context);
    player.setPause(false);
    context.deleteMessage();
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) Attachment(net.dv8tion.jda.core.entities.Message.Attachment)

Example 2 with Attachment

use of net.dv8tion.jda.core.entities.Message.Attachment 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);
}
Also used : MessagingException(fredboat.commandmeta.MessagingException) Attachment(net.dv8tion.jda.core.entities.Message.Attachment) URISyntaxException(java.net.URISyntaxException) Icon(net.dv8tion.jda.core.entities.Icon) URI(java.net.URI)

Aggregations

Attachment (net.dv8tion.jda.core.entities.Message.Attachment)2 GuildPlayer (fredboat.audio.player.GuildPlayer)1 MessagingException (fredboat.commandmeta.MessagingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Icon (net.dv8tion.jda.core.entities.Icon)1