Skip to content

πŸ“¦ Lightweight Kotlin Multiplatform library for Discord Rich Presence

License

Notifications You must be signed in to change notification settings

vyfor/KPresence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0e4f5fd Β· Mar 10, 2025
Apr 7, 2024
Mar 18, 2024
Mar 10, 2025
Apr 5, 2024
Mar 11, 2024
Mar 10, 2025
Mar 10, 2025
Apr 5, 2024
Mar 31, 2024
Mar 31, 2024
Mar 10, 2025

Repository files navigation

🧩 KPresence

πŸ“¦ A lightweight, cross-platform Kotlin Multiplatform library for interacting with Discord Rich Presence.

πŸ’Ž Features

  • Cross-platform compatibility (Windows, Linux, macOS)
  • Fast and user-friendly
  • Offers DSL support
  • Provides both JVM and Native implementations
  • Validates the activity fields before sending them
  • Supports Flatpak and Snap installations on Linux
  • Ability to extend and override the default search paths

πŸ”Œ Requirements

  • Java: 16 or later (only for use within the JVM environment)

βš™οΈ Installation

dependencies {
    implementation("io.github.vyfor:kpresence:0.6.5")
}

✨ Examples

Initial connection and presence updates

val client = RichClient(CLIENT_ID)
  
client.connect()

client.update {
    type = ActivityType.GAME
    details = "Exploring Kotlin Native"
    state = "Writing code"
    
    timestamps {
        start = now() - 3600_000
        end = now() + 3600_000
    }
    
    party {
      id = "myParty"
      size(current = 1, max = 5)
    }
    
    assets {
        largeImage = "kotlin_logo"
        largeText = "Kotlin"
        smallImage = "jetbrains_logo"
        smallText = "JetBrains"
    }
    
    secrets {
        join = "joinSecret"
        spectate = "spectateSecret"
        match = "matchSecret"
    }
    
    button("Learn more", "https://kotlinlang.org/")
    button("Try it yourself", "https://play.kotlinlang.org/")
}

Event handling

val client = RichClient(CLIENT_ID)

client.on<ReadyEvent> {
  update(activity)
}

client.on<ActivityUpdateEvent> {
  logger?.info("Updated rich presence")
}

client.on<DisconnectEvent> {
  connect(shouldBlock = true) // Attempt to reconnect
}

client.connect(shouldBlock = false)

Logging

val client = RichClient(CLIENT_ID)
client.logger = ILogger.default()