Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vyfor/kpresence
📦 A lightweight, cross-platform Kotlin library for Discord Rich Presence interaction.
https://github.com/vyfor/kpresence
discord discord-presence discord-rpc java jvm kotlin kotlin-native presence rich rich-presence rpc
Last synced: 4 months ago
JSON representation
📦 A lightweight, cross-platform Kotlin library for Discord Rich Presence interaction.
- Host: GitHub
- URL: https://github.com/vyfor/kpresence
- Owner: vyfor
- License: mit
- Created: 2024-03-11T12:44:01.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-05-24T13:56:17.000Z (9 months ago)
- Last Synced: 2024-09-30T13:04:04.040Z (4 months ago)
- Topics: discord, discord-presence, discord-rpc, java, jvm, kotlin, kotlin-native, presence, rich, rich-presence, rpc
- Language: Kotlin
- Homepage:
- Size: 211 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🧩 KPresence
**📦 A lightweight, cross-platform [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) 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## 🔌 Requirements
- **Java**: `16 or later` (only for use within the JVM environment)## ⚙️ Installation
```gradle
dependencies {
implementation("io.github.vyfor:kpresence:0.6.2")
}
```## ✨ Examples
### Initial connection and presence updates
```kt
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
```kt
val client = RichClient(CLIENT_ID)client.on {
update(activity)
}client.on {
logger?.info("Updated rich presence")
}client.on {
connect(shouldBlock = true) // Attempt to reconnect
}client.connect(shouldBlock = false)
```### Logging
```kt
val client = RichClient(CLIENT_ID)
client.logger = ILogger.default()
```