-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.go
36 lines (30 loc) · 1.07 KB
/
notifications.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
package main
import (
"fmt"
"log"
"regexp"
"github.com/0xAX/notificator"
"github.com/1egoman/slick/gateway"
)
var imagePath string = "/tmp/slick_notification.png"
var notify *notificator.Notificator = notificator.New(notificator.Options{
DefaultIcon: "/tmp/slick_notification.png",
AppName: "Slick",
})
// Send a notification when a message is received.
func Notification(title string, text string) {
log.Println("SEND NOTIFICATION", title, text)
notify.Push(title, text, "", notificator.UR_CRITICAL)
}
// When should we notify a user about a message?
// 1. When the channel that the message is received in is a channel we're a member of.
// 2. When the regex matches.
func ShouldMessageNotifyUser(messageBody string, selectedChannel *gateway.Channel, self *gateway.User) bool {
if self != nil && selectedChannel != nil && selectedChannel.IsMember {
notificationRegex := fmt.Sprintf("(%s|<@%s|<@%s|<!channel|<!here|<!everyone)", self.Name, self.Id, self.RealName)
match, _ := regexp.MatchString(notificationRegex, messageBody)
return match
} else {
return false
}
}