-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.go
More file actions
40 lines (33 loc) · 913 Bytes
/
Copy pathrpc.go
File metadata and controls
40 lines (33 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"log/slog"
"time"
"github.com/lmittmann/tint"
"github.com/xeyossr/go-discordrpc/client"
)
var loggedIn = false
// Logout closes the socket; the next Login redials to recover a dropped connection
var rpcClient = client.NewClient(discordAppId)
func getRPCLogCtx() *slog.Logger {
return slog.With("loggedIn", loggedIn)
}
func login() {
if loggedIn {
return
}
if err := rpcClient.Login(); err != nil {
getRPCLogCtx().Warn("Could not login to Discord.", tint.Err(err))
logout()
return
}
loggedIn = true
getRPCLogCtx().Debug("Successfully logged into Discord's RPC Server.")
}
func logout() {
if err := rpcClient.Logout(); err != nil {
getRPCLogCtx().Debug("Error closing Discord RPC connection.", tint.Err(err))
}
loggedIn = false
ts = time.Time{} // Force presence re-send on next login
getRPCLogCtx().Debug("Successfully logged out of Discord's RPC Server.")
}