Skip to content

Port Discord RPC from rich-go to go-discordrpc#73

Merged
twangodev merged 2 commits into
mainfrom
port-discord-rpc-axrona
May 24, 2026
Merged

Port Discord RPC from rich-go to go-discordrpc#73
twangodev merged 2 commits into
mainfrom
port-discord-rpc-axrona

Conversation

@twangodev
Copy link
Copy Markdown
Owner

@twangodev twangodev commented May 24, 2026

Switches Discord RPC to go-discordrpc for proper broken-pipe error handling (event-driven reconnect instead of the 3-minute timer hack); relicenses to GPL-3.0 since the new dependency is GPL.

Summary by CodeRabbit

  • Chores

    • Updated project license to GNU General Public License v3
  • Bug Fixes

    • Improved Discord RPC connection reliability with automatic reconnection on failures

Review Change Stack

twangodev added 2 commits May 23, 2026 21:19
rich-go's SetActivity could never report a dead pipe (it ignored both the
write error and the IPC response and always returned nil), so v1.3.1 worked
around it with a blind 3-minute reconnect timer.

go-discordrpc does a read-after-write and returns real errors, so reconnection
is now event-driven: on a failed SetActivity we drop the socket and redial on
the next cycle. Removes lastLoginTime/connectionRefreshInterval and the
timer-driven timestamp reset.
go-discordrpc is GPL-3.0; statically linking it into the release binaries
requires the project to be GPL-compatible. Switch LICENSE to verbatim GPLv3.
Copilot AI review requested due to automatic review settings May 24, 2026 04:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

📝 Walkthrough

Walkthrough

The PR migrates Discord RPC integration from the rich-go library to go-discordrpc, updates the project license from MIT to GPLv3, refactors RPC client initialization and lifecycle management, and adds automatic reconnection logic when activity status updates fail.

Changes

Discord RPC Library Migration from rich-go to go-discordrpc

Layer / File(s) Summary
License and Dependency Update
LICENSE, go.mod
Project license replaced from MIT to GPLv3. Dependency swap: github.com/hugolgst/rich-go removed, github.com/xeyossr/go-discordrpc v1.1.0 added in go.mod.
RPC Client Lifecycle (Login and Logout)
rpc.go
RPC client is initialized from discordAppId using go-discordrpc. Login now guards against repeat logins via loggedIn flag, attempts rpcClient.Login(), and triggers logout() on failure. Logout calls rpcClient.Logout() with debug-level error logging and state reset.
Activity Type Import Update
activity.go
Client import switched from github.com/hugolgst/rich-go/client to github.com/xeyossr/go-discordrpc/client for Activity type definition.
Activity Integration and Reconnection Logic
cycler.go
RPC activity setting changed to use rpcClient.SetActivity() with two sequential attempts (base then detailed payload). When both attempts fail, the code logs a reconnection warning, calls logout(), and resets the presence timestamp to force re-login on the next cycle.

Sequence Diagram(s)

sequenceDiagram
  participant keepStatus
  participant rpcClient
  participant Discord
  participant App as App State
  keepStatus->>rpcClient: SetActivity(basic payload)
  alt Attempt 1 Success
    rpcClient->>Discord: Update presence
    rpcClient-->>keepStatus: success
  else Attempt 1 Fails
    keepStatus->>rpcClient: SetActivity(detailed payload with songLink)
    alt Attempt 2 Success
      rpcClient->>Discord: Update presence
      rpcClient-->>keepStatus: success
    else Both Fail
      keepStatus->>keepStatus: log "will reconnect" warning
      keepStatus->>rpcClient: Logout()
      rpcClient->>Discord: Close connection
      keepStatus->>App: reset ts to 0
      Note over App: Next keepStatus cycle will re-login
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A migration swift, with license renewed,
Rich-go to Discord RPC, refactored and brewed!
When activity stumbles, reconnect with grace,
Bouncing right back to that Discord place! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: migrating the Discord RPC implementation from rich-go to go-discordrpc, which is the primary purpose of the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch port-discord-rpc-axrona

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​xeyossr/​go-discordrpc@​v1.1.010010010010070

