GithubHelp home page GithubHelp logo

vyfor / kpresence Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 1.0 216 KB

๐Ÿ“ฆ A lightweight, cross-platform Kotlin library for Discord Rich Presence interaction.

License: MIT License

Kotlin 100.00%
discord discord-presence discord-rpc kotlin kotlin-native rich-presence presence rich rpc java jvm

kpresence's Introduction

๐Ÿงฉ 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

๐Ÿ”Œ Requirements

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

โš™๏ธ Installation

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

โœจ 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()

kpresence's People

Contributors

vyfor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cybernetics

kpresence's Issues

ConnectionException on Fedora 39

ConnectionException is thrown when connecting on Fedora 39. This seems to persist even when Discord client is closed.

Reproducible example

fun main() {
    val client = RichClient(/* id */)
    client.connect()
}

Stacktrace

Exception in thread "main" io.github.vyfor.kpresence.exception.ConnectionException
	at io.github.vyfor.kpresence.ipc.Connection$UnixConnection.open(Connection.kt:135)
	at io.github.vyfor.kpresence.ipc.Connection.open(Connection.kt:24)
	at io.github.vyfor.kpresence.RichClient.connect(RichClient.kt:53)
	at io.github.vyfor.kpresence.RichClient.connect$default(RichClient.kt:47)
	at io.github.pandier.MainKt.main(Main.kt:7)
	at io.github.pandier.MainKt.main(Main.kt)

Stacktrace of exception inside ConnectionException:

java.net.SocketException: No such file or directory
	at java.base/sun.nio.ch.UnixDomainSockets.connect0(Native Method)
	at java.base/sun.nio.ch.UnixDomainSockets.connect(UnixDomainSockets.java:148)
	at java.base/sun.nio.ch.UnixDomainSockets.connect(UnixDomainSockets.java:144)
	at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:851)
	at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:285)
	at io.github.vyfor.kpresence.ipc.Connection$UnixConnection.open(Connection.kt:130)
	at io.github.vyfor.kpresence.ipc.Connection.open(Connection.kt:24)
	at io.github.vyfor.kpresence.RichClient.connect(RichClient.kt:53)
	at io.github.vyfor.kpresence.RichClient.connect$default(RichClient.kt:47)
	at io.github.pandier.MainKt.main(Main.kt:9)
	at io.github.pandier.MainKt.main(Main.kt)

Environment

  • KPresence version: 0.6.0
  • OS: Fedora 39

Rewrite code for Windows target

Current implementation makes use of posix libraries to display rich presence. It is preferred to use the Windows API for better compatibility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.