Search in sources :

Example 1 with IVoiceChannel

use of sx.blah.discord.handle.obj.IVoiceChannel in project Shadbot by Shadorc.

the class PlayCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        throw new MissingArgumentException();
    }
    IVoiceChannel botVoiceChannel = context.getClient().getOurUser().getVoiceStateForGuild(context.getGuild()).getChannel();
    IVoiceChannel userVoiceChannel = context.getAuthor().getVoiceStateForGuild(context.getGuild()).getChannel();
    if (botVoiceChannel != null && !botVoiceChannel.equals(userVoiceChannel)) {
        throw new IllegalCmdArgumentException(String.format("I'm currently playing music in voice channel %s" + ", join me before using this command.", botVoiceChannel.mention()));
    }
    if (userVoiceChannel == null) {
        throw new IllegalCmdArgumentException("Join a voice channel before using this command.");
    }
    if (botVoiceChannel == null && !BotUtils.hasPermissions(userVoiceChannel, Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK)) {
        BotUtils.sendMessage(TextUtils.missingPerm(Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK), context.getChannel());
        LogUtils.infof("{Guild ID: %d} Shadbot wasn't allowed to connect/speak in a voice channel.", context.getGuild().getLongID());
        return;
    }
    String identifier;
    if (context.getArg().startsWith("soundcloud ")) {
        identifier = AudioLoadResultListener.SC_SEARCH + StringUtils.remove(context.getArg(), "soundcloud ");
    } else if (NetUtils.isValidURL(context.getArg())) {
        identifier = context.getArg();
    } else {
        identifier = AudioLoadResultListener.YT_SEARCH + context.getArg();
    }
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic != null && guildMusic.isWaiting()) {
        if (guildMusic.getDj().equals(context.getAuthor())) {
            throw new IllegalCmdArgumentException(String.format("(**%s**) You're already selecting a music. " + "Enter a number or use `%scancel` to cancel the selection.", context.getAuthorName(), context.getPrefix()));
        }
        if (identifier.startsWith(AudioLoadResultListener.SC_SEARCH) || identifier.startsWith(AudioLoadResultListener.YT_SEARCH)) {
            BotUtils.sendMessage(String.format(Emoji.HOURGLASS + " **%s** is already selecting a music, please wait for him to finish.", guildMusic.getDj().getName()), context.getChannel());
            return;
        }
    }
    if (guildMusic == null) {
        guildMusic = GuildMusicManager.createGuildMusic(context.getGuild());
    }
    if (guildMusic.getScheduler().getPlaylist().size() >= Config.MAX_PLAYLIST_SIZE - 1 && !PremiumManager.isPremium(context.getGuild(), context.getAuthor())) {
        BotUtils.sendMessage(TextUtils.PLAYLIST_LIMIT_REACHED, context.getChannel());
        return;
    }
    guildMusic.setChannel(context.getChannel());
    AudioLoadResultListener resultListener = new AudioLoadResultListener(guildMusic, context.getAuthor(), userVoiceChannel, identifier, context.getCommandName().endsWith("first"));
    GuildMusicManager.PLAYER_MANAGER.loadItemOrdered(guildMusic, identifier, resultListener);
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) AudioLoadResultListener(me.shadorc.shadbot.listener.music.AudioLoadResultListener) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel)

Example 2 with IVoiceChannel

use of sx.blah.discord.handle.obj.IVoiceChannel in project Shadbot by Shadorc.

the class UserVoiceChannelListener method check.

private synchronized void check(IGuild guild) {
    IVoiceChannel botVoiceChannel = guild.getClient().getOurUser().getVoiceStateForGuild(guild).getChannel();
    if (botVoiceChannel == null) {
        return;
    }
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(guild.getLongID());
    if (guildMusic == null) {
        return;
    }
    if (this.isAlone(botVoiceChannel) && !guildMusic.isLeavingScheduled()) {
        BotUtils.sendMessage(Emoji.INFO + " Nobody is listening anymore, music paused. I will leave the voice channel in 1 minute.", guildMusic.getChannel());
        guildMusic.getScheduler().getAudioPlayer().setPaused(true);
        guildMusic.scheduleLeave();
    } else if (!this.isAlone(botVoiceChannel) && guildMusic.isLeavingScheduled()) {
        BotUtils.sendMessage(Emoji.INFO + " Somebody joined me, music resumed.", guildMusic.getChannel());
        guildMusic.getScheduler().getAudioPlayer().setPaused(false);
        guildMusic.cancelLeave();
    }
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel)

Example 3 with IVoiceChannel

use of sx.blah.discord.handle.obj.IVoiceChannel in project BoltBot by DiscordBolt.

the class DisconnectModule method disconnectCommand.

@BotCommand(command = "disconnect", module = "Disconnect Module", description = "Disconnect user(s) from their voice channel.", usage = "Disconnect [User] ", permissions = Permissions.VOICE_MOVE_MEMBERS)
public static void disconnectCommand(CommandContext cc) throws CommandException {
    IUser user = UserUtil.findUser(cc.getMessage(), 12);
    if (user == null)
        throw new CommandArgumentException("The user you specified was unable to be found!");
    if (user.getVoiceStateForGuild(cc.getGuild()).getChannel() == null)
        throw new CommandStateException("The user you specified is not connected to a voice channel!");
    IVoiceChannel temp = cc.getGuild().createVoiceChannel("Disconnect");
    user.moveToVoiceChannel(temp);
    temp.delete();
    cc.getMessage().delete();
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel) BotCommand(com.discordbolt.api.command.BotCommand)

Aggregations

IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)3 GuildMusic (me.shadorc.shadbot.music.GuildMusic)2 BotCommand (com.discordbolt.api.command.BotCommand)1 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)1 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)1 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)1 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)1 AudioLoadResultListener (me.shadorc.shadbot.listener.music.AudioLoadResultListener)1 IUser (sx.blah.discord.handle.obj.IUser)1