-
Notifications
You must be signed in to change notification settings - Fork 0
/
points.go.old
72 lines (61 loc) · 2.02 KB
/
points.go.old
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package twitchpubsub
import (
"encoding/json"
"errors"
"fmt"
"strings"
)
const pointsActionTopicPrefix = "channel-points-channel-v1."
// ModerationAction describes an incoming "Moderation" action coming from Twitch's PubSub servers
type PointsAction struct {
Timestamp time.Time `json:"timestamp"`
Redemption []RedemptionData
User_input string `json:"user_input"`
Status string `json:"status"`
}
type RedemptionData struct {
Id string `json:id`
User string `json:user`
Channel_id int `json:channel_id`
Redeemed_at string `json:redeemd_at`
Reward []RewardInfo
Background_color int `json:background_color`
Is_enabled bool `json:is_enabled`
Is_paused bool `json:is_paused`
Is_in_stock bool `json:is_in_stock`
Should_redemptions_skip_request_queue bool `json:should_redemptions_skip_request_queue`
//Max_per_stream
}
type RewardInfo struct {
Id string `json:id`
Channel_id int `json:channel_id`
Title string `json:title`
Prompt string `json:prompt`
Cost int `json:cost`
Is_user_input_required bool `json:is_user_input_required`
Is_sub_only bool `json:is_sub_only`
//Max_per_stream
}
type outerPointsAction struct {
Data PointsAction `json:"data"`
}
func parsePointsAction(bytes []byte) (*PointsAction, error) {
data := &outerPointsAction{}
err := json.Unmarshal(bytes, data)
if err != nil {
return nil, err
}
return &data.Data, nil
}
func parseChannelIDFromPointsTopic(topic string) (string, error) {
parts := strings.Split(topic, ".")
if len(parts) != 3 {
return "", errors.New("Unable to parse channel ID from Points topic")
}
return parts[2], nil
}
// ModerationActionTopic returns a properly formatted moderation action topic string with the given user and channel ID arguments
func PointsActionTopic(channelID string) string {
const f = `channel-points-channel-v1.%s`
return fmt.Sprintf(f, channelID)
}