diff --git a/README.md b/README.md index 0eacdda..200fc3b 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ - and a group called `Apple` and `Apple Core` - the bot group needs to be above `Apple` - [funbot](./cmd/funbot/main.go) sends funny and cute pictures - - needs env `disgo_token`, `disgo_guild_id` and `disgo_imgur` - - TODO: make global and remove `disgo_guild_id` + - needs env `disgo_token` and `disgo_imgur` + - if `disgo_global` is not TRUE, `disgo_guild_id` is needed - TODO: add other apis - [dealsbot](./cmd/dealsbot/main.go) send deals from steam, epic and more - needs env `disgo_token`, `disgo_guild_id` diff --git a/cmd/funbot/main.go b/cmd/funbot/main.go index 24f4cf3..20df443 100644 --- a/cmd/funbot/main.go +++ b/cmd/funbot/main.go @@ -23,9 +23,10 @@ import ( ) var ( - token = os.Getenv("disgo_token") - apiImgurKey = os.Getenv("disgo_imgur") - registerGuildID = snowflake.GetEnv("disgo_guild_id") + token = os.Getenv("disgo_token") + apiImgurKey = os.Getenv("disgo_imgur") + globalComandsEnv = os.Getenv("disgo_global") + registerGuildID = snowflake.GetEnv("disgo_guild_id") // TODO: add jokes commands = []discord.ApplicationCommandCreate{ @@ -83,6 +84,8 @@ var ( }, }, } + + noCommands []discord.ApplicationCommandCreate ) func main() { @@ -110,8 +113,27 @@ func main() { defer client.Close(context.TODO()) - if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, commands); err != nil { - log.Fatal("error while registering commands: ", err) + var globalComands bool + if strings.ToUpper(globalComandsEnv) == "TRUE" { + globalComands = true + } + + if globalComands { + if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), commands); err != nil { + log.Fatal("error while registering commands: ", err) + } + if registerGuildID != 0 { + if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, noCommands); err != nil { + log.Info("error deleting guild commands", err) + } + } + } else { + if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, commands); err != nil { + log.Fatal("error while registering commands: ", err) + } + if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), noCommands); err != nil { + log.Info("error deleting global commands", err) + } } if err = client.OpenGateway(context.TODO()); err != nil {