some cleanup

This commit is contained in:
Seraphim Strub 2023-01-26 00:33:18 +01:00
parent 16ee889aae
commit 1a8de9b9fd
3 changed files with 23 additions and 16 deletions

View file

@ -22,17 +22,18 @@ var (
func main() { func main() {
log.SetLevel(log.LevelInfo) log.SetLevel(log.LevelInfo)
log.Info("starting joinbot...") log.Info("starting tempbot...")
log.Info("disgo version: ", disgo.Version) log.Info("disgo version: ", disgo.Version)
// intents needed GUILD_MESSAGES // permissions: Manage Messages
// intent:
client, err := disgo.New(token, client, err := disgo.New(token,
bot.WithGatewayConfigOpts( bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentsAll), gateway.WithIntents(gateway.IntentsNone),
), ),
bot.WithCacheConfigOpts( bot.WithCacheConfigOpts(
cache.WithCacheFlags( cache.WithCaches(
cache.FlagsAll, cache.FlagsNone,
), ),
), ),
) )
@ -43,6 +44,10 @@ func main() {
defer client.Close(context.TODO()) 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) channels, err := client.Rest().GetGuildChannels(registerGuildID)
for _, channel := range channels { for _, channel := range channels {
switch channel.Name() { switch channel.Name() {

View file

@ -40,7 +40,7 @@ type appleApiBody struct {
func main() { func main() {
log.SetLevel(log.LevelInfo) log.SetLevel(log.LevelInfo)
log.Info("starting voicechannelbot...") log.Info("starting vcbot...")
log.Info("disgo version: ", disgo.Version) log.Info("disgo version: ", disgo.Version)
err := loadAppleList() err := loadAppleList()
@ -49,7 +49,8 @@ func main() {
return return
} }
// intents needed // permissions: Manage Channels
// intents:
client, err := disgo.New(token, client, err := disgo.New(token,
bot.WithGatewayConfigOpts( bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentGuildVoiceStates), gateway.WithIntents(gateway.IntentGuildVoiceStates),
@ -89,7 +90,7 @@ func main() {
log.Fatal("couldn't find needed channel") 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) s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s <-s

View file

@ -33,17 +33,18 @@ var (
func main() { func main() {
log.SetLevel(log.LevelInfo) log.SetLevel(log.LevelInfo)
log.Info("starting example...") log.Info("starting welcomebot...")
log.Info("disgo version: ", disgo.Version) 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, client, err := disgo.New(token,
bot.WithGatewayConfigOpts( bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentGuildMembers), gateway.WithIntents(gateway.IntentGuildMembers),
), ),
bot.WithCacheConfigOpts( bot.WithCacheConfigOpts(
cache.WithCacheFlags( cache.WithCaches(
cache.FlagsAll, cache.FlagsNone,
), ),
), ),
bot.WithEventListenerFunc(joinListener), bot.WithEventListenerFunc(joinListener),
@ -88,7 +89,7 @@ func main() {
log.Fatal("couldn't find needed role") 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) s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s <-s
@ -97,7 +98,7 @@ func main() {
func joinListener(event *events.GuildMemberJoin) { func joinListener(event *events.GuildMemberJoin) {
// on join send message in welcome // on join send message in welcome
user := event.Member.User user := event.Member.User
if event.GuildID != registerGuildID { if event.GuildID.String() != registerGuildID.String() {
event.Client().Logger().Error("join from an other guild") event.Client().Logger().Error("join from an other guild")
return return
} }
@ -137,7 +138,7 @@ func reactionListener(event *events.ComponentInteractionCreate) {
} }
approverID := event.User().ID approverID := event.User().ID
if approverID == event.Client().ID() { if approverID.String() == event.Client().ID().String() {
// reaction user is bot itself // reaction user is bot itself
return return
} }
@ -152,7 +153,7 @@ func reactionListener(event *events.ComponentInteractionCreate) {
} }
hasPermission := func() bool { hasPermission := func() bool {
for _, roleID := range approver.RoleIDs { for _, roleID := range approver.RoleIDs {
if roleID == roleAppleCoreID { if roleID.String() == roleAppleCoreID.String() {
return true return true
} }
} }