-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.go
More file actions
38 lines (32 loc) · 853 Bytes
/
rpc.go
File metadata and controls
38 lines (32 loc) · 853 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
package main
import (
log "github.com/sirupsen/logrus"
"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() *log.Entry {
return log.WithFields(log.Fields{
"loggedIn": loggedIn,
})
}
func login() {
if loggedIn {
return
}
if err := rpcClient.Login(); err != nil {
getRPCLogCtx().Warnln("Could not login to Discord.")
logout()
return
}
loggedIn = true
getRPCLogCtx().Debugln("Successfully logged into Discord's RPC Server.")
}
func logout() {
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.")
}