SOME OF THE PROJECTS ARE MOVED IN THEIR SEPARATE REPOSITORIES
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.3 KiB

package main
import (
"fmt"
"os"
"time"
"twitch-hooks/config"
"twitch-hooks/discordhooks"
"twitch-hooks/twitchhooks"
"twitch-hooks/vkhooks"
)
var logo string = ` _______ _ _ _ _ _
|__ __| (_) | | | | | | |
| |_ ___| |_ ___| |__ ______| |__ ___ ___ | | _____
| \ \ /\ / / | __/ __| '_ \______| '_ \ / _ \ / _ \| |/ / __|
| |\ V V /| | || (__| | | | | | | | (_) | (_) | <\__ \
|_| \_/\_/ |_|\__\___|_| |_| |_| |_|\___/ \___/|_|\_\___/ by Unbewohnte`
var Config config.Config
func init() {
// process the config file
if !config.ConfigExists() {
// there is no existing config file;
// create a new one and exit
err := config.CreateConfig()
if err != nil {
panic(err)
}
fmt.Println("Created a new config file")
os.Exit(0)
}
configContents, err := config.ReadConfig()
if err != nil {
panic(err)
}
Config = *configContents
}
func main() {
fmt.Println(logo)
if Config.Keys.Twitch.ClientID == "" || Config.Keys.Twitch.ClientSecret == "" {
// no twitch api key used. Notify the user and check for the force-send flag
fmt.Println("No Twitch API keys found")
if !Config.ForceSend {
// not forced to send messages. Exiting
fmt.Println("Not forced to send. Exiting...")
os.Exit(0)
}
}
var delay = time.Second * 300
fmt.Printf("Delay: %s\n", delay)
// mainloop
for {
// retrieve access token
tokenResp, err := twitchhooks.GetToken(&Config.Keys.Twitch)
if err != nil {
panic(err)
}
// check if live
is_live, err := twitchhooks.IsLive(Config.TwitchName, &twitchhooks.RequestOptions{
ApplicationKeys: Config.Keys.Twitch,
AccessToken: *tokenResp,
})
if err != nil {
panic(err)
}
if is_live || Config.ForceSend {
// live or forced to send -> send alerts
fmt.Println("Live !")
if Config.Keys.Discord.WebhookUrl != "" {
err := discordhooks.Post(Config.Keys.Discord.WebhookUrl, Config.Messages.DiscordMessage)
if err != nil {
panic(err)
}
}
if Config.Keys.VK.Key != "" {
vkhooks.Initialise(Config.Keys.VK.Key)
err := vkhooks.Send(Config.Messages.VKmessage)
if err != nil {
panic(err)
}
}
// alerted. Now exiting
fmt.Println("Alerts has been sent ! My work is done here...")
os.Exit(0)
}
// sleeping
time.Sleep(delay)
}
}