-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (76 loc) · 1.98 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/simsor/twitchplays/controllers"
"github.com/simsor/twitchplays/producers"
)
var (
producer producers.KeysProducer
controller controllers.Controller
configFile string
)
func init() {
var setupMode = flag.Bool("setup", false, "Enter vJoy setup mode")
flag.StringVar(&configFile, "conf", "twitchplays.toml", "Path to the configuration file")
flag.Parse()
if *setupMode {
c, err := controllers.NewVJoyController()
if err != nil {
fmt.Println("Error setting up vJoy:", err)
os.Exit(1)
}
c.InteractiveMode()
os.Exit(0)
}
}
func main() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
config, err := ReadConfig(configFile)
if err != nil {
fmt.Println("Error opening config file:", err)
return
}
if config.Reader == "twitch" {
producer = producers.NewTwitch(config.Twitch.Username, config.Twitch.Password, config.Twitch.Channel)
} else if config.Reader == "irc" {
producer = &producers.IRCKeysProducer{
Server: config.IRC.Server,
Port: config.IRC.Port,
Channel: config.IRC.Channel,
}
} else if config.Reader == "random" {
producer = producers.RandomKeysProducer{}
} else {
fmt.Println("Error: reader", config.Reader, "unknown")
return
}
if config.Controller == "keyboard" {
controller, _ = controllers.NewKeyboardController()
} else if config.Controller == "vjoy" {
controller, _ = controllers.NewVJoyController()
} else {
fmt.Println("Error: controller", config.Controller, "unknown")
return
}
keys := make(chan controllers.KeyInput)
producer.Init()
go processKeys(keys)
go producer.ReadKeys(keys)
fmt.Println("TwitchPlays is running. Press Ctrl+C to stop")
<-quit
close(keys)
time.Sleep(500 * time.Millisecond)
}
func processKeys(keyChan chan controllers.KeyInput) {
for k := range keyChan {
fmt.Printf("<%s> %s\n", k.Sender, k.Key)
go controller.Press(k.Key)
}
fmt.Println("No more keys...")
}