NotJustAnna / andeclient

A Java 11, Library-independent, Andesite Client implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AndeClient

A Java 11, Library-independent, Andesite Client implementation.

Licensed under the Apache 2.0 License.

Installation

Latest Version

Using in Gradle:

repositories {
  jcenter()
}

dependencies {
  compile 'pw.aru.libs:andeclient:LATEST' // replace LATEST with the version above
}

Using in Maven:

<repositories>
  <repository>
    <id>central</id>
    <name>bintray</name>
    <url>http://jcenter.bintray.com</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>pw.aru.libs</groupId>
    <artifactId>andeclient</artifactId>
    <version>LATEST</version> <!-- replace LATEST with the version above -->
  </dependency>
</dependencies>

Usage

First, create your own instance of AndeClient.

AndeClient andeClient = AndeClient.andeClient(botUserId).create();

With an instance of AndeClient, you can connect to nodes and create players.

AndesiteNode localNode = andeClient.newNode()
    .host("127.0.0.1")
    .password("youshallnotpass")
    .create(); // automatically added to AndeClient after you create it.

AndePlayer myGuildPlayer = andeClient.newPlayer()
    .guildId(myGuildId)
    .andesiteNode(localNode)
    .create(); // automatically added to AndeClient after you create it.

For each player, you need to setup a voice-server-update handler in your Discord lib and redirect it to the player.

// example with Catnip - https://github.com/mewna/catnip

Catnip catnip = Catnip.catnip("token");

catnip.connect();

catnip.on(DiscordEvent.VOICE_SERVER_UPDATE, voiceServerUpdate -> {
    String sessionId = catnip.cache().voiceState(GUILD_ID, catnip.selfUser().id()).sessionId();
    myGuildPlayer.handleVoiceServerUpdate(sessionId, voiceServerUpdate.token(), voiceServerUpdate.endpoint());
});

catnip.openVoiceConnection(GUILD_ID, VOICE_CHANNEL_ID);

Instances of AndePlayer offer a AndePlayer#controls method which lets you play tracks, pause the player or stop the music.

AudioTrack myTrack = ...; // use AndesiteNode#loadTracksAsync or cache tracks with AudioTrackUtil#fromTrack

// plays a track
myGuildPlayer.controls()
    .play()
        .track(myTrack)
        .submit();

// pauses the player
myGuildPlayer.controls()
    .pause().submit();

You can listen to events of a specific type, node, player or listen to all events.

// listen to all events
andeClient.on(event -> System.out.println("new event: " + event));

// listen to newly created nodes
andeClient.on(EventType.NEW_NODE_EVENT, event -> System.out.println("new node v" + event.node().version() + " connected"));

// listen to all events of a node
localNode.on(event -> System.out.println("new event on local node: " + event));

// listen to all events of a player
myGuildPlayer.on(event -> System.out.println("new event on my player: " + event));

// listen to all times the player updates
myGuildPlayer.on(EventType.PLAYER_UPDATE_EVENT, event -> System.out.println("player update: " + event));

Work in Progress/Missing

Support

Support is given on Aru's Discord Server

Aru's Discord Server

About

A Java 11, Library-independent, Andesite Client implementation.

License:Apache License 2.0


Languages

Language:Java 100.0%