2023-01-25 19:09:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/disgoorg/disgo"
|
|
|
|
"github.com/disgoorg/disgo/bot"
|
|
|
|
"github.com/disgoorg/disgo/cache"
|
|
|
|
"github.com/disgoorg/disgo/gateway"
|
2023-03-08 20:39:42 +00:00
|
|
|
"grow.rievo.dev/discordBots/cmd/vcbot/config"
|
|
|
|
"grow.rievo.dev/discordBots/cmd/vcbot/event"
|
2023-04-22 22:33:20 +00:00
|
|
|
"log"
|
2023-01-25 19:09:58 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-04-22 22:33:20 +00:00
|
|
|
log.Printf("INFO: starting vcbot...")
|
|
|
|
log.Printf("INFO: disgo version: %v", disgo.Version)
|
2023-01-25 19:09:58 +00:00
|
|
|
|
2023-03-08 20:39:42 +00:00
|
|
|
err := config.LoadAppleList()
|
2023-01-25 19:09:58 +00:00
|
|
|
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,
|
2023-01-25 19:09:58 +00:00
|
|
|
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),
|
2023-01-25 19:09:58 +00:00
|
|
|
)
|
|
|
|
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)
|
2023-01-25 19:09:58 +00:00
|
|
|
for _, channel := range channels {
|
|
|
|
switch channel.Name() {
|
|
|
|
case "🔊-talk":
|
2023-03-08 20:39:42 +00:00
|
|
|
config.ChannelVoiceGroupID = channel.ID()
|
2023-01-25 19:09:58 +00:00
|
|
|
case "📋-voice":
|
2023-03-08 20:39:42 +00:00
|
|
|
config.ChannelVoiceLogID = channel.ID()
|
2023-01-25 19:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 20:39:42 +00:00
|
|
|
if config.ChannelVoiceGroupID == 0 {
|
2023-01-25 19:09:58 +00:00
|
|
|
log.Fatal("couldn't find needed channel")
|
|
|
|
}
|
|
|
|
|
2023-04-22 22:33:20 +00:00
|
|
|
log.Printf("ERROR: vcbot is now running. Press CTRL-C to exit.")
|
2023-01-25 19:09:58 +00:00
|
|
|
s := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
|
|
|
<-s
|
|
|
|
}
|