File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed
src/main/kotlin/dev/arbjerg/lavalink Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,9 @@ import java.util.concurrent.TimeUnit
19
19
20
20
/* *
21
21
* @param userId ID of the bot for authenticating with Discord
22
- * @param clientName Name of the client, used for connecting to the Lavalink node(s)
22
+ * @param userAgent Name of the client, used for connecting to the Lavalink node(s)
23
23
*/
24
- class LavalinkClient (val userId : Long , var clientName : String? ) : Closeable, Disposable {
24
+ class LavalinkClient (val userId : Long , var userAgent : String? ) : Closeable, Disposable {
25
25
private val internalNodes = CopyOnWriteArrayList <LavalinkNode >()
26
26
private val linkMap = ConcurrentHashMap <Long , Link >()
27
27
private var clientOpen = true
Original file line number Diff line number Diff line change @@ -55,8 +55,8 @@ class LavalinkNode(
55
55
val flux: Flux <ClientEvent > = sink.asFlux()
56
56
private val reference: Disposable = flux.subscribe()
57
57
58
- internal val rest = LavalinkRestClient (this )
59
- val ws = LavalinkSocket (this , lavalink.clientName )
58
+ internal val rest = LavalinkRestClient (this , lavalink.userAgent )
59
+ val ws = LavalinkSocket (this , lavalink.userAgent )
60
60
61
61
// Stuff for load balancing
62
62
val penalties = Penalties (this )
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ import java.io.IOException
15
15
import java.net.URLEncoder
16
16
import java.nio.charset.StandardCharsets
17
17
18
- class LavalinkRestClient (val node : LavalinkNode ) {
18
+ class LavalinkRestClient (val node : LavalinkNode , private val userAgent : String? ) {
19
+
19
20
fun getPlayers (): Mono <Players > {
20
21
return newRequest {
21
22
path(" /v4/sessions/${node.sessionId} /players" )
@@ -82,6 +83,10 @@ class LavalinkRestClient(val node: LavalinkNode) {
82
83
internal fun newRequest (configure : HttpBuilder .() -> HttpBuilder ): Call {
83
84
val requestBuilder = Request .Builder ()
84
85
.addHeader(" Authorization" , node.password)
86
+ .apply {
87
+ if (userAgent != null )
88
+ addHeader(" User-Agent" , userAgent)
89
+ }
85
90
.get()
86
91
val builder = configure(HttpBuilder (requestBuilder))
87
92
You can’t perform that action at this time.
0 commit comments