use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class AudioCmdUtils method embedForQueue.
public static void embedForQueue(int page, GuildMessageReceivedEvent event, GuildMusicManager musicManager) {
String toSend = AudioUtils.getQueueList(musicManager.getTrackScheduler().getQueue());
Guild guild = event.getGuild();
if (toSend.isEmpty()) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you queue some songs?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
return;
}
String[] lines = NEWLINE_PATTERN.split(toSend);
if (!guild.getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION)) {
String line = null;
StringBuilder sb = new StringBuilder();
int total;
{
int t = 0;
int c = 0;
for (String s : lines) {
if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
t++;
c = 0;
}
c += s.length() + 1;
}
if (c > 0)
t++;
total = t;
}
int current = 0;
for (String s : lines) {
int l = s.length() + 1;
if (l > MessageEmbed.TEXT_MAX_LENGTH)
throw new IllegalArgumentException("Length for one of the pages is greater than the maximum");
if (sb.length() + l > MessageEmbed.TEXT_MAX_LENGTH) {
current++;
if (current == page) {
line = sb.toString();
break;
}
sb = new StringBuilder();
}
sb.append(s).append('\n');
}
if (sb.length() > 0 && current + 1 == page) {
line = sb.toString();
}
if (line == null || page > total) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you go back some pages?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
} else {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> Use ~>queue <page> to change pages. Currently in page " + page, guild.getIconUrl());
event.getChannel().sendMessage(builder.setDescription(line).build()).queue();
}
return;
}
DiscordUtils.list(event, 30, false, (p, total) -> {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> React to change pages. Currently in page " + p, guild.getIconUrl());
return builder;
}, lines);
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project c0debaseBot by Biospheere.
the class ReadyListener method onReady.
@Override
public void onReady(ReadyEvent event) {
super.onReady(event);
event.getJDA().getGuilds().get(0).getMembers().forEach(member -> {
if (!member.getUser().isBot()) {
CodebaseBot.getInstance().getLevelManager().load(member.getUser().getId());
if (CodebaseBot.getInstance().getLevelManager().getLevelUser(member.getUser().getId()).getLevel() >= 3 && !member.getGuild().getRolesByName("Projekt", true).isEmpty()) {
Role role = member.getGuild().getRolesByName("Projekt", true).get(0);
if (PermissionUtil.canInteract(member.getGuild().getSelfMember(), role)) {
member.getGuild().getController().addRolesToMember(member, role).queue();
}
}
}
});
Set<Class<? extends ListenerAdapter>> classes = new Reflections("de.c0debase.bot.listener").getSubTypesOf(ListenerAdapter.class);
classes.forEach(listenerClass -> {
if (!listenerClass.getName().equals(this.getClass().getName())) {
try {
event.getJDA().addEventListener(listenerClass.newInstance());
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
for (VoiceChannel voiceChannel : event.getJDA().getGuilds().get(0).getVoiceChannels()) {
String name = ("temp-" + voiceChannel.getName().toLowerCase()).replaceAll("\\s+", "-");
final TextChannel textChannel = voiceChannel.getGuild().getTextChannelsByName(name, true).isEmpty() ? null : voiceChannel.getGuild().getTextChannelsByName(name, true).get(0);
if (textChannel == null) {
CodebaseBot.getInstance().getTempchannels().put(voiceChannel.getId(), new Tempchannel());
} else {
Tempchannel tempchannel = new Tempchannel(textChannel);
tempchannel.onLoad(textChannel, voiceChannel);
CodebaseBot.getInstance().getTempchannels().put(voiceChannel.getId(), tempchannel);
}
}
CodebaseBot.getInstance().getLevelManager().startInviteChecker();
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project c0debaseBot by Biospheere.
the class JoinCommand method execute.
@Override
public void execute(String[] args, Message msg) {
EmbedBuilder embedBuilder = getEmbed(msg.getGuild(), msg.getAuthor());
AudioManager audioManager = msg.getGuild().getAudioManager();
if (audioManager.isConnected() || audioManager.isAttemptingToConnect()) {
embedBuilder.setDescription("Der Bot ist bereits verbunden");
} else if (!msg.getMember().getVoiceState().inVoiceChannel()) {
embedBuilder.setDescription("Dafür musst du in einem Voicechannel sein.");
} else {
VoiceChannel channel = msg.getMember().getVoiceState().getChannel();
msg.getGuild().getAudioManager().openAudioConnection(channel);
embedBuilder.setDescription("Channel" + channel.getName() + " betreten");
}
msg.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class MusicOptions method onRegistry.
@Subscribe
public void onRegistry(OptionRegistryEvent e) {
registerOption("fairqueue:max", "Fair queue maximum", "Sets the maximum fairqueue value (max amount of the same song any user can add).\n" + "Example: `~>opts fairqueue max 5`", "Sets the maximum fairqueue value.", (event, args) -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a positive integer.").queue();
return;
}
String much = args[0];
final int fq;
try {
fq = Integer.parseInt(much);
} catch (Exception ex) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid number").queue();
return;
}
guildData.setMaxFairQueue(fq);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Set max fair queue size to " + fq).queue();
});
registerOption("musicannounce:toggle", "Music announce toggle", "Toggles whether the bot will announce the new song playing or no.", event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
boolean t1 = guildData.isMusicAnnounce();
guildData.setMusicAnnounce(!t1);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Set music announce to " + "**" + !t1 + "**").queue();
dbGuild.save();
});
registerOption("music:channel", "Music VC lock", "Locks the bot to a VC. You need the VC name.\n" + "Example: `~>opts music channel Music`", "Locks the music feature to the specified VC.", (event, args) -> {
if (args.length == 0) {
OptsCmd.onHelp(event);
return;
}
String channelName = String.join(" ", args);
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
Consumer<VoiceChannel> consumer = voiceChannel -> {
guildData.setMusicChannel(voiceChannel.getId());
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.OK + "Music Channel set to: " + voiceChannel.getName()).queue();
};
VoiceChannel channel = Utils.findVoiceChannelSelect(event, channelName, consumer);
if (channel != null) {
consumer.accept(channel);
}
});
registerOption("music:queuelimit", "Music queue limit", "Sets a custom queue limit.\n" + "Example: `~>opts music queuelimit 90`", "Sets a custom queue limit.", (event, args) -> {
if (args.length == 0) {
OptsCmd.onHelp(event);
return;
}
boolean isNumber = args[0].matches("^[0-9]*$");
if (!isNumber) {
event.getChannel().sendMessage(EmoteReference.ERROR + "That's not a valid number!").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
try {
int finalSize = Integer.parseInt(args[0]);
int applySize = finalSize >= 300 ? 300 : finalSize;
guildData.setMusicQueueSizeLimit((long) applySize);
dbGuild.save();
event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "The queue limit on this server is now " + "**%d** songs.", applySize)).queue();
} catch (NumberFormatException ex) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You're trying to set too high of a number (which won't" + " be applied anyway), silly").queue();
}
});
registerOption("music:clearchannel", "Music channel clear", "Clears the specific music channel.", (event) -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setMusicChannel(null);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "I can play music on all channels now").queue();
});
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project FlareBot by FlareBot.
the class DebugCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length < 1) {
MessageUtils.sendUsage(this, channel, sender, args);
return;
}
FlareBot fb = FlareBot.instance();
EmbedBuilder eb = MessageUtils.getEmbed();
if (args[0].equalsIgnoreCase("flarebot") || args[0].equalsIgnoreCase("bot")) {
eb.setTitle("Bot Debug").setDescription(String.format("Debug for FlareBot v" + FlareBot.getVersion() + "\nUptime: %s" + "\nMemory Usage: %s" + "\nMemory Free: %s" + "\nVideo Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\n\nGuilds: %d" + "\nLoaded Guilds: %d" + "\nVoice Channels: %d" + "\nActive Voice Channels: %d" + "\nCommands Executed: %d" + "\nQueued RestActions: %s", fb.getUptime(), getMB(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()), getMB(Runtime.getRuntime().freeMemory()), VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), fb.getShardManager().getGuildCache().size(), FlareBotManager.instance().getGuilds().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels(), fb.getEvents().getCommandCount(), getQueuedRestActions()));
StringBuilder sb = new StringBuilder();
for (DataInterceptor interceptor : DataInterceptor.getInterceptors()) sb.append(WordUtils.capitalize(interceptor.getSender().getName())).append(" - ").append(interceptor.getRequests()).append(" requests").append("\n");
eb.addField("HTTP Requests", sb.toString(), false);
} else if (args[0].equalsIgnoreCase("threads")) {
eb.setTitle("Thread Debug").setDescription(String.format("Video Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\nThread list: %s", VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), MessageUtils.paste(Thread.getAllStackTraces().keySet().stream().map(th -> th.getName() + " - " + th.getState() + " (" + th.getThreadGroup().getName() + ")").collect(Collectors.joining("\n")))));
} else if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("guild")) {
} else if (args[0].equalsIgnoreCase("player") || args[0].equalsIgnoreCase("music")) {
GuildWrapper wrapper = guild;
if (args.length == 2)
wrapper = FlareBotManager.instance().getGuild(args[1]);
if (wrapper == null) {
channel.sendMessage("I can't find that guild!").queue();
return;
}
Player player = FlareBot.instance().getMusicManager().getPlayer(wrapper.getGuildId());
VoiceChannel vc = (wrapper.getGuild().getSelfMember().getVoiceState() != null && wrapper.getGuild().getSelfMember().getVoiceState().getChannel() != null ? wrapper.getGuild().getSelfMember().getVoiceState().getChannel() : null);
String lastActive = "Not tracked.";
if (VoiceChannelCleanup.VC_LAST_USED.containsKey(vc != null ? vc.getIdLong() : guild.getGuildIdLong())) {
long ms = VoiceChannelCleanup.VC_LAST_USED.get(vc != null ? vc.getIdLong() : guild.getGuildIdLong());
lastActive = String.valueOf(ms) + " (" + (System.currentTimeMillis() - ms) + "ms ago)";
}
boolean isPlaying = player.getPlayingTrack() != null;
Track track = player.getPlayingTrack();
eb.setTitle("Bot Debug").setDescription(String.format("Player Debug for `" + wrapper.getGuildId() + "`" + "\nCurrent Track: %s" + "\nCurrent Position: %s" + "\nIs Paused: %b" + "\nPlaylist Length: %s" + "\nIs Looping: %b" + "\nVoice Channel: %s" + "\nLast Active: %s", (isPlaying ? track.getTrack().getIdentifier() : "No current track"), (isPlaying ? track.getTrack().getPosition() + "/" + track.getTrack().getDuration() : "N/A"), player.getPaused(), player.getPlaylist().size(), player.getLooping(), (vc == null ? "null" : vc.toString()), lastActive));
} else {
channel.sendMessage("Invalid debug option").queue();
return;
}
channel.sendMessage(eb.build()).queue();
}
Aggregations