-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeedback.go
162 lines (138 loc) · 5.73 KB
/
feedback.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package slash
import (
"github.com/bwmarrin/discordgo"
"github.com/google/uuid"
"github.com/ritsec/ops-bot-iii/commands/slash/permission"
"github.com/ritsec/ops-bot-iii/config"
"github.com/ritsec/ops-bot-iii/helpers"
"github.com/ritsec/ops-bot-iii/logging"
"github.com/sirupsen/logrus"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
var (
// FeedbackChannelID is the ID of the channel to send feedback to
FeedbackChannelID string = config.GetString("commands.feedback.channel_id")
)
// Feedback is the feedback command
func Feedback() (*discordgo.ApplicationCommand, func(s *discordgo.Session, i *discordgo.InteractionCreate)) {
return &discordgo.ApplicationCommand{
Name: "feedback",
Description: "Send Anonymous Feedback to E-Board",
DefaultMemberPermissions: &permission.Member,
},
func(s *discordgo.Session, i *discordgo.InteractionCreate) {
span := tracer.StartSpan(
"commands.slash.feedback:Feedback",
tracer.ResourceName("/feedback"),
)
defer span.Finish()
logging.Debug(s, "Feedback command received", nil, span)
feedbackSlug := uuid.New().String()
closeChan := make(chan bool)
defer close(closeChan)
(*ComponentHandlers)[feedbackSlug] = func(s *discordgo.Session, i *discordgo.InteractionCreate) {
span_feedbackSlug := tracer.StartSpan(
"commands.slash.feedback:Feedback:feedbackSlug",
tracer.ResourceName("/feedback:feedbackSlug"),
tracer.ChildOf(span.Context()),
)
defer span_feedbackSlug.Finish()
feedback := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Feedback Sent",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
// Let the eboard know that this failed while keeping the user anon
logging.Error(s, err.Error(), nil, span_feedbackSlug, logrus.Fields{"error": err})
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Unable to send the feedback. Error reported without revealing your name.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, err.Error(), nil, span, logrus.Fields{"error": err})
err = helpers.SendDirectMessage(s, i.Member.User.ID, "Unable to send the feedback. Error reported without revealing your name.", span.Context())
// dawg everything failed, might as well have eboard contact the user
if err != nil {
logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err})
}
}
}
_, err = s.ChannelMessageSendComplex(FeedbackChannelID,
&discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Title: "New Feedback",
Description: feedback,
},
},
)
if err != nil {
// Let the eboard know that this failed while keeping the user anon
logging.Error(s, err.Error(), nil, span_feedbackSlug, logrus.Fields{"error": err})
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Unable to send the feedback. Error reported without revealing your name.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, err.Error(), nil, span, logrus.Fields{"error": err})
err = helpers.SendDirectMessage(s, i.Member.User.ID, "Unable to send the feedback. Error reported without revealing your name.", span.Context())
// dawg everything failed, might as well have eboard contact the user
if err != nil {
logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err})
}
}
}
closeChan <- true
}
defer delete(*ComponentHandlers, feedbackSlug)
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseModal,
Data: &discordgo.InteractionResponseData{
CustomID: feedbackSlug,
Title: "Feedback",
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.TextInput{
CustomID: "feedback",
Label: "Feedback",
Style: discordgo.TextInputParagraph,
},
},
},
},
},
})
if err != nil {
// Let the eboard know that this failed while keeping the user anon
logging.Error(s, err.Error(), nil, span, logrus.Fields{"error": err})
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Unable to send the feedback. Error reported without revealing your name.",
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
logging.Error(s, err.Error(), nil, span, logrus.Fields{"error": err})
err = helpers.SendDirectMessage(s, i.Member.User.ID, "Unable to send the feedback. Error reported without revealing your name.", span.Context())
// dawg everything failed, might as well have eboard contact the user
if err != nil {
logging.Error(s, err.Error(), i.Member.User, span, logrus.Fields{"error": err})
}
}
}
logging.Debug(s, "Feedback command responded", nil, span)
<-closeChan
logging.Debug(s, "Feedback command closed", nil, span)
}
}