Merge branch 'dev' of pocketjawa/discord-buttsbot-go into master

master
pocketjawa 2019-04-27 06:31:51 +00:00 committed by Gogs
commit 31e15a9ba8
2 changed files with 92 additions and 0 deletions

24
.drone.yml Normal file
View File

@ -0,0 +1,24 @@
kind: pipeline
name: default
workspace:
base: /go
path: src/discord-buttsbot-go
steps:
- name: test
image: golang
environment:
DISCORD_TOKEN:
from_secret: discord_token
DISCORD_BOT_CHANNEL:
from_secret: discord_bot_channel
commands:
- go get
- go build
- ./discord-buttsbot-go -test
- name: discord
image: appleboy/drone-discord
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token

68
buttsbot.go Normal file
View File

@ -0,0 +1,68 @@
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")
var bot_token string
var bot_channel string
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") != "" {
Session.Token = "Bot " + os.Getenv("DISCORD_TOKEN")
} else {
Session.Token = "Bot " + bot_token
}
if os.Getenv("DISCORD_BOT_CHANNEL") != "" {
bot_channel = os.Getenv("DISCORD_BOT_CHANNEL")
}
}
func main() {
var err error
fmt.Println("butts!")
flag.Parse()
if Session.Token == "" {
log.Println("You must provide a Discord auth token!")
return
}
//Handlers
Session.AddHandler(ready)
//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.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Session.Close()
}
func ready(s *discordgo.Session, event *discordgo.Ready) {
if *testPtr == true {
s.ChannelMessageSend(bot_channel, "Test complete: discord-buttsbot-go")
log.Printf("Test successful! Now quiting.")
s.Close()
os.Exit(0)
}
s.UpdateStatus(0, "with butts!")
s.ChannelMessageSend(bot_channel, "This isn't a butt...")
}