A Kotlin library for interacting with Discord via IPC

Related tags

Kotlin kotlin discord ipc
Overview

KDiscordIPC

A Kotlin library for interacting with Discord via IPC

Features

  • Fully documented codebase
  • macOS and Linux support (including M1 Macs, Windows support is coming soon)
  • Easy to use Kotlin DSL for building presence objects

Installation

You can add KDiscordIPC to your project via Jitpack:

repositories {
    mavenCentral()

    // Required to retrieve KDiscordIPC from GitHub
    maven("https://jitpack.io/")
}

dependencies {
    implementation("com.github.cbyrneee:KDiscordIPC:latest-commit-hash")
}

Usage

import dev.cbyrne.kdiscordipc.*

fun main(args: Array<String>) {
    val ipc = DiscordIPC("application id")

    // Once the READY event is received, the presence will be set
    // This can be set at any time unless the connection has been closed
    ipc.presence = presence {
        state = "Testing..."
        details = "Hello world"
        largeImageKey = "icon"
        largeImageText = "So cool!"
    }

    ipc.listener = object : IPCListener {
        override fun onReadyEvent(event: DiscordEvent.Ready) {
            println("User: ${event.user}")
            
            // You could also set the presence in here if you wish
            // ipc.presence = ...
        }
    }

    ipc.connect()
}

License

GPL 3.0

