discordBots/cmd/vcbot/main.go

74 lines
1.7 KiB
Go
Raw Normal View History

package main
import (
"context"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
2023-03-08 20:39:42 +00:00
"grow.rievo.dev/discordBots/cmd/vcbot/config"
"grow.rievo.dev/discordBots/cmd/vcbot/event"
"os"
"os/signal"
"syscall"
)
func main() {
log.SetLevel(log.LevelInfo)
2023-01-25 23:33:18 +00:00
log.Info("starting vcbot...")
log.Info("disgo version: ", disgo.Version)
2023-03-08 20:39:42 +00:00
err := config.LoadAppleList()
if err != nil {
log.Fatal(err)
return
}
2023-01-25 23:33:18 +00:00
// permissions: Manage Channels
// intents:
2023-03-08 20:39:42 +00:00
client, err := disgo.New(config.Token,
bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentGuildVoiceStates),
),
bot.WithCacheConfigOpts(
cache.WithCaches(
cache.FlagChannels,
cache.FlagVoiceStates,
cache.FlagMembers,
),
),
2023-03-08 20:39:42 +00:00
bot.WithEventListenerFunc(event.JoinEvent),
bot.WithEventListenerFunc(event.MoveEvent),
bot.WithEventListenerFunc(event.LeaveEvent),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
return
}
defer client.Close(context.TODO())
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
}
2023-03-08 20:39:42 +00:00
channels, err := client.Rest().GetGuildChannels(config.RegisterGuildID)
for _, channel := range channels {
switch channel.Name() {
case "🔊-talk":
2023-03-08 20:39:42 +00:00
config.ChannelVoiceGroupID = channel.ID()
case "📋-voice":
2023-03-08 20:39:42 +00:00
config.ChannelVoiceLogID = channel.ID()
}
}
2023-03-08 20:39:42 +00:00
if config.ChannelVoiceGroupID == 0 {
log.Fatal("couldn't find needed channel")
}
2023-01-25 23:33:18 +00:00
log.Infof("vcbot is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
}