discord-buttsbot-go/buttsbot.go

51 lines
978 B
Go
Raw Normal View History

2019-04-27 02:23:04 +00:00
package main
import (
2019-04-27 04:12:46 +00:00
"flag"
"fmt"
"github.com/bwmarrin/discordgo"
2019-04-27 04:12:46 +00:00
"log"
"os"
"os/signal"
"syscall"
2019-04-27 02:23:04 +00:00
)
2019-04-27 04:12:46 +00:00
var Session, _ = discordgo.New()
var testPtr = flag.Bool("test", false, "Test mode")
2019-04-27 04:12:46 +00:00
func init() {
2019-04-27 04:12:46 +00:00
Session.Token = os.Getenv("DISCORD_TOKEN")
if Session.Token == "" {
flag.StringVar(&Session.Token, "t", "", "Discord Authentication Token")
}
}
func main() {
2019-04-27 04:12:46 +00:00
var err error
2019-04-27 03:21:46 +00:00
fmt.Println("butts!")
2019-04-27 04:12:46 +00:00
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)
}
2019-04-27 04:12:46 +00:00
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Session.Close()
}