TerraOceanPlugin/GoBot/discord/discord.go

42 lines
816 B
Go

2019-10-12 09:45:43 +07:00
package discord
import (
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/modules"
)
func StartBot(token string, wg *sync.WaitGroup) {
defer wg.Done()
dg, err := discordgo.New("Bot " + strings.TrimSpace(token))
if err != nil {
panic(err)
}
dg.AddHandler(ProcessCommand)
dg.AddHandler(ProcessVote)
dg.AddHandler(modules.CheckForVote)
dg.AddHandler(modules.CheckForTrustUpdate)
dg.AddHandler(modules.CheckForInvite)
if err := dg.Open(); err != nil {
panic(err)
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
go modules.ListenToVoteFinishes(dg)
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
dg.Close()
fmt.Println("Discordgo exited successfully.")
}