-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendSubMessage.go
53 lines (48 loc) · 1.31 KB
/
sendSubMessage.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
package bot
import (
"github.com/khades/servbot/models"
"github.com/khades/servbot/repos"
"strings"
"github.com/cbroglie/mustache"
)
func sendSubMessage(channel *string, channelID *string, user *string, subPlan *string) {
subAlert, error := repos.GetSubAlert(channelID)
if error != nil || subAlert.Enabled == false {
return
}
template := subAlert.SubFiveMessage
switch *subPlan {
case "Prime":
{
if subAlert.SubPrimeMessage != "" {
template = subAlert.SubPrimeMessage
}
}
case "2000":
{
if subAlert.SubTenMessage != "" {
template = subAlert.SubTenMessage
}
}
case "3000":
{
if subAlert.SubTwentyFiveMessage != "" {
template = subAlert.SubTwentyFiveMessage
}
}
}
channelInfo, channelInfoError := repos.GetChannelInfo(channelID)
if channelInfoError == nil && channelInfo.SubTrain.Enabled {
localSubtrain := channelInfo.SubTrain
localSubtrain.CurrentStreak = localSubtrain.CurrentStreak + 1
subtrainAdditionalString, _ := mustache.Render(channelInfo.SubTrain.AppendTemplate, localSubtrain)
template = template +" " + strings.TrimSpace(subtrainAdditionalString)
repos.IncrementSubtrainCounterByChannelID(channelID, user)
}
if template != "" {
IrcClientInstance.SendPublic(&models.OutgoingMessage{
Body: template,
Channel: *channel,
User: *user})
}
}