Initial commit
parent
e246d6f254
commit
79f1fc62cb
|
@ -0,0 +1,26 @@
|
|||
# ---> Go
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/bwmarrin/disgord/x/mux"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var Session, _ = discordgo.New()
|
||||
var bot_token string
|
||||
var bot_channel string
|
||||
var Router = mux.New()
|
||||
|
||||
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("pocketbot")
|
||||
//flag.Parse()
|
||||
if Session.Token == "" {
|
||||
log.Println("You must provide a Discord auth token!")
|
||||
return
|
||||
}
|
||||
|
||||
//Handlers
|
||||
Session.AddHandler(ready)
|
||||
Session.AddHandler(Router.OnMessageCreate)
|
||||
|
||||
// Register the build-in help command.
|
||||
Router.Route("help", "Display this message.", Router.Help)
|
||||
|
||||
//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) {
|
||||
s.UpdateStatus(0, "with droids!")
|
||||
s.ChannelMessageSend(bot_channel, "This isn't Tatooine...")
|
||||
}
|
Loading…
Reference in New Issue