-
Notifications
You must be signed in to change notification settings - Fork 0
/
emitter.go
54 lines (43 loc) · 908 Bytes
/
emitter.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
51
52
53
54
package fsmcli
import (
"errors"
"fmt"
"reflect"
"github.com/go-carrot/fsm-emitable"
)
type CommandLineEmitter struct{}
func (c *CommandLineEmitter) Emit(i interface{}) error {
switch v := i.(type) {
case string:
fmt.Println(v)
return nil
case emitable.Audio:
fmt.Println("Audio:", v.URL)
return nil
case emitable.File:
fmt.Println("File:", v.URL)
return nil
case emitable.Image:
fmt.Println("Image:", v.URL)
return nil
case emitable.Video:
fmt.Println("Video:", v.URL)
return nil
case emitable.QuickReply:
fmt.Print("Type one of: [ ")
for i, reply := range v.Replies {
fmt.Print("'" + reply + "'")
if i+1 < len(v.Replies) {
fmt.Print(", ")
}
}
fmt.Println(" ]")
return nil
case emitable.Typing:
if v.Enabled {
fmt.Println("...")
}
return nil
}
return errors.New("CommandLineEmitter cannot handle " + reflect.TypeOf(i).String())
}