forked from nnev/frank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight.go
50 lines (39 loc) · 984 Bytes
/
highlight.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
package main
import (
"log"
"regexp"
"strings"
"time"
)
var customTextRegex = regexp.MustCompile(`^(?:high|highpub)\s+(.{1,70})`)
func runnerHighlight(parsed Message) {
defer func() {
if r := recover(); r != nil {
log.Printf("MEGA-WTF:pkg: %v", r)
}
}()
if !IsPrivateQuery(parsed) {
return
}
msg := parsed.Trailing
if !strings.HasPrefix(msg, "high") {
// no highlight request, ignore
return
}
n := Nick(parsed)
log.Printf("received highlighting request from %s", n)
highlight := n
if customTextRegex.MatchString(msg) {
match := customTextRegex.FindStringSubmatch(msg)
highlight = match[1]
}
// allow for 100ms round trip time to highlight on time
time.Sleep(4900 * time.Millisecond)
if strings.HasPrefix(msg, "highpub") {
log.Printf("highlighting %s publicly for: %s", n, highlight)
Privmsg("#test", "highlight test: "+highlight)
} else {
log.Printf("highlighting %s privately for: %s", n, highlight)
Privmsg(n, highlight)
}
}