-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifier.go
46 lines (36 loc) · 904 Bytes
/
modifier.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
package main
import "regexp"
var (
asciiRegexp = regexp.MustCompile(`^[\x21-\x7e\s]+$`)
urlRegexp = regexp.MustCompile(`https?:\/\/[^\s ]+`)
)
type Modifier interface {
Modify(sa SayArgs) (SayArgs, error)
}
type ModifierFunc func(sa SayArgs) (SayArgs, error)
func (f ModifierFunc) Modify(sa SayArgs) (SayArgs, error) {
return f(sa)
}
type VoiceLanguageModifier struct {
Config SayConfig
}
func (vlm VoiceLanguageModifier) Modify(sa SayArgs) (SayArgs, error) {
if asciiRegexp.MatchString(sa.Text) {
sa.Voice = vlm.Config.Voice.En
}
return sa, nil
}
type OverflowModifier struct {
Limit int
}
func (om OverflowModifier) Modify(sa SayArgs) (SayArgs, error) {
r := []rune(sa.Text)
if len(r) > om.Limit {
sa.Text = string(r[0:om.Limit])
}
return sa, nil
}
func OmitURL(sa SayArgs) (SayArgs, error) {
sa.Text = urlRegexp.ReplaceAllString(sa.Text, "URL省略")
return sa, nil
}