View full report

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Discord Rich Presence integration from hugolgst/rich-go to xeyossr/go-discordrpc, aiming to improve handling of dropped IPC connections and remove the previous periodic reconnect workaround. It also updates the project license to GPL-3.0 to align with the new dependency’s license.

Changes:

  • Replaced rich-go RPC usage with a shared go-discordrpc client (rpcClient) and updated login/logout flow.
  • Updated presence update loop to drop/reconnect the RPC connection on SetActivity failures instead of using a periodic refresh timer.
  • Switched repository license from MIT to GPL-3.0 and updated Go module dependencies accordingly.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rpc.go Introduces a persistent go-discordrpc client and updates login/logout behavior and logging.
cycler.go Updates presence-setting calls to use rpcClient and adjusts reconnect-on-error logic.
activity.go Switches the Activity/Button/Timestamps types import to go-discordrpc.
go.mod Removes rich-go, adds go-discordrpc.
go.sum Updates checksums to reflect the dependency switch.
LICENSE Replaces MIT text with GPL-3.0 license text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rpc.go
Comment on lines +23 to +26
if err := rpcClient.Login(); err != nil {
getRPCLogCtx().Warnln("Could not login to Discord.")
logout()
} else {
loggedIn = true
getRPCLogCtx().Debugln("Successfully logged into Discord's RPC Server.")
return
Comment thread rpc.go
Comment on lines +33 to 38
if err := rpcClient.Logout(); err != nil {
getRPCLogCtx().WithError(err).Debugln("Error closing Discord RPC connection.")
}
loggedIn = false
getRPCLogCtx().Debugln("Successfully logged out of Discord's RPC Server.")
}
Comment thread cycler.go
Comment on lines 26 to +28
if err != nil {
log.Warnln("Failed to keep activity.")
log.Warnln("Failed to keep activity. Dropping connection to reconnect next cycle.")
logout()
Comment thread cycler.go
Comment on lines 59 to 61
if err1 != nil {
log.Info("Failed to set base RPC. Retrying with detailed payload.")
} else {
Comment thread cycler.go
Comment on lines 72 to 74
} else {
log.Info("Failed to set detailed RPC.")
}
Comment thread cycler.go
Comment on lines 68 to +71
if err1 != nil {
log.Warnln("Both attempts to set RPC failed.")
log.Warnln("Both attempts to set RPC failed. Reconnecting next cycle.")
logout()
ts = time.Time{}
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
rpc.go (1)

32-38: 💤 Low value

Consider guarding logout() with a loggedIn check to avoid redundant operations.

Currently logout() unconditionally calls rpcClient.Logout() even if not logged in. While likely harmless if the library handles it gracefully, adding a guard similar to login() would be more consistent and avoid unnecessary IPC calls.

♻️ Optional: Add loggedIn guard to logout()
 func logout() {
+	if !loggedIn {
+		return
+	}
 	if err := rpcClient.Logout(); err != nil {
 		getRPCLogCtx().WithError(err).Debugln("Error closing Discord RPC connection.")
 	}
 	loggedIn = false
 	getRPCLogCtx().Debugln("Successfully logged out of Discord's RPC Server.")
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rpc.go` around lines 32 - 38, Add a guard at the start of logout() to return
early when loggedIn is false to avoid calling rpcClient.Logout() unnecessarily;
specifically, check the package-level boolean loggedIn and if it's false simply
log or return, otherwise proceed to call rpcClient.Logout(), set loggedIn =
false and log via getRPCLogCtx(), keeping the existing error handling around
rpcClient.Logout().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@rpc.go`:
- Around line 32-38: Add a guard at the start of logout() to return early when
loggedIn is false to avoid calling rpcClient.Logout() unnecessarily;
specifically, check the package-level boolean loggedIn and if it's false simply
log or return, otherwise proceed to call rpcClient.Logout(), set loggedIn =
false and log via getRPCLogCtx(), keeping the existing error handling around
rpcClient.Logout().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9f9d3b5-eb00-42db-b1c2-d4c49d1e48f4

📥 Commits

Reviewing files that changed from the base of the PR and between 4b75bc6 and 3533cb6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • LICENSE
  • activity.go
  • cycler.go
  • go.mod
  • rpc.go

@twangodev twangodev merged commit ae288ab into main May 24, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants