40 lines
661 B
Go
40 lines
661 B
Go
// Discord bot infrastructure.
|
|
|
|
package discord
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func InitServer(auth_token string) *discordgo.Session {
|
|
session, err := discordgo.New("Bot " + auth_token)
|
|
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
|
|
defer session.Close()
|
|
|
|
// Register handler
|
|
session.AddHandler(dispatcher)
|
|
|
|
err = session.Open()
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
|
|
return session
|
|
}
|
|
|
|
func RunServer() {
|
|
log.Println("Bot is now running. Press CTRL-C to exit.")
|
|
sig_chan := make(chan os.Signal, 1)
|
|
signal.Notify(sig_chan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
|
<-sig_chan
|
|
}
|