Comments
  • Failed to read raw packet exception on Windows

    Failed to read raw packet exception on Windows

    some users are getting this error:

    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.IllegalStateException: Failed to read raw packet
    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at dev.cbyrne.kdiscordipc.socket.DiscordSocket.readPacket(DiscordSocket.kt:156)
    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at dev.cbyrne.kdiscordipc.socket.DiscordSocket.access$readPacket(DiscordSocket.kt:44)
    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at dev.cbyrne.kdiscordipc.socket.DiscordSocket$connect$1.invoke(DiscordSocket.kt:80)
    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at dev.cbyrne.kdiscordipc.socket.DiscordSocket$connect$1.invoke(DiscordSocket.kt:78)
    [10:35:41] [Thread-39/INFO]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
    

    Some don't, some do, the issue is very inconsistent.

    bug help wanted hacktoberfest 
    opened by Wyvest 8
  • KDiscordIPC cannot load junixsocket-native for amd64-Linux

    KDiscordIPC cannot load junixsocket-native for amd64-Linux

    KDiscordIPC throws Caused by: SocketConnectionException(reason=Could not load native library junixsocket-native for architecture amd64-Linux) at dev.cbyrne.kdiscordipc.socket.impl.UnixSystemSocket.connect(UnixSystemSocket.kt:47) at dev.cbyrne.kdiscordipc.socket.DiscordSocket.connect(DiscordSocket.kt:76) at dev.cbyrne.kdiscordipc.DiscordIPC.connect(DiscordIPC.kt:95) when trying to connect.

    This error occurs on my Kubuntu 21.04 machine and someone else's Arch Linux machine

    opened by Wyvest 8
  • Not working on Linux

    Not working on Linux

    Disclaimer: I am using another library that wraps this one. There's a good chance that it's a problem with the other one, but I thought I should check here. Whenever I try to open the connection, I get this error (I'm accessing it through Mozilla Rhino):

    Error loading module DynPresence
    org.mozilla.javascript.WrappedException: Wrapped SocketConnectionException(reason=org.newsclub.net.unix.AFUNIXSocketAddress.of(Ljava/io/File;)Lorg/newsclub/net/unix/AFUNIXSocketAddress;) (file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/config/ChatTriggers/modules/RichPresence/index.js#35)
    	at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1897)
    	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:139)
    	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:215)
    	at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:92)
    	at RichPresence_index_js_169._c_RichPresence_1(RichPresence/index.js:35)
    	at RichPresence_index_js_169.call(RichPresence/index.js)
    	at org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:436)
    	at RichPresence_index_js_169.construct(RichPresence/index.js)
    	at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2960)
    	at DynPresence_index_js_168._c_script_0(DynPresence/index.js:3)
    	at DynPresence_index_js_168.call(DynPresence/index.js)
    	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:342)
    	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3951)
    	at DynPresence_index_js_168.call(DynPresence/index.js)
    	at DynPresence_index_js_168.exec(DynPresence/index.js)
    	at org.mozilla.javascript.commonjs.module.Require.executeModuleScript(Require.java:351)
    	at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:302)
    	at com.chattriggers.ctjs.engine.langs.js.JSLoader$CTRequire.loadCTModule(JSLoader.kt:326)
    Caused by: SocketConnectionException(reason=org.newsclub.net.unix.AFUNIXSocketAddress.of(Ljava/io/File;)Lorg/newsclub/net/unix/AFUNIXSocketAddress;)
    	at dev.cbyrne.kdiscordipc.socket.impl.UnixSystemSocket.connect(UnixSystemSocket.kt:47)
    	at dev.cbyrne.kdiscordipc.socket.DiscordSocket.connect(DiscordSocket.kt:67)
    	at dev.cbyrne.kdiscordipc.DiscordIPC.connect(DiscordIPC.kt:96)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:117)
    	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:215)
    	at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:92)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft_config_ChatTriggers_modules_RichPresence_index_js_169._c_RichPresence_1(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/config/ChatTriggers/modules/RichPresence/index.js:35)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft_config_ChatTriggers_modules_RichPresence_index_js_169.call(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/config/ChatTriggers/modules/RichPresence/index.js)
    	at org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:436)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft_config_ChatTriggers_modules_RichPresence_index_js_169.construct(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/config/ChatTriggers/modules/RichPresence/index.js)
    	at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2960)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft___config_ChatTriggers_modules_DynPresence_index_js_168._c_script_0(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/./config/ChatTriggers/modules/DynPresence/index.js:3)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft___config_ChatTriggers_modules_DynPresence_index_js_168.call(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/./config/ChatTriggers/modules/DynPresence/index.js)
    	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:342)
    	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3951)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft___config_ChatTriggers_modules_DynPresence_index_js_168.call(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/./config/ChatTriggers/modules/DynPresence/index.js)
    	at org.mozilla.javascript.gen.file__home_kendell__local_share_multimc_instances_1_8_9__minecraft___config_ChatTriggers_modules_DynPresence_index_js_168.exec(file:/home/kendell/.local/share/multimc/instances/1.8.9/.minecraft/./config/ChatTriggers/modules/DynPresence/index.js)
    	at org.mozilla.javascript.commonjs.module.Require.executeModuleScript(Require.java:351)
    	at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:302)
    	at com.chattriggers.ctjs.engine.langs.js.JSLoader$CTRequire.loadCTModule(JSLoader.kt:326)
    	at com.chattriggers.ctjs.engine.langs.js.JSLoader.entryPass(JSLoader.kt:153)
    	at com.chattriggers.ctjs.engine.module.ModuleManager.entryPass(ModuleManager.kt:100)
    	at com.chattriggers.ctjs.engine.module.ModuleManager.entryPass$default(ModuleManager.kt:89)
    	at com.chattriggers.ctjs.Reference$loadCT$1.invoke(Reference.kt:74)
    	at com.chattriggers.ctjs.Reference$loadCT$1.invoke(Reference.kt:72)
    	at com.chattriggers.ctjs.Reference$conditionalThread$1.invoke(Reference.kt:111)
    	at com.chattriggers.ctjs.Reference$conditionalThread$1.invoke(Reference.kt:109)
    	at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
    

    Do you have any ideas what's going on? Other programs can access Discord Rich Presence just fine.

    opened by KTibow 5
  • KDiscordIPC reads packets incorrectly

    KDiscordIPC reads packets incorrectly

    From the recent changes which allowed us to read more than 8096 bytes, an issue appeared where we would read a chunk of one packet, and then a chunk of the next, and treat it as one.

    We can use DataInputStream#readFully to solve this.

    bug 
    opened by cbyrneee 1
  • Unable to show time as

    Unable to show time as "elapsed"

    Discord RPC question

    fun Activity.timestamps(start: Long, end: Long) {
        this.timestamps = Activity.Timestamps(start, end)
    }
    

    The discord docs says that to show the time as "elapsed" I have to not pass the endTimeStamp, but if I don't pass it or pass it as null there is an error. Null can not be a value of a non-null type Long How do I show the time as "elapsed" instead of "remaining"?

    bug 
    opened by fshif 1
  • Jitpack build for dev branch not working

    Jitpack build for dev branch not working

    Trying to get a dependency for the dev branch via Jitpack fails during compile:

    > Task :compileKotlin FAILED
    2 actionable tasks: 1 executed, 1 up-to-date
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
    e: /home/jitpack/build/src/main/kotlin/dev/cbyrne/kdiscordipc/core/socket/impl/UnixSocket.kt: (8, 17): Unresolved reference: UnixDomainSocketAddress
    e: /home/jitpack/build/src/main/kotlin/dev/cbyrne/kdiscordipc/core/socket/impl/UnixSocket.kt: (13, 68): Unresolved reference: UNIX
    e: /home/jitpack/build/src/main/kotlin/dev/cbyrne/kdiscordipc/core/socket/impl/UnixSocket.kt: (19, 24): Unresolved reference: UnixDomainSocketAddress
    e: /home/jitpack/build/src/main/kotlin/dev/cbyrne/kdiscordipc/core/util/constants.kt: (16, 64): Unresolved reference: pid
    
    FAILURE: Build failed with an exception.
    
    opened by Mr-Pine 1
  • Add support for Voice Settings

    Add support for Voice Settings

    This PR adds support for Voice Settings by

    • Implementing the GET_VOICE_SETTINGS and SET_VOICE_SETTINGS commands
    • Implementing the VOICE_SETTINGS_CHANGED Event
    • Implementing the authorization flow enabling different scopes by adding the AUTHORIZE command
    • Renamed getOAuthToken to authenticate to represent the actual command name
    • Changed example project to contain getting and setting voice settings
    • Added a gitignored secrets.kt containing client id and secret
    opened by Mr-Pine 1
  • Allow CoroutineScope to be provided

    Allow CoroutineScope to be provided

    I would love to provide different CoroutineScope with different Dispatcher.

    This change allows developers to provide coroutineScope to be used by the library.

    opened by cyoung06 0
  • Fix: text fields not allowed to be empty or have <2 characters

    Fix: text fields not allowed to be empty or have <2 characters

    See the following issues for context:

    • https://github.com/Almighty-Alpaca/JetBrains-Discord-Integration/issues/252
    • https://github.com/Almighty-Alpaca/JetBrains-Discord-Integration/issues/279
    opened by dnbln 0
  • IOException when disconnecting while sending an activity

    IOException when disconnecting while sending an activity

    This exception is thrown inside a Flow, which means there's no way to handle or ignore it as a user.

    	java.io.IOException: The pipe is being closed
    	at java.base/java.io.RandomAccessFile.writeBytes(Native Method)
    	at java.base/java.io.RandomAccessFile.write(RandomAccessFile.java:546)
    	at dev.cbyrne.kdiscordipc.core.socket.impl.WindowsSocket.write(WindowsSocket.kt:48)
    	at dev.cbyrne.kdiscordipc.core.socket.handler.SocketHandler$1.invokeSuspend(SocketHandler.kt:52)
    	at dev.cbyrne.kdiscordipc.core.socket.handler.SocketHandler$1.invoke(SocketHandler.kt)
    	at dev.cbyrne.kdiscordipc.core.socket.handler.SocketHandler$1.invoke(SocketHandler.kt)
    	at kotlinx.coroutines.flow.FlowKt__TransformKt$onEach$$inlined$unsafeTransform$1$2.emit(Collect.kt:136)
    	at kotlinx.coroutines.flow.SharedFlowImpl.collect(SharedFlow.kt:351)
    	at kotlinx.coroutines.flow.SharedFlowImpl$collect$1.invokeSuspend(SharedFlow.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
    
    opened by Almighty-Alpaca 1
Owner
Conor Byrne
🧑🏻‍💻 he/him
Conor Byrne
A simplified interface for interacting with in-memory cache implementations on the JVM

This library provides a simplified interface for interacting with in-memory cache implementations on the JVM. Think: "SLF4J but for caching"

null 5 Nov 29, 2022
A discord bot made in Kotlin powered by JDA and Realms.

A discord bot made in Kotlin powered by JDA and Realms.

null 1 Jun 30, 2022
Blog implemented via the Storyblok Kotlin Multiplatform SDK (Android, JVM)

storyblok-mp-SDK-blog ... a showcase of using the Storyblok Kotlin Multiplatform Client to build a blog application (Android, JVM) What's included ??

Mike Penz 5 Sep 28, 2022
BlurHash support for iOS, Android and JVM via Kotlin Multiplatform

blurhash A Kotlin Multiplatform library to use blurhash in your Android App, iOS / Mac App & JVM Backend. Android iOS JVM Why? If you've tried using b

Niklas Baudy 19 Nov 17, 2022
🤝 Link your Fabric server and Discord with ease!

Fabric2Discord Link your Fabric server and Discord with ease! ?? Getting Started I wrote few helpful articles about this mod, so if you need help you

Igor Ryzhenkov 10 Oct 25, 2022
It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

Shutter-Android It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android. What is Shutter? Shutter is an Androi

Levi Bostian 56 Oct 3, 2022
A pair of applications provide a direct means of integrating with one another via application programming interfaces (APIs)

What is a native integration? It's when a pair of applications provide a direct means of integrating with one another via application programming interfaces (APIs). Once integrated, data can flow between the apps and become more readily available to your employees.

Behruz Hurramov 2 Jan 17, 2022
Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs

Zipline This library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it possible to do continuous deploymen

Cash App 1.5k Dec 30, 2022
A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

common sense OSS 0 Jan 20, 2022
Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

Gérard Paligot 98 Dec 15, 2022
[Android Library] A SharedPreferences helper library to save and fetch the values easily.

Preference Helper A SharedPreferences helper library to save and fetch the values easily. Featured in Use in your project Add this to your module's bu

Naveen T P 13 Apr 4, 2020
Kotlin library for Android

KAndroid Kotlin library for Android providing useful extensions to eliminate boilerplate code in Android SDK and focus on productivity. Download Downl

Paweł Gajda 890 Nov 13, 2022
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

EasyPermissions-ktx Kotlin version of the popular googlesample/easypermissions wrapper library to simplify basic system permissions logic on Android M

Madalin Valceleanu 326 Dec 23, 2022
Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

SpinnerDialog Android Spinner Dialog Library, Use for single or multi selection of choice Android UI Download To include SpinnerDialog in your project

Hamza Khan 55 Sep 15, 2022
A Kotlin library for reactive and boilerplate-free SharedPreferences in Android

KPreferences A Kotlin library for reactive and boilerplate-free Shared Preferences in Android. With KPreferences you can use Kotlin's marvelous delega

Mohamad Amin Mohamadi 19 Dec 16, 2020
AbstractMvp 0.8 0.0 Kotlin is a library that provides abstract components for MVP architecture realization, with problems solutions that are exist in classic MVP.

MinSDK 14+ AbstractMvp AbstractMvp is a library that provides abstract components for MVP architecture realization, with problems solutions that are e

Robert 12 Apr 5, 2022
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

Mike 112 Dec 9, 2022
A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Andrew Reed 220 Dec 28, 2022