-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.go
More file actions
71 lines (51 loc) · 1.11 KB
/
Copy pathbot.go
File metadata and controls
71 lines (51 loc) · 1.11 KB
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
package main
import (
"encoding/json"
"fmt"
"github.com/gempir/go-twitch-irc/v2"
"os"
)
type Configuration struct {
Channel string
User string
Oauth string
}
var configuration = Configuration{}
func main() {
responseCommands := map[string]func(*twitch.PrivateMessage, *twitch.Client){
"!tournament": Tournament,
}
file, _ := os.Open("conf.json")
defer func(file *os.File) {
err := file.Close()
if err != nil {
}
}(file)
decoder := json.NewDecoder(file)
err := decoder.Decode(&configuration)
if err != nil {
fmt.Println("error:", err)
}
channel := configuration.Channel
user := configuration.User
oauth := configuration.Oauth
client := twitch.NewClient(user, oauth)
client.OnPrivateMessage(func(message twitch.PrivateMessage) {
if message.Message[0] == '!'{
response, found := responseCommands[message.Message]
if found {
response(&message, client)
} else {
client.Say(channel, "Command not found")
}
}
})
client.OnConnect(func() {
client.Say(channel, "bot joined")
})
client.Join(channel)
err = client.Connect()
if err != nil {
panic(err)
}
}