Message bot channel during startup and testing.

pull/1/head
pocketjawa 2019-04-27 02:20:18 -04:00
parent 944d6137d4
commit c6151323ee
2 changed files with 11 additions and 2 deletions

View File

@ -9,6 +9,8 @@ steps:
environment: environment:
DISCORD_TOKEN: DISCORD_TOKEN:
from_secret: discord_token from_secret: discord_token
DISCORD_BOT_CHANNEL:
from_secret: discord_bot_channel
commands: commands:
- go get - go get
- go build - go build

View File

@ -13,15 +13,20 @@ import (
var Session, _ = discordgo.New() var Session, _ = discordgo.New()
var testPtr = flag.Bool("test", false, "Test mode") var testPtr = flag.Bool("test", false, "Test mode")
var bot_token string var bot_token string
var bot_channel string
func init() { func init() {
flag.StringVar(&bot_token, "t", "", "Discord Authentication Token")
flag.StringVar(&bot_channel, "bc", "", "Bot status channel")
flag.Parse()
if os.Getenv("DISCORD_TOKEN") != "" { if os.Getenv("DISCORD_TOKEN") != "" {
Session.Token = "Bot " + os.Getenv("DISCORD_TOKEN") Session.Token = "Bot " + os.Getenv("DISCORD_TOKEN")
} else { } else {
flag.StringVar(&bot_token, "t", "", "Discord Authentication Token")
flag.Parse()
Session.Token = "Bot " + bot_token Session.Token = "Bot " + bot_token
} }
if os.Getenv("DISCORD_BOT_CHANNEL") != "" {
bot_channel = os.Getenv("DISCORD_BOT_CHANNEL")
}
} }
func main() { func main() {
@ -43,10 +48,12 @@ func main() {
//Wait for a CTRL-C //Wait for a CTRL-C
log.Printf("Now running. Press CTRL-C to exit.") log.Printf("Now running. Press CTRL-C to exit.")
if *testPtr == true { if *testPtr == true {
Session.ChannelMessageSend(bot_channel, "Test complete: discord-buttsbot-go")
log.Printf("Test successful! Now quiting.") log.Printf("Test successful! Now quiting.")
Session.Close() Session.Close()
os.Exit(0) os.Exit(0)
} }
Session.ChannelMessageSend(bot_channel, "This isn't a butt...")
sc := make(chan os.Signal, 1) sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc <-sc