use of gnu.trove.set.TLongSet in project PorkBot by DaMatrix.
the class AudioUtils method init.
public static void init() {
youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
}
}).setApplicationName("youtube-cmdline-search-sample").build();
devKey = KeyGetter.getDevKey();
musicManagers = new TSynchronizedLongObjectMap<>(new TLongObjectHashMap<>());
playerManager = new DefaultAudioPlayerManager();
AudioSourceManagers.registerRemoteSources(playerManager);
AudioSourceManagers.registerLocalSource(playerManager);
PorkBot.timer.schedule(new TimerTask() {
@Override
public void run() {
TLongSet toRemove = new TLongHashSet();
long now = System.currentTimeMillis();
musicManagers.forEachEntry((key, value) -> {
A: {
if (value.channel == null) {
// System.out.println("Removing guild because: missing channel");
toRemove.add(key);
break A;
}
if (value.created + 10000 < now && (value.channel.getMembers().size() < 2 || (value.manager.scheduler.queue.size() == 0 && value.manager.player.getPlayingTrack() == null))) {
// nobody's in the channel
// System.out.println("Removing guild because: empty");
value.manager.player.destroy();
value.channel.getGuild().getAudioManager().closeAudioConnection();
toRemove.add(key);
break A;
}
}
return true;
});
toRemove.forEach(l -> {
musicManagers.remove(l);
return true;
});
// not sure why or how this is happening, but it does apparently
List<AudioManager> list = ShardUtils.getConnectedVoice();
for (AudioManager manager : list) {
if (manager.getConnectedChannel().getMembers().size() < 2) {
manager.closeAudioConnection();
}
}
}
}, 10000, 5000);
}
Aggregations