Skip to content

Commit 7e7ad56

Browse files
committed
meowcord/wsapi: send standard Op 1 heartbeat for bot sessions
Sync from beeper/discordgo@8051e14
1 parent 1fbf127 commit 7e7ad56

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ require (
5050
maunium.net/go/mauflag v1.0.0 // indirect
5151
)
5252

53-
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20260803125648-0ee5f692e9eb
53+
replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20260808090638-8051e14a4471
5454

5555
replace github.com/imroc/req/v3 => github.com/beeper/req/v3 v3.0.0-20260703124114-47a4e2aa147e

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
44
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
55
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
66
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
7-
github.com/beeper/discordgo v0.0.0-20260803125648-0ee5f692e9eb h1:pryU/1vc9mz0+EmBAv9BXYQHuLCw7LXa5PJ10x/RbA0=
8-
github.com/beeper/discordgo v0.0.0-20260803125648-0ee5f692e9eb/go.mod h1:ATQaN5n/cY4rxHFSsp4UOB1cxf4gdtreFt5NXmlVTmc=
7+
github.com/beeper/discordgo v0.0.0-20260808090638-8051e14a4471 h1:yeMnzGxjXjRNbUo5cwP5+XGNJUPHX+yFjvD/PbGvTJc=
8+
github.com/beeper/discordgo v0.0.0-20260808090638-8051e14a4471/go.mod h1:ATQaN5n/cY4rxHFSsp4UOB1cxf4gdtreFt5NXmlVTmc=
99
github.com/beeper/req/v3 v3.0.0-20260703124114-47a4e2aa147e h1:CpRFpusGLZVcc+R1Im50QYI9JeEQuwudVMkUkRvZpuU=
1010
github.com/beeper/req/v3 v3.0.0-20260703124114-47a4e2aa147e/go.mod h1:pH5qbsMNeaNpCOlozJoLRuLfSxEYGp9uWEG5j6zogNQ=
1111
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=

pkg/meowcord/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ to):
4545
meowcord incorporates the following commits and all of their ancestors:
4646

4747
- [beeper/discordgo][beeper-discordgo]:
48-
[`0ee5f692e9eb3a3135cbd139d8c15bc6434a8f41`](https://github.com/beeper/discordgo/commit/0ee5f692e9eb3a3135cbd139d8c15bc6434a8f41)
49-
(authored 2026-08-03)
48+
[`8051e14a447170269a615268c4d83b55e6fcf2fe`](https://github.com/beeper/discordgo/commit/8051e14a447170269a615268c4d83b55e6fcf2fe)
49+
(authored 2026-08-08)
5050
- [bwmarrin/discordgo][bwmarrin-discordgo]:
5151
[`f43dd94faaacd5b163e9e783f14b5bd8be639fc9`](https://github.com/bwmarrin/discordgo/commit/f43dd94faaacd5b163e9e783f14b5bd8be639fc9)
5252
(authored 2026-02-14)

pkg/meowcord/wsapi.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ func (s *Session) listen(ctx context.Context, wsConn *websocket.Conn, listening
350350
}
351351
}
352352

353+
type heartbeatOp struct {
354+
Op int `json:"op"`
355+
Data int64 `json:"d"`
356+
}
357+
358+
func (s *Session) newHeartbeatOp(seq int64) interface{} {
359+
if s.IsUser {
360+
return newForegroundedQosHeartbeatOp(seq)
361+
}
362+
return heartbeatOp{Op: 1, Data: seq}
363+
}
364+
353365
func newForegroundedQosHeartbeatOp(seq int64) qosHeartbeatOp {
354366
return qosHeartbeatOp{
355367
Op: 40,
@@ -428,7 +440,7 @@ func (s *Session) heartbeat(ctx context.Context, wsConn *websocket.Conn, listeni
428440
s.log(LogDebug, "sending gateway websocket heartbeat seq %d", sequence)
429441
s.wsMutex.Lock()
430442
s.LastHeartbeatSent = time.Now().UTC()
431-
err = wsjson.Write(ctx, wsConn, newForegroundedQosHeartbeatOp(sequence))
443+
err = wsjson.Write(ctx, wsConn, s.newHeartbeatOp(sequence))
432444
s.wsMutex.Unlock()
433445
if err != nil || time.Now().UTC().Sub(last) > (heartbeatInterval*FailedHeartbeatAcks) {
434446
if err != nil {
@@ -794,7 +806,7 @@ func (s *Session) onEvent(messageType websocket.MessageType, message []byte, isO
794806
if e.Operation == 1 {
795807
s.log(LogInformational, "sending heartbeat in response to Op1")
796808
s.wsMutex.Lock()
797-
err = wsjson.Write(s.wsConnCtx, s.wsConn, newForegroundedQosHeartbeatOp(atomic.LoadInt64(s.sequence)))
809+
err = wsjson.Write(s.wsConnCtx, s.wsConn, s.newHeartbeatOp(atomic.LoadInt64(s.sequence)))
798810
s.wsMutex.Unlock()
799811
if err != nil {
800812
s.log(LogError, "error sending heartbeat in response to Op1")

0 commit comments

Comments
 (0)