use of net.dv8tion.jda.core.entities.VoiceChannel in project FredBoat by Frederikam.
the class VoiceChannelCleanupAgent method cleanup.
private void cleanup() {
log.info("Checking guilds for stale voice connections.");
final AtomicInteger totalGuilds = new AtomicInteger(0);
final AtomicInteger totalVcs = new AtomicInteger(0);
final AtomicInteger closedVcs = new AtomicInteger(0);
guildProvider.streamGuilds().forEach(guild -> {
try {
totalGuilds.incrementAndGet();
if (guild != null && guild.getSelfMember() != null && guild.getSelfMember().getVoiceState() != null && guild.getSelfMember().getVoiceState().getChannel() != null) {
totalVcs.incrementAndGet();
VoiceChannel vc = guild.getSelfMember().getVoiceState().getChannel();
if (getHumanMembersInVC(vc).size() == 0) {
closedVcs.incrementAndGet();
VoteSkipCommand.guildSkipVotes.remove(guild.getIdLong());
audioConnectionFacade.closeConnection(guild);
VC_LAST_USED.remove(vc.getId());
} else if (isBeingUsed(vc)) {
VC_LAST_USED.put(vc.getId(), System.currentTimeMillis());
} else {
if (!VC_LAST_USED.containsKey(vc.getId())) {
VC_LAST_USED.put(vc.getId(), System.currentTimeMillis());
}
long lastUsed = VC_LAST_USED.get(vc.getId());
if (System.currentTimeMillis() - lastUsed > UNUSED_CLEANUP_THRESHOLD) {
closedVcs.incrementAndGet();
audioConnectionFacade.closeConnection(guild);
VC_LAST_USED.remove(vc.getId());
}
}
}
} catch (Exception e) {
log.error("Failed to check guild {} for stale voice connections", guild.getIdLong(), e);
}
});
log.info("Checked {} guilds for stale voice connections.", totalGuilds.get());
log.info("Closed {} of {} voice connections.", closedVcs.get(), totalVcs.get());
Metrics.voiceChannelsCleanedUp.inc(closedVcs.get());
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project Rubicon by Rubicon-Bot.
the class CommandAutochannel method invokeDelete.
private void invokeDelete(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
String[] args = parsedCommandInvocation.getArgs();
Guild guild = parsedCommandInvocation.getMessage().getGuild();
StringBuilder names = new StringBuilder();
for (int i = 1; i < args.length; i++) {
names.append(args[i]).append(" ");
}
String name = names.toString();
name = names.replace(name.lastIndexOf(" "), name.lastIndexOf(" ") + 1, "").toString();
List<VoiceChannel> channels = guild.getVoiceChannelsByName(name, false);
String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "autochannels");
List<VoiceChannel> autochannels = new ArrayList<>();
channels.forEach(c -> {
if (oldEntry.contains(c.getId()))
autochannels.add(c);
});
if (autochannels.isEmpty()) {
Message mymsg = parsedCommandInvocation.getTextChannel().sendMessage(EmbedUtil.error("Unknown Channel", "There is now channel with this name").build()).complete();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
mymsg.delete().queue();
}
}, 5000);
return;
}
if (autochannels.size() > 1) {
ChannelSearch search = genChannelSearch(autochannels, true, parsedCommandInvocation);
searches.put(guild, search);
} else {
VoiceChannel channel = channels.get(0);
if (!oldEntry.contains(channel.getId())) {
parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.error("Unknown channel", "This channel isn't an autochannel").build()).queue();
return;
}
deleteChannel(channel, parsedCommandInvocation);
}
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project Rubicon by Rubicon-Bot.
the class CommandAutochannel method genChannelSearch.
private ChannelSearch genChannelSearch(List<VoiceChannel> channels, boolean deleteChannel, CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
HashMap<String, VoiceChannel> channellist = new HashMap<>();
StringBuilder channelnames = new StringBuilder();
ArrayList<String> EMOJIS = new ArrayList<>(Arrays.asList(EMOTI));
channels.forEach(c -> {
String category;
if (c.getParent() != null)
category = c.getParent().getName();
else
category = "NONE";
channelnames.append(EMOJIS.get(0)).append(" - ").append(c.getName()).append("(`").append(c.getId()).append("`) (Category: ").append(category).append(")\n");
channellist.put(EMOJIS.get(0), c);
EMOJIS.remove(0);
});
if (channellist.isEmpty()) {
parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.error("Unknown Channel", "There is now channel with this name").build()).queue();
return null;
} else {
Message msg = parsedCommandInvocation.getMessage().getTextChannel().sendMessage(new EmbedBuilder().setColor(Colors.COLOR_SECONDARY).setDescription(channelnames.toString()).build()).complete();
channellist.keySet().forEach(e -> msg.addReaction(e).queue());
return new ChannelSearch(msg, channellist, deleteChannel);
}
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project Rubicon by Rubicon-Bot.
the class AutochannelListener method onGuildVoiceMove.
@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent e) {
VoiceChannel ch = e.getChannelJoined();
if (isAutoChannel(e.getGuild(), ch)) {
VoiceChannel newChannel = (VoiceChannel) e.getGuild().getController().createCopyOfChannel(ch).setName(ch.getName() + " [AC]").complete();
e.getGuild().getController().moveVoiceMember(e.getMember(), newChannel).queue();
}
if (e.getChannelLeft().getMembers().size() == 0) {
if (e.getChannelLeft().getName().contains("[AC]")) {
e.getChannelLeft().delete().queue();
}
}
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.
the class PermanentChannelCommand method execute.
@Override
protected void execute() {
if (!ev.getMember().getVoiceState().inVoiceChannel()) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
return;
}
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
if (l.getChannelController().isPermanent(vc)) {
handleError(MessageContent.CHANNEL_ALREADY_PERMANENT);
return;
}
l.getChannelController().getPermChannels().putStoring(ev.getChannel(), vc);
LoggerUtils.logAndDelete(log, String.format("%s has been made permanent.", vc.getName()));
l.getDiscordController().sendMessage(ev.getChannel(), String.format("Successfully made **%s** permanent!", vc.getName()), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
l.getFileController().applyPermAddition(ev.getChannel(), vc);
}
Aggregations