-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
111 lines (101 loc) · 3.65 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"time"
"github.com/devict/promobot/channels"
"github.com/devict/promobot/engine"
"github.com/devict/promobot/rules"
"github.com/devict/promobot/sources"
"github.com/kelseyhightower/envconfig"
)
type config struct {
DebugMode bool `envconfig:"DEBUG_MODE"`
// Channels
DevICTSlackWebhook string `envconfig:"DEVICT_SLACK_WEBHOOK" required:"true"`
DevICTTwitter DevICTTwitterConfig
// Sources
DevICTMeetupURL string `envconfig:"DEVICT_MEETUP_URL" required:"true"`
OzSecMeetupURL string `envconfig:"OZSEC_MEETUP_URL" required:"true"`
WTFMeetupURL string `envconfig:"WTF_MEETUP_URL" required:"true"`
}
type DevICTTwitterConfig struct {
AccessToken string `envconfig:"DEVICT_TW_ACCESS_TOKEN" required:"true"`
AccessTokenSecret string `envconfig:"DEVICT_TW_ACCESS_TOKEN_SECRET" required:"true"`
APIKey string `envconfig:"DEVICT_TW_API_KEY" required:"true"`
APISecretKey string `envconfig:"DEVICT_TW_API_SECRET_KEY" required:"true"`
}
func main() {
var c config
if err := envconfig.Process("", &c); err != nil {
panic(err)
}
loc, _ := time.LoadLocation("America/Chicago")
e := engine.NewEngine(engine.EngineConfig{
Sources: []sources.Source{
sources.Source(sources.NewMeetupSource("devICT", c.DevICTMeetupURL)),
sources.Source(sources.NewMeetupSource("OzSec", c.OzSecMeetupURL)),
sources.Source(sources.NewMeetupSource("Wichita Technology Forum", c.WTFMeetupURL)),
},
Channels: []channels.Channel{
channels.Channel(channels.NewSlackChannel("devICT", c.DevICTSlackWebhook)),
channels.Channel(channels.NewTwitterChannel("devICT", channels.TwitterConfig{
AccessToken: c.DevICTTwitter.AccessToken,
AccessTokenSecret: c.DevICTTwitter.AccessTokenSecret,
APIKey: c.DevICTTwitter.APIKey,
APISecretKey: c.DevICTTwitter.APISecretKey,
})),
},
Rules: []rules.NotifyRule{
{
NumDaysOut: 10,
ChannelTemplates: map[string]rules.MsgFunc{
"slack": func(e sources.Event) string {
t := e.DateTime.Format("Mon 01/02 @ 03:04 PM")
return fmt.Sprintf("*%s*, %s is hosting <%s|%s> at %s", t, e.Source, e.URL, e.Name, e.Location)
},
// "twitter": func(e sources.Event) string {
// t := e.DateTime.Format("Mon, 01/02 at 03:04 PM")
// return fmt.Sprintf("Join %s for %s! %s\n\nRSVP at %s", e.Source, e.Name, t, e.URL)
// },
},
},
{
NumDaysOut: 4,
ChannelTemplates: map[string]rules.MsgFunc{
"slack": func(e sources.Event) string {
t := e.DateTime.Format("Monday @ 03:04 PM")
return fmt.Sprintf("*%s*, %s is hosting <%s|%s> at %s", t, e.Source, e.URL, e.Name, e.Location)
},
// "twitter": func(e sources.Event) string {
// t := e.DateTime.Format("Monday at 03:04 PM")
// return fmt.Sprintf("Join %s for %s! %s\n\nMore info at %s", e.Source, e.Name, t, e.URL)
// },
},
},
{
NumDaysOut: 1,
ChannelTemplates: map[string]rules.MsgFunc{
"slack": func(e sources.Event) string {
return fmt.Sprintf("*Tomorrow!* %s is hosting <%s|%s> at %s", e.Source, e.URL, e.Name, e.Location)
},
// "twitter": func(e sources.Event) string {
// t := e.DateTime.Format("03:04 PM")
// return fmt.Sprintf("Tomorrow! Join %s at %s for %s\n\nMore info here: %s", e.Source, t, e.Name, e.URL)
// },
},
},
{
NumDaysOut: 0,
ChannelTemplates: map[string]rules.MsgFunc{
"slack": func(e sources.Event) string {
t := e.DateTime.Format("03:04 PM")
return fmt.Sprintf("*Today!* %s is hosting <%s|%s> at %s, %s", e.Source, e.URL, e.Name, e.Location, t)
},
},
},
},
Location: loc,
DebugMode: c.DebugMode,
})
e.RunOnce()
}