discord-buttsbot-go/buttsbot.go

51 lines
978 B
Go

package main
import (
"flag"
"fmt"
"github.com/bwmarrin/discordgo"
"log"
"os"
"os/signal"
"syscall"
)
var Session, _ = discordgo.New()
var testPtr = flag.Bool("test", false, "Test mode")
func init() {
Session.Token = os.Getenv("DISCORD_TOKEN")
if Session.Token == "" {
flag.StringVar(&Session.Token, "t", "", "Discord Authentication Token")
}
}
func main() {
var err error
fmt.Println("butts!")
flag.Parse()
if Session.Token == "" {
log.Println("You must provide a Discord auth token!")
return
}
//Open a connection to Discord
err = Session.Open()
if err != nil {
log.Printf("Error opening connection to Discord, %s\n", err)
os.Exit(1)
}
//Wait for a CTRL-C
log.Printf("Now running. Press CTRL-C to exit.")
if *testPtr == true {
log.Printf("Test successful! Now quiting.")
Session.Close()
os.Exit(0)
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Session.Close()
}