Skip to content

Commit 2aaccb6

Browse files
committed
push discord fix
1 parent 558b554 commit 2aaccb6

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ configurations.all {
7070
repositories {
7171
mavenLocal() // Allow the use of local repositories
7272
maven("https://maven.2b2t.vc/releases") // Baritone
73-
maven("https://jitpack.io") // KDiscordIPC
73+
maven("https://maven.firstdark.dev/releases")
7474
maven("https://api.modrinth.com/maven")
7575
mavenCentral()
7676

@@ -155,7 +155,7 @@ dependencies {
155155

156156
// Add dependencies on the required Kotlin modules.
157157
includeLib("io.github.classgraph:classgraph:${classGraphVersion}")
158-
includeLib("com.github.emyfops:KDiscordIPC:$discordIPCVersion")
158+
includeLib("dev.firstdark.discordrpc:discord-rpc:1.0.4")
159159
includeLib("com.pngencoder:pngencoder:$pngEncoderVersion")
160160

161161
includeLib("io.github.spair:imgui-java-binding:$spairVersion")

src/main/kotlin/com/lambda/module/modules/client/Discord.kt

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,21 @@
1818
package com.lambda.module.modules.client
1919

2020
import com.lambda.Lambda
21-
import com.lambda.Lambda.LOG
2221
import com.lambda.context.SafeContext
23-
import com.lambda.event.EventFlow
22+
import com.lambda.event.events.ClientEvent
2423
import com.lambda.event.events.WorldEvent
2524
import com.lambda.event.listener.SafeListener.Companion.listenOnce
25+
import com.lambda.event.listener.UnsafeListener.Companion.listenOnceUnsafe
2626
import com.lambda.module.Module
2727
import com.lambda.module.tag.ModuleTag
28-
import com.lambda.network.NetworkManager.updateToken
29-
import com.lambda.network.api.v1.endpoints.linkDiscord
3028
import com.lambda.threading.runConcurrent
31-
import com.lambda.util.Communication.warn
3229
import com.lambda.util.Nameable
3330
import com.lambda.util.extension.dimensionName
3431
import com.lambda.util.extension.fullHealth
3532
import com.lambda.util.extension.worldName
36-
import dev.cbyrne.kdiscordipc.KDiscordIPC
37-
import dev.cbyrne.kdiscordipc.core.packet.inbound.impl.AuthenticatePacket
38-
import dev.cbyrne.kdiscordipc.data.activity.button
39-
import dev.cbyrne.kdiscordipc.data.activity.largeImage
40-
import dev.cbyrne.kdiscordipc.data.activity.smallImage
41-
import dev.cbyrne.kdiscordipc.data.activity.timestamps
33+
import dev.firstdark.rpc.DiscordRpc
34+
import dev.firstdark.rpc.handlers.RPCEventHandler
35+
import dev.firstdark.rpc.models.DiscordRichPresence
4236
import kotlinx.coroutines.delay
4337

4438
object Discord : Module(
@@ -54,63 +48,55 @@ object Discord : Module(
5448
private val line2Left by setting("Line 2 Left", LineInfo.Version)
5549
private val line2Right by setting("Line 2 Right", LineInfo.Fps)
5650

57-
val rpc = KDiscordIPC(Lambda.APP_ID, scope = EventFlow.lambdaScope)
58-
51+
val rpc = DiscordRpc()
5952
private var startup = System.currentTimeMillis()
6053

61-
var discordAuth: AuthenticatePacket.Data? = null; private set
54+
// var discordAuth: AuthenticatePacket.Data? = null; private set
6255

6356
init {
6457
listenOnce<WorldEvent.Join> {
65-
if (rpc.connected) return@listenOnce false
66-
6758
runConcurrent {
6859
start()
69-
handleLoop()
60+
update()
7061
}
7162

7263
return@listenOnce true
7364
}
7465

75-
onEnable { runConcurrent { start(); handleLoop() } }
66+
onEnable { runConcurrent { start(); update() } }
7667
onDisable { stop() }
7768
}
7869

79-
private suspend fun start() {
80-
if (rpc.connected) return
81-
82-
runConcurrent { rpc.connect() }
83-
delay(1000)
84-
85-
val auth = rpc.applicationManager.authenticate()
86-
87-
linkDiscord(discordToken = auth.accessToken)
88-
.onSuccess { updateToken(it); discordAuth = auth }
89-
.onFailure { LOG.error(it); warn("Failed to link your discord account") }
70+
private fun start() {
71+
rpc.init(Lambda.APP_ID, RPCEventHandler(), true)
72+
// val auth = rpc.applicationManager.authenticate()
73+
//
74+
// linkDiscord(discordToken = auth.accessToken)
75+
// .onSuccess { updateToken(it); discordAuth = auth }
76+
// .onFailure { LOG.error(it); warn("Failed to link your discord account") }
9077
}
9178

9279
private fun stop() {
93-
if (rpc.connected) rpc.disconnect()
94-
}
95-
96-
private suspend fun SafeContext.handleLoop() {
97-
while (rpc.connected) {
98-
update()
99-
delay(delay)
100-
}
80+
rpc.shutdown()
10181
}
10282

10383
private suspend fun SafeContext.update() {
104-
rpc.activityManager.setActivity {
105-
details = "${line1Left.value(this@update)} | ${line1Right.value(this@update)}".take(128)
106-
state = "${line2Left.value(this@update)} | ${line2Right.value(this@update)}".take(128)
107-
108-
largeImage("lambda", Lambda.VERSION)
109-
smallImage("https://mc-heads.net/avatar/${mc.gameProfile.id}/nohelm", mc.gameProfile.name)
110-
button("Download", "https://github.com/lambda-client/lambda")
111-
112-
if (showTime) timestamps(startup)
113-
}
84+
val presence = DiscordRichPresence
85+
.builder()
86+
.details("${line1Left.value(this)} | ${line1Right.value(this)}".take(128))
87+
.state("${line2Left.value(this)} | ${line2Right.value(this)}".take(128))
88+
.largeImageKey("lambda")
89+
.largeImageText(Lambda.VERSION)
90+
.smallUrl("https://mc-heads.net/avatar/${mc.gameProfile.id}/nohelm")
91+
.smallImageText(mc.gameProfile.name)
92+
.button(DiscordRichPresence.RPCButton.of("Download", "https://github.com/lambda-client/lambda"))
93+
94+
if (showTime)
95+
presence.startTimestamp(startup)
96+
97+
rpc.updatePresence(presence.build())
98+
99+
delay(delay)
114100
}
115101

116102
private enum class LineInfo(val value: SafeContext.() -> String) : Nameable {

0 commit comments

Comments
 (0)