This repository has been archived by the owner on Jul 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (85 loc) · 2.27 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
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/TimothyCole/WeetBot-V2/twitch"
_ "github.com/joho/godotenv/autoload"
)
var (
nick = os.Getenv("TWITCH_BOT_NAME")
pass = os.Getenv("TWITCH_BOT_AUTH")
api CommandsAPI
)
type CommandsAPI struct {
Data []Command `json:"data"`
}
type Command struct {
Channel int `json:"channel"`
Command string `json:"command"`
Response string `json:"response"`
Cooldown int `json:"cooldown"`
Userlevel int `json:"userlevel"`
Points int `json:"points"`
Hidden bool `json:"hidden"`
}
func GetCommandsForTim() {
commands := "https://tcole.me/api/stream/51684790/commands"
req, _ := http.NewRequest("GET", commands, nil)
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
api = CommandsAPI{}
err = json.Unmarshal(body, &api)
api.Data = append(api.Data, Command{
Channel: 51684790,
Command: "!ping",
Response: "PONG KappaPride",
Cooldown: 0,
Userlevel: 0,
Points: 0,
})
fmt.Println("Commands Loaded for Tim")
}
func main() {
bot := twitch.NewClient(nick, pass)
if err := bot.Connect(); err != nil {
panic(err)
}
go GetCommandsForTim()
bot.OnNewMessage(func(msg *twitch.Message) {
fmt.Println("> New Message: ", msg.Data.DisplayName, msg.Data.Message)
if "!reload" == msg.Data.Message && msg.Data.DisplayName == "ModestTim" {
go GetCommandsForTim()
}
for _, command := range api.Data {
if command.Command != msg.Data.Message || command.Channel != msg.Data.StreamerID {
continue
}
bot.Say(msg.Data.StreamerName, command.Response)
}
})
bot.OnNewWhisper(func(msg *twitch.Message) {
fmt.Println("> New Whisper: ", msg.Data.DisplayName, msg.Data.Message)
})
bot.OnNewSub(func(msg *twitch.Message) {
fmt.Println("> New Sub: ", msg.Data.DisplayName, msg.Data.Sub.Plan, msg.Data.GiftSub.Login)
// dbug, _ := json.Marshal(msg)
// bot.Say(msg.Data.StreamerName, string(dbug))
})
bot.OnNewRaid(func(msg *twitch.Message) {
fmt.Println("> New Raid: ", msg.Data.Raid.DisplayName, msg.Data.Raid.Viewers)
})
go joinChannel(bot, 51684790, "ModestTim")
go joinChannel(bot, 88560344, "WeetBot")
<-bot.Done
}