1
0
Fork 0
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:
Ash Keel 2023-02-23 10:50:52 +01:00
parent 8304afa89e
commit 86a86799e5
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
7 changed files with 44 additions and 13 deletions

View file

@ -3,6 +3,8 @@ package main
import (
"os"
"github.com/strimertul/strimertul/utils"
"github.com/strimertul/strimertul/database"
"github.com/urfave/cli/v2"
@ -16,7 +18,7 @@ func cliImport(ctx *cli.Context) error {
if err != nil {
return fatalError(err, "could not open import file for reading")
}
defer file.Close()
defer utils.Close(file, logger)
inStream = file
}
var entries map[string]string
@ -47,7 +49,7 @@ func cliRestore(ctx *cli.Context) error {
if err != nil {
return fatalError(err, "could not open import file for reading")
}
defer file.Close()
defer utils.Close(file, logger)
inStream = file
}
@ -73,7 +75,7 @@ func cliExport(ctx *cli.Context) error {
if err != nil {
return fatalError(err, "could not open output file for writing")
}
defer file.Close()
defer utils.Close(file, logger)
outStream = file
}

View file

@ -6,6 +6,8 @@ import (
"os"
"path/filepath"
"github.com/strimertul/strimertul/utils"
"github.com/cockroachdb/pebble"
kv "github.com/strimertul/kilovolt/v9"
pebble_driver "github.com/strimertul/kv-pebble"
@ -50,7 +52,7 @@ func (p *PebbleDatabase) Hub() *kv.Hub {
func (p *PebbleDatabase) Close() error {
err := p.db.Close()
if err != nil {
return fmt.Errorf("Could not close database: %w", err)
return fmt.Errorf("could not close database: %w", err)
}
return nil
}
@ -89,8 +91,12 @@ func (p *PebbleDatabase) Restore(file io.Reader) error {
}
func (p *PebbleDatabase) Backup(file io.Writer) error {
iter := p.db.NewSnapshot().NewIter(&pebble.IterOptions{})
defer iter.Close()
snapshot := p.db.NewSnapshot()
defer utils.Close(snapshot, p.logger)
iter := snapshot.NewIter(&pebble.IterOptions{})
defer utils.Close(iter, p.logger)
out := make(map[string]string)
for iter.First(); iter.Valid(); iter.Next() {
val, err := iter.ValueAndErr()

2
go.mod
View file

@ -20,7 +20,7 @@ require (
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 (
github.com/DataDog/zstd v1.5.2 // indirect

4
go.sum
View file

@ -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/go.mod h1:nfFtvHn2Hgs9G1u0/J6LHQv//EksNC+7G8vXmd1VTJ8=
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.11.0-ws/go.mod h1:zZcKsyyBWDli34x3QleYsVMiiNGMXPAEU5NjsiZDtvY=
github.com/ashkeel/helix/v2 v2.20.0-ws h1:IvwMHs4PBCoVgu0IVlTZGyQG8h40zBY/FYmRXGcfEco=
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/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=

View file

@ -22,7 +22,7 @@ func (c *Client) GetAuthorizationURL() string {
}
return c.API.GetAuthorizationURL(&helix.AuthorizationURLParams{
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"},
})
}

View file

@ -4,6 +4,8 @@ import (
"fmt"
"time"
"github.com/strimertul/strimertul/utils"
"github.com/gorilla/websocket"
jsoniter "github.com/json-iterator/go"
"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))
return "", err
}
defer connection.Close()
defer utils.Close(connection, c.logger)
received := make(chan []byte, 10)
wsErr := make(chan error, 1)
@ -163,7 +165,7 @@ func (c *Client) addSubscriptionsForSession(userClient *helix.Client, session st
Condition: topicCondition(topic, c.User.ID),
})
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)
}
if err != nil {
@ -180,6 +182,11 @@ func topicCondition(topic string, id string) helix.EventSubCondition {
return helix.EventSubCondition{
ToBroadcasterUserID: id,
}
case "channel.follow":
return helix.EventSubCondition{
BroadcasterUserID: id,
ModeratorUserID: id,
}
default:
return helix.EventSubCondition{
BroadcasterUserID: id,
@ -218,7 +225,7 @@ type EventSubMetadata struct {
var subscriptionVersions = map[string]string{
helix.EventSubTypeChannelUpdate: "1",
helix.EventSubTypeChannelFollow: "1",
helix.EventSubTypeChannelFollow: "2",
helix.EventSubTypeChannelSubscription: "1",
helix.EventSubTypeChannelSubscriptionGift: "1",
helix.EventSubTypeChannelSubscriptionMessage: "1",

16
utils/deferlogger.go Normal file
View 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())))
}
}