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