mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-18 01:50:50 +00:00
fix: fix eventsub breaking because of channel.follow v1 deprecation
This commit is contained in:
parent
8304afa89e
commit
86a86799e5
7 changed files with 44 additions and 13 deletions
|
@ -3,6 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/strimertul/strimertul/utils"
|
||||||
|
|
||||||
"github.com/strimertul/strimertul/database"
|
"github.com/strimertul/strimertul/database"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
@ -16,7 +18,7 @@ func cliImport(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fatalError(err, "could not open import file for reading")
|
return fatalError(err, "could not open import file for reading")
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer utils.Close(file, logger)
|
||||||
inStream = file
|
inStream = file
|
||||||
}
|
}
|
||||||
var entries map[string]string
|
var entries map[string]string
|
||||||
|
@ -47,7 +49,7 @@ func cliRestore(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fatalError(err, "could not open import file for reading")
|
return fatalError(err, "could not open import file for reading")
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer utils.Close(file, logger)
|
||||||
inStream = file
|
inStream = file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ func cliExport(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fatalError(err, "could not open output file for writing")
|
return fatalError(err, "could not open output file for writing")
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer utils.Close(file, logger)
|
||||||
outStream = file
|
outStream = file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/strimertul/strimertul/utils"
|
||||||
|
|
||||||
"github.com/cockroachdb/pebble"
|
"github.com/cockroachdb/pebble"
|
||||||
kv "github.com/strimertul/kilovolt/v9"
|
kv "github.com/strimertul/kilovolt/v9"
|
||||||
pebble_driver "github.com/strimertul/kv-pebble"
|
pebble_driver "github.com/strimertul/kv-pebble"
|
||||||
|
@ -50,7 +52,7 @@ func (p *PebbleDatabase) Hub() *kv.Hub {
|
||||||
func (p *PebbleDatabase) Close() error {
|
func (p *PebbleDatabase) Close() error {
|
||||||
err := p.db.Close()
|
err := p.db.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not close database: %w", err)
|
return fmt.Errorf("could not close database: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -89,8 +91,12 @@ func (p *PebbleDatabase) Restore(file io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PebbleDatabase) Backup(file io.Writer) error {
|
func (p *PebbleDatabase) Backup(file io.Writer) error {
|
||||||
iter := p.db.NewSnapshot().NewIter(&pebble.IterOptions{})
|
snapshot := p.db.NewSnapshot()
|
||||||
defer iter.Close()
|
defer utils.Close(snapshot, p.logger)
|
||||||
|
|
||||||
|
iter := snapshot.NewIter(&pebble.IterOptions{})
|
||||||
|
defer utils.Close(iter, p.logger)
|
||||||
|
|
||||||
out := make(map[string]string)
|
out := make(map[string]string)
|
||||||
for iter.First(); iter.Valid(); iter.Next() {
|
for iter.First(); iter.Valid(); iter.Next() {
|
||||||
val, err := iter.ValueAndErr()
|
val, err := iter.ValueAndErr()
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -20,7 +20,7 @@ require (
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/nicklaw5/helix/v2 => github.com/ashkeel/helix/v2 v2.11.0-ws
|
replace github.com/nicklaw5/helix/v2 => github.com/ashkeel/helix/v2 v2.20.0-ws
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/DataDog/zstd v1.5.2 // indirect
|
github.com/DataDog/zstd v1.5.2 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -22,8 +22,8 @@ github.com/apenwarr/fixconsole v0.0.0-20191012055117-5a9f6489cc29/go.mod h1:JYWa
|
||||||
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab h1:CMGzRRCjnD50RjUFSArBLuCxiDvdp7b8YPAcikBEQ+k=
|
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab h1:CMGzRRCjnD50RjUFSArBLuCxiDvdp7b8YPAcikBEQ+k=
|
||||||
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab/go.mod h1:nfFtvHn2Hgs9G1u0/J6LHQv//EksNC+7G8vXmd1VTJ8=
|
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab/go.mod h1:nfFtvHn2Hgs9G1u0/J6LHQv//EksNC+7G8vXmd1VTJ8=
|
||||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||||
github.com/ashkeel/helix/v2 v2.11.0-ws h1:AG2mWRs7qfhigv+UcNDkjJaSSbtiJIM1njlwLu7FVa4=
|
github.com/ashkeel/helix/v2 v2.20.0-ws h1:IvwMHs4PBCoVgu0IVlTZGyQG8h40zBY/FYmRXGcfEco=
|
||||||
github.com/ashkeel/helix/v2 v2.11.0-ws/go.mod h1:zZcKsyyBWDli34x3QleYsVMiiNGMXPAEU5NjsiZDtvY=
|
github.com/ashkeel/helix/v2 v2.20.0-ws/go.mod h1:zZcKsyyBWDli34x3QleYsVMiiNGMXPAEU5NjsiZDtvY=
|
||||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (c *Client) GetAuthorizationURL() string {
|
||||||
}
|
}
|
||||||
return c.API.GetAuthorizationURL(&helix.AuthorizationURLParams{
|
return c.API.GetAuthorizationURL(&helix.AuthorizationURLParams{
|
||||||
ResponseType: "code",
|
ResponseType: "code",
|
||||||
Scopes: []string{"bits:read channel:read:subscriptions channel:read:redemptions channel:read:polls channel:read:predictions channel:read:hype_train user_read chat:read chat:edit channel:moderate whispers:read whispers:edit moderator:read:chatters"},
|
Scopes: []string{"bits:read channel:read:subscriptions channel:read:redemptions channel:read:polls channel:read:predictions channel:read:hype_train user_read chat:read chat:edit channel:moderate whispers:read whispers:edit moderator:read:chatters moderator:read:followers"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/strimertul/strimertul/utils"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/nicklaw5/helix/v2"
|
"github.com/nicklaw5/helix/v2"
|
||||||
|
@ -30,7 +32,7 @@ func (c *Client) connectWebsocket(url string, userClient *helix.Client) (string,
|
||||||
c.logger.Error("could not connect to eventsub ws", zap.Error(err))
|
c.logger.Error("could not connect to eventsub ws", zap.Error(err))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer connection.Close()
|
defer utils.Close(connection, c.logger)
|
||||||
|
|
||||||
received := make(chan []byte, 10)
|
received := make(chan []byte, 10)
|
||||||
wsErr := make(chan error, 1)
|
wsErr := make(chan error, 1)
|
||||||
|
@ -163,7 +165,7 @@ func (c *Client) addSubscriptionsForSession(userClient *helix.Client, session st
|
||||||
Condition: topicCondition(topic, c.User.ID),
|
Condition: topicCondition(topic, c.User.ID),
|
||||||
})
|
})
|
||||||
if sub.Error != "" || sub.ErrorMessage != "" {
|
if sub.Error != "" || sub.ErrorMessage != "" {
|
||||||
c.logger.Error("subscription error", zap.String("err", sub.Error), zap.String("message", sub.ErrorMessage))
|
c.logger.Error("subscription error", zap.String("topic", topic), zap.String("topic-version", version), zap.String("err", sub.Error), zap.String("message", sub.ErrorMessage))
|
||||||
return fmt.Errorf("%s: %s", sub.Error, sub.ErrorMessage)
|
return fmt.Errorf("%s: %s", sub.Error, sub.ErrorMessage)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,6 +182,11 @@ func topicCondition(topic string, id string) helix.EventSubCondition {
|
||||||
return helix.EventSubCondition{
|
return helix.EventSubCondition{
|
||||||
ToBroadcasterUserID: id,
|
ToBroadcasterUserID: id,
|
||||||
}
|
}
|
||||||
|
case "channel.follow":
|
||||||
|
return helix.EventSubCondition{
|
||||||
|
BroadcasterUserID: id,
|
||||||
|
ModeratorUserID: id,
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return helix.EventSubCondition{
|
return helix.EventSubCondition{
|
||||||
BroadcasterUserID: id,
|
BroadcasterUserID: id,
|
||||||
|
@ -218,7 +225,7 @@ type EventSubMetadata struct {
|
||||||
|
|
||||||
var subscriptionVersions = map[string]string{
|
var subscriptionVersions = map[string]string{
|
||||||
helix.EventSubTypeChannelUpdate: "1",
|
helix.EventSubTypeChannelUpdate: "1",
|
||||||
helix.EventSubTypeChannelFollow: "1",
|
helix.EventSubTypeChannelFollow: "2",
|
||||||
helix.EventSubTypeChannelSubscription: "1",
|
helix.EventSubTypeChannelSubscription: "1",
|
||||||
helix.EventSubTypeChannelSubscriptionGift: "1",
|
helix.EventSubTypeChannelSubscriptionGift: "1",
|
||||||
helix.EventSubTypeChannelSubscriptionMessage: "1",
|
helix.EventSubTypeChannelSubscriptionMessage: "1",
|
||||||
|
|
16
utils/deferlogger.go
Normal file
16
utils/deferlogger.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Close(res io.Closer, logger *zap.Logger) {
|
||||||
|
err := res.Close()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("could not close resource", zap.String("name", reflect.TypeOf(res).String()), zap.Error(err), zap.String("stack", string(debug.Stack())))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue