2019-10-12 09:45:43 +07:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
2019-10-13 11:39:17 +07:00
|
|
|
"TerraOceanBot/discord/backend"
|
2019-10-12 09:45:43 +07:00
|
|
|
"TerraOceanBot/discord/modules"
|
|
|
|
)
|
|
|
|
|
2019-10-12 15:49:28 +07:00
|
|
|
func StartBot(token string, kill chan bool) {
|
2019-10-12 09:45:43 +07:00
|
|
|
dg, err := discordgo.New("Bot " + strings.TrimSpace(token))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dg.AddHandler(ProcessCommand)
|
2019-10-15 15:29:23 +07:00
|
|
|
dg.AddHandler(ProcessVoiceStateUpdate)
|
2019-10-14 10:01:25 +07:00
|
|
|
dg.AddHandler(modules.CheckForReact)
|
2019-10-12 09:45:43 +07:00
|
|
|
dg.AddHandler(modules.CheckForVote)
|
2019-10-15 11:06:42 +07:00
|
|
|
dg.StateEnabled = true
|
2019-10-12 09:45:43 +07:00
|
|
|
|
|
|
|
if err := dg.Open(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
2019-10-14 12:28:46 +07:00
|
|
|
modules.GenerateHelpEmbed()
|
2019-10-12 09:45:43 +07:00
|
|
|
go modules.ListenToVoteFinishes(dg)
|
2019-10-13 11:39:17 +07:00
|
|
|
go backend.UpdateVoiceChannelState(dg)
|
2019-10-12 15:49:28 +07:00
|
|
|
|
|
|
|
<-kill
|
2019-10-12 09:45:43 +07:00
|
|
|
|
|
|
|
dg.Close()
|
|
|
|
fmt.Println("Discordgo exited successfully.")
|
2019-10-12 15:49:28 +07:00
|
|
|
|
|
|
|
<-kill
|
2019-10-12 09:45:43 +07:00
|
|
|
}
|