Coder Social home page Coder Social logo

jagrosh / discordipc Goto Github PK

View Code? Open in Web Editor NEW
137.0 8.0 46.0 55 KB

Connect locally to the Discord client using IPC for a subset of RPC features like Rich Presence and Activity Join/Spectate

License: Apache License 2.0

Java 100.00%
discord ipc java rpc rich presence activity join spectate

discordipc's Issues

unicode support issue

Code that i use:

import com.jagrosh.discordipc.IPCListener
import com.jagrosh.discordipc.entities.RichPresence
import com.jagrosh.discordipc.entities.pipe.PipeStatus
import java.time.OffsetDateTime

fun main() {
    try {
        val client = IPCClient(client_id) //replaced for secret
        val rpcBuilder = RichPresence.Builder()
            .setLargeImage("default", "asdf")
            .setSmallImage("minecraft_logo", "asdf")
        client.connect()
        rpcBuilder.setStartTimestamp(OffsetDateTime.now())
        val richPresence = rpcBuilder
            .setDetails("asdf")
            .setState("하이요")
            .build()
        client.sendRichPresence(richPresence)
    }
}
main()

Result:
image
state with unicode string(in this case, "하이요") got seems broken. tried

.setState(String("하이요".toByteArray(), Charset.forName("euc-kr")))

and

.setState(String("하이요".toByteArray(), Charset.forName("cp949")))

but it didn't work for me :(

FileNotFoundException: `\\?\pipe\discord-ipc-0 (All pipe instances are busy)`

Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: \\?\pipe\discord-ipc-0 (All pipe instances are busy)
	at com.jagrosh.discordipc.entities.pipe.WindowsPipe.<init>(WindowsPipe.java:45)
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:158)
	at com.jagrosh.discordipc.entities.pipe.Pipe.openPipe(Pipe.java:67)
	at com.jagrosh.discordipc.IPCClient.connect(IPCClient.java:116)
	at xxAROX.PresenceMan.Application.Bootstrap.main(Bootstrap.java:31)
Caused by: java.io.FileNotFoundException: \\?\pipe\discord-ipc-0 (All pipe instances are busy)
	at java.base/java.io.RandomAccessFile.open0(Native Method)
	at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:344)
	at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:259)
	at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:213)
	at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:127)
	at com.jagrosh.discordipc.entities.pipe.WindowsPipe.<init>(WindowsPipe.java:43)
	... 4 more

Process finished with exit code 1

README example is broken in Ubuntu

object Main {
    @JvmStatic
    fun main(args: Array<String>) {
        val client = IPCClient(384465696496549888L)
        client.setListener(object : IPCListener {
            override fun onReady(client: IPCClient?) {
                val builder = RichPresence.Builder()
                builder.setState("West of House")
                    .setDetails("Frustration level: Over 9000")
                    .setStartTimestamp(OffsetDateTime.now())
                    .setLargeImage("canary-large", "Discord Canary")
                    .setSmallImage("ptb-small", "Discord PTB")
                    .setParty("party1234", 1, 6)
                    .setMatchSecret("xyzzy")
                    .setJoinSecret("join")
                    .setSpectateSecret("look")
                client!!.sendRichPresence(builder.build())
            }
        })
        client.connect()
    }
}
Exception in thread "main" java.lang.RuntimeException: java.net.SocketException: Socket file not found: /run/user/1000/snap.intellij-idea-community/discord-ipc-0
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:167)
	at com.jagrosh.discordipc.entities.pipe.Pipe.openPipe(Pipe.java:67)
	at com.jagrosh.discordipc.IPCClient.connect(IPCClient.java:116)
	at com.mrpowergamerbr.powerrp.Main.main(Main.kt:34)
Caused by: java.net.SocketException: Socket file not found: /run/user/1000/snap.intellij-idea-community/discord-ipc-0
	at org.newsclub.net.unix.AFUNIXSocketImpl.validateSocketFile(AFUNIXSocketImpl.java:164)
	at org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:154)
	at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:138)
	at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:117)
	at com.jagrosh.discordipc.entities.pipe.UnixPipe.<init>(UnixPipe.java:46)
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:163)
	... 3 more

I'm running the code directly from IDEA, maybe that's why it isn't working? Discord's IPC socket is in ./run/user/1000/discord-ipc-0 on my system

No support for OSX

DiscordIPC doesn't work with OSX, keep throwing NoDiscordClientException

Gradle not finding the project

Whenever I try to use this project with gradle, it cannot find it.

