@@ -35,7 +35,7 @@ object DiscordRPC : Module(
3535 name = " DiscordRPC" ,
3636 description = " Discord Rich Presence configuration" ,
3737 defaultTags = setOf(ModuleTag .CLIENT ),
38- enabledByDefault = true ,
38+ // enabledByDefault = true, // ToDo: Bring this back on beta release
3939) {
4040 private val page by setting(" Page" , Page .General )
4141
@@ -52,7 +52,7 @@ object DiscordRPC : Module(
5252 /* Technical settings */
5353 private var rpcServer by setting(" RPC Server" , " http://127.0.0.1:8080" ) { page == Page .Settings } // TODO: Change this in production
5454 private var apiVersion by setting(" API Version" , ApiVersion .V1 ) { page == Page .Settings }
55- private val delay by setting(" Update Delay" , 5000 , 5000 .. 10000 , 1 , unit = " ms" , visibility = { page == Page .Settings })
55+ private val delay by setting(" Update Delay" , 15000 , 15000 .. 30000 , 100 , unit = " ms" , visibility = { page == Page .Settings })
5656
5757 /* Party settings */
5858 private val enableParty by setting(" Enable Party" , true , description = " Allows you to create parties." ) { page == Page .Party }
@@ -64,6 +64,7 @@ object DiscordRPC : Module(
6464 private var startup = System .currentTimeMillis()
6565 private val dimensionRegex = Regex (""" \b\w+_\w+\b""" )
6666
67+ private var ready: ReadyEvent ? = null
6768 private var discordAuth: AuthenticatePacket .Data ? = null
6869 private var rpcAuth: Authentication ? = null
6970 private var currentParty: AtomicReference <Party ?> = AtomicReference (null )
@@ -157,6 +158,21 @@ object DiscordRPC : Module(
157158 rpc.disconnect()
158159 leaveParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ? : return )
159160 }
161+
162+ ready = null
163+ discordAuth = null
164+ rpcAuth = null
165+ currentParty.lazySet(null )
166+ }
167+
168+ fun createParty () {
169+ if (! allowed) return
170+
171+ createParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ? : return , maxPlayers, public)
172+ .also { response ->
173+ if (response.error != null ) warn(" Failed to create a party: ${response.error} " )
174+ currentParty.lazySet(response.data)
175+ }
160176 }
161177
162178 fun join (id : String = rpc.activityManager.activity?.party?.id ? : "") {
@@ -203,20 +219,14 @@ object DiscordRPC : Module(
203219 }
204220
205221 private suspend fun KDiscordIPC.register (auth : ConnectionEvent .Connect .Login .Key ) {
206- // TODO: Check if the rpc is already ready
222+ if (rpc.connected && ready != null ) return
223+
207224 on<ReadyEvent > {
225+ ready = this
226+
208227 // Party features
209228 subscribe(DiscordEvent .ActivityJoinRequest )
210229 subscribe(DiscordEvent .ActivityJoin )
211- // subscribe(DiscordEvent.LobbyUpdate)
212- // subscribe(DiscordEvent.LobbyDelete)
213- // subscribe(DiscordEvent.LobbyMemberConnect)
214- // subscribe(DiscordEvent.LobbyMemberDisconnect)
215- // subscribe(DiscordEvent.LobbyMemberUpdate)
216-
217- // QOL features
218- // subscribe(DiscordEvent.SpeakingStart)
219- // subscribe(DiscordEvent.SpeakingStop)
220230
221231 if (System .currentTimeMillis() - connectionTime > 300000 ) {
222232 warn(" The authentication hash has expired, reconnect to the server." )
@@ -236,11 +246,7 @@ object DiscordRPC : Module(
236246 rpcAuth = response.data
237247 }
238248
239- if (createByDefault) createParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ? : return @on, maxPlayers, public)
240- .also { response ->
241- if (response.error != null ) warn(" Failed to create a party: ${response.error} " )
242- currentParty.lazySet(response.data)
243- }
249+ if (createByDefault) createParty()
244250 }
245251
246252 // Event when someone would like to join your party
0 commit comments