-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoodfood.go
101 lines (86 loc) · 3.58 KB
/
goodfood.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
package scheduled
import (
"time"
"github.com/bwmarrin/discordgo"
"github.com/ritsec/ops-bot-iii/config"
"github.com/ritsec/ops-bot-iii/helpers"
"github.com/ritsec/ops-bot-iii/logging"
"github.com/robfig/cron"
"github.com/sirupsen/logrus"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
var (
// GoodFoodRoleID is the ID of the Good Food role
GoodFoodRoleID string = config.GetString("commands.good_food.role_id")
// GoodFoodChannelID is the ID of the Good Food channel
GoodFoodChannelID string = config.GetString("commands.good_food.channel_id")
)
// sendGoodFoodPing sends a ping to the Good Food channel
func sendGoodFoodPing(s *discordgo.Session, location string, ctx ddtrace.SpanContext) {
span := tracer.StartSpan(
"commands.scheduled.goodfood:sendGoodFoodPing",
tracer.ResourceName("Schedued.GoodFood:sendGoodFoodPing"),
tracer.ChildOf(ctx),
)
defer span.Finish()
logging.Debug(s, "Sending Good Food ping for "+location, nil, span)
message, err := s.ChannelMessageSend(GoodFoodChannelID, helpers.AtRole(GoodFoodRoleID)+"Good Food is Waiting @ "+location+"! https://imgur.com/ur0HqAj")
if err != nil {
logging.Error(s, err.Error(), message.Member.User, span, logrus.Fields{"error": err})
return
}
logging.DebugButton(
s,
"Good Food is Here!",
discordgo.Button{
Label: "View Message",
URL: helpers.JumpURL(message),
Style: discordgo.LinkButton,
Emoji: &discordgo.ComponentEmoji{
Name: "👀",
},
},
nil,
span,
)
}
// GoodFood is the Good Food scheduled event
func GoodFood(s *discordgo.Session, quit chan interface{}) error {
span := tracer.StartSpan(
"commands.scheduled.goodfood:GoodFood",
tracer.ResourceName("Scheduled.GoodFood"),
)
defer span.Finish()
est, err := time.LoadLocation("America/New_York")
if err != nil {
logging.Error(s, err.Error(), nil, span)
return err
}
c := cron.NewWithLocation(est)
must := func(err error) {
if err != nil {
logging.Error(s, err.Error(), nil, span)
}
}
// 11:00 AM
must(c.AddFunc("0 0 11 * * MON", func() { sendGoodFoodPing(s, "RITZ", span.Context()) })) // Monday
must(c.AddFunc("0 0 11 * * TUE", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) })) // Tuesday
must(c.AddFunc("0 0 11 * * WED", func() { sendGoodFoodPing(s, "Brick City Cafe", span.Context()) })) // Wednesday
must(c.AddFunc("0 0 11 * * THU", func() {})) // Thursday
must(c.AddFunc("0 0 11 * * FRI", func() { sendGoodFoodPing(s, "Brick City Cafe", span.Context()) })) // Friday
must(c.AddFunc("0 0 11 * * SAT", func() {})) // Saturday
must(c.AddFunc("0 0 11 * * SUN", func() {})) // Sunday
// 4:00 PM
must(c.AddFunc("0 0 16 * * MON", func() {})) // Monday
must(c.AddFunc("0 0 16 * * TUE", func() {})) // Tuesday
must(c.AddFunc("0 0 16 * * WED", func() { sendGoodFoodPing(s, "RITZ", span.Context()) })) // Wednesday
must(c.AddFunc("0 0 16 * * THU", func() { sendGoodFoodPing(s, "Crossroads", span.Context()) })) // Thursday
must(c.AddFunc("0 0 16 * * FRI", func() {})) // Friday
must(c.AddFunc("0 0 16 * * SAT", func() {})) // Saturday
must(c.AddFunc("0 0 16 * * SUN", func() {})) // Sunday
c.Start()
<-quit
c.Stop()
return nil
}