/
actions.go
42 lines (34 loc) · 924 Bytes
/
actions.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
// This file contains extra features that aren't enabled by default.
package main
import (
"fmt"
"github.com/markberger/tally"
"regexp"
)
// Extract the sender from the given line
func get_user(line string) string {
re := regexp.MustCompile(`:(.*)!`)
result := re.FindStringSubmatch(line)
return result[1]
}
// If someone types "/me <action> tally", tally will
// respond with "/me <action> <user>"
func ParseAction(re *regexp.Regexp, line string) interface{} {
// Regex: `:\x01ACTION (\w*) <your bot>\x01`
action := re.FindStringSubmatch(line)
if len(action) == 0 {
return nil
}
user := get_user(line)
m := make(map[string]string)
m["user"] = user
m["action"] = action[1]
return m
}
func RespondToAction(bot *tally.Bot, output interface{}) {
m := output.(map[string]string)
user := m["user"]
action := m["action"]
msg := fmt.Sprintf("\x01ACTION %s %s\x01", action, user)
bot.MsgChannel(msg)
}