From 1a8de9b9fd6ce192fbabdce3b87aa66ffdf6148f Mon Sep 17 00:00:00 2001 From: Seraphim Strub Date: Thu, 26 Jan 2023 00:33:18 +0100 Subject: [PATCH] some cleanup --- cmd/tempbot/main.go | 15 ++++++++++----- cmd/{voicechannelbot => vcbot}/main.go | 7 ++++--- cmd/{joinbot => welcomebot}/main.go | 17 +++++++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) rename cmd/{voicechannelbot => vcbot}/main.go (98%) rename cmd/{joinbot => welcomebot}/main.go (93%) diff --git a/cmd/tempbot/main.go b/cmd/tempbot/main.go index a6b6b71..8085c36 100644 --- a/cmd/tempbot/main.go +++ b/cmd/tempbot/main.go @@ -22,17 +22,18 @@ var ( func main() { log.SetLevel(log.LevelInfo) - log.Info("starting joinbot...") + log.Info("starting tempbot...") log.Info("disgo version: ", disgo.Version) - // intents needed GUILD_MESSAGES + // permissions: Manage Messages + // intent: client, err := disgo.New(token, bot.WithGatewayConfigOpts( - gateway.WithIntents(gateway.IntentsAll), + gateway.WithIntents(gateway.IntentsNone), ), bot.WithCacheConfigOpts( - cache.WithCacheFlags( - cache.FlagsAll, + cache.WithCaches( + cache.FlagsNone, ), ), ) @@ -43,6 +44,10 @@ func main() { defer client.Close(context.TODO()) + if err = client.OpenGateway(context.TODO()); err != nil { + log.Fatal("error while connecting to gateway: ", err) + } + channels, err := client.Rest().GetGuildChannels(registerGuildID) for _, channel := range channels { switch channel.Name() { diff --git a/cmd/voicechannelbot/main.go b/cmd/vcbot/main.go similarity index 98% rename from cmd/voicechannelbot/main.go rename to cmd/vcbot/main.go index 0d33768..e9f4fac 100644 --- a/cmd/voicechannelbot/main.go +++ b/cmd/vcbot/main.go @@ -40,7 +40,7 @@ type appleApiBody struct { func main() { log.SetLevel(log.LevelInfo) - log.Info("starting voicechannelbot...") + log.Info("starting vcbot...") log.Info("disgo version: ", disgo.Version) err := loadAppleList() @@ -49,7 +49,8 @@ func main() { return } - // intents needed + // permissions: Manage Channels + // intents: client, err := disgo.New(token, bot.WithGatewayConfigOpts( gateway.WithIntents(gateway.IntentGuildVoiceStates), @@ -89,7 +90,7 @@ func main() { log.Fatal("couldn't find needed channel") } - log.Infof("voicechannelbot is now running. Press CTRL-C to exit.") + 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 diff --git a/cmd/joinbot/main.go b/cmd/welcomebot/main.go similarity index 93% rename from cmd/joinbot/main.go rename to cmd/welcomebot/main.go index 54cdbcb..0a6e7e4 100644 --- a/cmd/joinbot/main.go +++ b/cmd/welcomebot/main.go @@ -33,17 +33,18 @@ var ( func main() { log.SetLevel(log.LevelInfo) - log.Info("starting example...") + log.Info("starting welcomebot...") log.Info("disgo version: ", disgo.Version) - // intents needed GUILD_MEMBER_ADD (from GUILD_MEMBERS) + // permissions: Manage Roles + // intent: Server Members Intent client, err := disgo.New(token, bot.WithGatewayConfigOpts( gateway.WithIntents(gateway.IntentGuildMembers), ), bot.WithCacheConfigOpts( - cache.WithCacheFlags( - cache.FlagsAll, + cache.WithCaches( + cache.FlagsNone, ), ), bot.WithEventListenerFunc(joinListener), @@ -88,7 +89,7 @@ func main() { log.Fatal("couldn't find needed role") } - log.Infof("joinbot is now running. Press CTRL-C to exit.") + log.Infof("welcomebot is now running. Press CTRL-C to exit.") s := make(chan os.Signal, 1) signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) <-s @@ -97,7 +98,7 @@ func main() { func joinListener(event *events.GuildMemberJoin) { // on join send message in welcome user := event.Member.User - if event.GuildID != registerGuildID { + if event.GuildID.String() != registerGuildID.String() { event.Client().Logger().Error("join from an other guild") return } @@ -137,7 +138,7 @@ func reactionListener(event *events.ComponentInteractionCreate) { } approverID := event.User().ID - if approverID == event.Client().ID() { + if approverID.String() == event.Client().ID().String() { // reaction user is bot itself return } @@ -152,7 +153,7 @@ func reactionListener(event *events.ComponentInteractionCreate) { } hasPermission := func() bool { for _, roleID := range approver.RoleIDs { - if roleID == roleAppleCoreID { + if roleID.String() == roleAppleCoreID.String() { return true } }