forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streaming.go
99 lines (79 loc) · 3.32 KB
/
streaming.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package streaming
import (
"encoding/json"
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/common"
"strconv"
)
type Plugin struct{}
func (p *Plugin) Name() string {
return "Streaming"
}
func RegisterPlugin() {
plugin := &Plugin{}
common.RegisterPlugin(plugin)
}
type Config struct {
Enabled bool `json:"enabled" schema:"enabled"` // Wether streaming notifications is enabled or not
// Give a role to people streaming
GiveRole int64 `json:"give_role,string" schema:"give_role" valid:"role,true"`
// Ignores people with this role, requirerole is ignored if this is set
IgnoreRole int64 `json:"ban_role,string" schema:"ignore_role" valid:"role,true"`
// Requires people to have this role
RequireRole int64 `json:"require_role,string" schema:"require_role" valid:"role,true"`
// Channel to send streaming announcements in
AnnounceChannel int64 `json:"announce_channel,string" schema:"announce_channel" valid:"channel,true"`
// The message
AnnounceMessage string `json:"announce_message" schema:"announce_message" valid:"template,2000"`
// Match the game name or title against these to filter users out
GameRegex string `json:"game_regex" schema:"game_regex" valid:"regex,2000"`
TitleRegex string `json:"title_regex" schema:"title_regex" valid:"regex,2000"`
}
type LegacyConfig struct {
Enabled bool `json:"enabled" schema:"enabled"` // Wether streaming notifications is enabled or not
// Give a role to people streaming
GiveRole string `json:"give_role" schema:"give_role" valid:"role,true"`
// Ignores people with this role, requirerole is ignored if this is set
IgnoreRole string `json:"ban_role" schema:"ignore_role" valid:"role,true"`
// Requires people to have this role
RequireRole string `json:"require_role" schema:"require_role" valid:"role,true"`
// Channel to send streaming announcements in
AnnounceChannel string `json:"announce_channel" schema:"announce_channel" valid:"channel,true"`
// The message
AnnounceMessage string `json:"announce_message" schema:"announce_message" valid:"template,2000"`
// Match the game name or title against these to filter users out
GameRegex string `json:"game_regex" schema:"game_regex" valid:"regex,2000"`
TitleRegex string `json:"title_regex" schema:"title_regex" valid:"regex,2000"`
}
func (c *Config) UnmarshalJSON(b []byte) error {
var tmp LegacyConfig
err := json.Unmarshal(b, &tmp)
if err != nil {
return err
}
c.GiveRole, _ = strconv.ParseInt(tmp.GiveRole, 10, 64)
c.IgnoreRole, _ = strconv.ParseInt(tmp.IgnoreRole, 10, 64)
c.RequireRole, _ = strconv.ParseInt(tmp.RequireRole, 10, 64)
c.AnnounceChannel, _ = strconv.ParseInt(tmp.AnnounceChannel, 10, 64)
c.GameRegex = tmp.GameRegex
c.TitleRegex = tmp.TitleRegex
c.Enabled = tmp.Enabled
c.AnnounceMessage = tmp.AnnounceMessage
return nil
}
func (c *Config) Save(guildID int64) error {
return common.SetRedisJson("streaming_config:"+discordgo.StrID(guildID), c)
}
var DefaultConfig = &Config{
Enabled: false,
AnnounceMessage: "OH WOWIE! **{{.User.Username}}** is currently streaming! Check it out: {{.URL}}",
}
// Returns he guild's conifg, or the defaul one if not set
func GetConfig(guildID int64) (*Config, error) {
var config *Config
err := common.GetRedisJson("streaming_config:"+discordgo.StrID(guildID), &config)
if err == nil && config == nil {
return DefaultConfig, nil
}
return config, err
}