-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
67 lines (55 loc) · 1.73 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
package main
import (
"context"
"flag"
"github.com/gempir/go-twitch-irc"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
"log"
"strings"
"time"
)
func init() {
}
const commandPrefix = "!warn"
var interceptPrefixes = [...]string{"!sr", "!songrequest"}
var botOauthString string
var botUsername string
var youtubeApiKey string
var twitchChatClient *twitch.Client
var youtubeService *youtube.Service
func init() {
flag.StringVar(&botOauthString, "oauth", "oauth:123123123", "oAuth String to authenticate to twitch chat")
flag.StringVar(&botUsername, "botname", "ingressres_bot", "Name of bot account")
flag.StringVar(&youtubeApiKey, "youtubeApiKey", "", "Youtube API key")
flag.Parse()
twitchChatClient = twitch.NewClient(botUsername, botOauthString)
ctx := context.Background()
var err error
youtubeService, err = youtube.NewService(ctx, option.WithScopes(youtube.YoutubeReadonlyScope), option.WithAPIKey(youtubeApiKey))
if err != nil {
log.Fatal(err)
}
}
func main() {
twitchChatClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
receiveTime := time.Now()
log.Printf("Message | in | %s | %s | \"%s\"\n", message.Channel, message.User.DisplayName, message.Message)
if strings.HasPrefix(message.Message, commandPrefix) {
handleCommand(message)
}
for _, interceptedPrefix := range interceptPrefixes {
if strings.HasPrefix(message.Message, interceptedPrefix) {
intercept(message, interceptedPrefix)
}
}
log.Printf("Message | Done in %04dms | %s | %s | \"%s\"\n", time.Now().Sub(receiveTime).Milliseconds(),
message.Channel, message.User.DisplayName, message.Message)
})
twitchChatClient.Join(botUsername)
err := twitchChatClient.Connect()
if err != nil {
panic(err)
}
select {}
}