-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhighlight.go
49 lines (39 loc) · 1.13 KB
/
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
package main
import (
"log"
"regexp"
"strings"
"time"
"gopkg.in/sorcix/irc.v2"
)
var highlightRe = regexp.MustCompile(`^(?:highpub|high)(?:\s+(.{1,70}))*`)
func runnerHighlight(msg *irc.Message) error {
// Only accept highlight request via queries (as opposed to in
// channels).
if msg.Command != irc.PRIVMSG ||
len(msg.Params) < 1 ||
strings.HasPrefix(msg.Params[0], "#") {
return nil
}
matches := highlightRe.FindStringSubmatch(msg.Trailing())
if matches == nil {
return nil // no highlight request
}
nick := msg.Prefix.Name // for convenience
log.Printf("received highlighting request from %s: %#v", nick, matches)
highlight := nick
if matches[1] != "" {
highlight = matches[1]
}
Privmsg(nick, "will highlight you in 5 seconds")
// allow for 100ms round trip time to highlight on time
time.Sleep(4900 * time.Millisecond)
if strings.HasPrefix(msg.Trailing(), "highpub") {
log.Printf("highlighting %s publicly for: %s", nick, highlight)
Privmsg("#test", "highlight test: "+highlight)
} else {
log.Printf("highlighting %s privately for: %s", nick, highlight)
Privmsg(nick, highlight)
}
return nil
}