forked from usdevs/cinnabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedback.go
150 lines (122 loc) Β· 5.38 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
package cinnabot
import (
"log"
"strconv"
"github.com/patrickmn/go-cache"
"cinnabot/model"
"gopkg.in/telegram-bot-api.v4"
)
//The different feedback functions are broken to four different functions so that responses can be easily personalised.
//Feedback allows users an avenue to give feedback. Admins can retrieve by searching the /feedback handler in the db
func (cb *Cinnabot) Feedback(msg *message) {
if cb.CheckArgCmdPair("/feedback", msg.Args) {
//Set Cache
log.Print(msg.Args[0])
key := msg.Args[0]
if msg.Args[0] == "general(usc)" {
key = "usc"
}
cb.cache.Set(strconv.Itoa(msg.From.ID), "/"+key+"feedback", cache.DefaultExpiration)
text := ""
if key == "usc" {
text = "This feedback will be sent to the University Scholars Club. Please send your message."
} else if key == "dining" {
text = "This feedback will be sent to the Dining Hall Committee. Please send your message. \n(Indicate which stall you ate and whether it was Breakfast or Dinner)"
} else if key == "residential" {
text = "This feedback will be sent to the Residential Assistants. Please send your message."
} else if key == "cinnabot" {
text = "This feedback will be sent to USDevs, the developers of CinnaBot. Please send your message."
} else if key == "ohs" {
text = "[OHS Feedback](https://bit.ly/faultycinnamon)"
}
cb.SendTextMessage(msg.Message.From.ID, text)
//Sets cache to the corresponding feedback
return
}
opt1 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("Cinnabot"))
opt2 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("General(USC)"))
opt3 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("Dining"))
opt4 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("Residential"))
opt5 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("OHS"))
options := tgbotapi.NewReplyKeyboard(opt2, opt3, opt4, opt1, opt5)
replyMsg := tgbotapi.NewMessage(int64(msg.Message.From.ID), "π€: What will you like to give feedback to?\nUse /cancel if you chicken out.")
replyMsg.ReplyMarkup = options
cb.SendMessage(replyMsg)
return
}
func (cb *Cinnabot) CinnabotFeedback(msg *message) {
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
text := "π€: Feedback received! I will now transmit feedback to USDevs\n\n " +
"We really appreciate you taking the time out to submit feedback.\n" +
"If you want to you may contact my owner at @sean_npn. He would love to have coffee with you."
cb.SendTextMessage(int(msg.Chat.ID), text)
forwardMess := tgbotapi.NewForward(-315255349, msg.Chat.ID, msg.MessageID)
cb.SendMessage(forwardMess)
return
}
func (cb *Cinnabot) USCFeedback(msg *message) {
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
text := "π€: Feedback received! I will now transmit feedback to USC\n\n " +
"We really appreciate you taking the time out to submit feedback.\n"
cb.SendTextMessage(int(msg.Chat.ID), text)
forwardMess := tgbotapi.NewForward(-218198924, msg.Chat.ID, msg.MessageID)
cb.SendMessage(forwardMess)
return
}
func (cb *Cinnabot) DiningFeedback(msg *message) {
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
text := "π€: Feedback received! I will now transmit feedback to dining hall committeel\n\n " +
"We really appreciate you taking the time out to submit feedback.\n"
cb.SendTextMessage(int(msg.Chat.ID), text)
forwardMess := tgbotapi.NewForward(-295443996, msg.Chat.ID, msg.MessageID)
cb.SendMessage(forwardMess)
return
}
func (cb *Cinnabot) ResidentialFeedback(msg *message) {
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
text := "π€: Feedback received! I will now transmit feedback to the residential committeel\n\n " +
"We really appreciate you taking the time out to submit feedback.\n"
cb.SendTextMessage(int(msg.Chat.ID), text)
forwardMess := tgbotapi.NewForward(-278463800, msg.Chat.ID, msg.MessageID)
cb.SendMessage(forwardMess)
return
}
func (cb *Cinnabot) Cancel(msg *message) {
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
text := "π€: Command cancelled!\n"
cb.SendTextMessage(int(msg.Chat.ID), text)
return
}
// function to send message when someone enters dhsurvey tag
func (cb *Cinnabot) DHSurvey(msg *message) {
replyMsg := tgbotapi.NewMessage(int64(msg.Message.From.ID), `
π€: Welcome to the Dining Hall Survey function! Please enter the following:
1. Breakfast or dinner?
2. Which stall did you have it from?
3. Rate food from 1-5 (1: couldn't eat it, 5: would take another serving)
4. Any feedback or complaints?
Here's a sample response:
1. Breakfast
2. Asian
3. 4
4. Good food`)
cb.SendMessage(replyMsg)
// redirect to new function which takes the survey
cb.cache.Set(strconv.Itoa(msg.From.ID), "/dhsurveyfeedback", cache.DefaultExpiration)
return
}
// function to add DH survey entry to database
func (cb *Cinnabot) DHSurveyFeedback(msg *message) {
// cache must return to normal after this fuction
cb.cache.Set(strconv.Itoa(msg.From.ID), "", cache.DefaultExpiration)
// add entry to database
db := model.InitializeDB()
modelFeedback, err := model.CreateFeedbackEntry(*msg.Message)
if err != nil {
cb.SendTextMessage(int(msg.From.ID), "π€: Please enter correct format for feedback. :(")
} else {
db.Add(&modelFeedback)
cb.SendTextMessage(int(msg.From.ID), "π€: Thank you! The feedback will be sent to the dining hall committee. :)")
}
return
}