Heres the error:
Could not find com.jagrosh:DiscordIPC:0.4. Searched in the following locations: - file:/Users/myuser/.gradle/caches/forge_gradle/bundeled_repo/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.pom - file:/Users/myuser/.gradle/caches/forge_gradle/bundeled_repo/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.jar - https://files.minecraftforge.net/maven/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.pom - https://files.minecraftforge.net/maven/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.jar - https://libraries.minecraft.net/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.jar - https://repo.maven.apache.org/maven2/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.pom - https://repo.maven.apache.org/maven2/com/jagrosh/DiscordIPC/0.4/DiscordIPC-0.4.jar Required by: project :

app crashed when discord isn't opened

How to fix it that the app crashes when discord isn't opened?

`IPCClient client = new IPCClient(/ID not for you/);
client.setListener(new IPCListener() {
private Minecraft mc;

			@Override
			public void onReady(IPCClient client) {
				RichPresence.Builder builder = new RichPresence.Builder();
				builder.setState("Versie: " + getMinecraft().getVersion())
						.setDetails("Naam: " + getMinecraft().getSession().getUsername())
						.setStartTimestamp(OffsetDateTime.now())
						.setLargeImage("monkey-logo", "Client Side Anicheat");
				client.sendRichPresence(builder.build());
			}
		});
		try {
			client.connect();
		} catch (NoDiscordClientException e) {
			e.printStackTrace();
		}`

IPC Connect

How do you connect this to the app you want to use (like IntelliJ IDEA)

Error while closing the stream in IPCClient#close

Hello @jagrosh

I'm receiving this error while calling the function IPCClient#close which it should close everything safety but it appears an exception that I can't handle it by try and catch because it's in a different thread. So, I hope there's a solution for this error.

21:25:26.238 [Thread-11] ERROR com.jagrosh.discordipc.IPCClient - Reading thread encountered an IOException
java.io.IOException: Stream Closed
    at java.io.RandomAccessFile.length(Native Method)
    at com.jagrosh.discordipc.entities.pipe.WindowsPipe.read(WindowsPipe.java:56)
    at com.jagrosh.discordipc.IPCClient.lambda$startReading$0(IPCClient.java:350)
    at java.lang.Thread.run(Thread.java:748)

Can't connect to Discord because it's not possible to create a Pipe that works either

So this is a pretty strange error. It's my first time working with DiscordIPC, so it's possible I'm just not doing something. However, it seems to be the fault of a class here. Basically, I'm working on a Minecraft mod that will work in conjunction with the server I run, and one of its functions is to show Rich Presence. However, when I try to start the game using the mod, it crashes trying to startup.
Here's what the crash report says the error is:

...
Caused by: java.lang.RuntimeException: org.newsclub.net.unix.AFUNIXSocketException: Cannot find method "setCreated" in java.net.Socket. Unsupported JVM?
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:167)
	at com.jagrosh.discordipc.entities.pipe.Pipe.openPipe(Pipe.java:67)
	at com.jagrosh.discordipc.IPCClient.connect(IPCClient.java:116)
	at com.playbuilderverse.builderversetweaks.BuilderverseTweaks.connect(BuilderverseTweaks.java:29)
	at com.playbuilderverse.builderversetweaks.BuilderverseTweaks.onInitialize(BuilderverseTweaks.java:17)
	at net.fabricmc.loader.impl.entrypoint.EntrypointUtils.invoke0(EntrypointUtils.java:47)
	... 12 more
Caused by: org.newsclub.net.unix.AFUNIXSocketException: Cannot find method "setCreated" in java.net.Socket. Unsupported JVM?
	at org.newsclub.net.unix.NativeUnixSocket.setCreated(Native Method)
	at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
	at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)
	at com.jagrosh.discordipc.entities.pipe.UnixPipe.<init>(UnixPipe.java:45)
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:163)
	... 17 more

Not sure if it's possible that I'm running an unsupported JVM, because I'm running it straight from a build configuration in IntelliJ IDEA which is using Java 17. I can send the full crash report, just ask me for it.

@jagrosh

throws org.newsclub.net.unix.AFUNIXSocketException in macOS High Sierra

Exception in thread "main" java.lang.RuntimeException: org.newsclub.net.unix.AFUNIXSocketException: Cannot find method "setCreated" in java.net.Socket. Unsupported JVM?
at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:167)
at com.jagrosh.discordipc.entities.pipe.Pipe.openPipe(Pipe.java:67)
at com.jagrosh.discordipc.IPCClient.connect(IPCClient.java:116)
at Main.main(Main.java:22)
Caused by: org.newsclub.net.unix.AFUNIXSocketException: Cannot find method "setCreated" in java.net.Socket. Unsupported JVM?
at org.newsclub.net.unix.NativeUnixSocket.setCreated(Native Method)
at org.newsclub.net.unix.AFUNIXSocket.(AFUNIXSocket.java:36)
at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)
at com.jagrosh.discordipc.entities.pipe.UnixPipe.(UnixPipe.java:45)
at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:163)
... 3 more

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.