41 lines
756 B
Go
41 lines
756 B
Go
package discord
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"TerraOceanBot/discord/backend"
|
|
"TerraOceanBot/discord/modules"
|
|
)
|
|
|
|
func StartBot(token string, kill chan bool) {
|
|
dg, err := discordgo.New("Bot " + strings.TrimSpace(token))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
dg.AddHandler(ProcessCommand)
|
|
dg.AddHandler(ProcessVoiceStateUpdate)
|
|
dg.AddHandler(modules.CheckForReact)
|
|
dg.AddHandler(modules.CheckForVote)
|
|
dg.StateEnabled = true
|
|
|
|
if err := dg.Open(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
|
modules.GenerateHelpEmbed()
|
|
go modules.ListenToVoteFinishes(dg)
|
|
go backend.UpdateVoiceChannelState(dg)
|
|
|
|
<-kill
|
|
|
|
dg.Close()
|
|
fmt.Println("Discordgo exited successfully.")
|
|
|
|
<-kill
|
|
}
|