make command global

This commit is contained in:
Seraphim Strub 2023-01-26 20:10:40 +01:00
parent ac3d3c204b
commit 2a3ec00b58
2 changed files with 29 additions and 7 deletions

View file

@ -12,8 +12,8 @@
- and a group called `Apple` and `Apple Core` - and a group called `Apple` and `Apple Core`
- the bot group needs to be above `Apple` - the bot group needs to be above `Apple`
- [funbot](./cmd/funbot/main.go) sends funny and cute pictures - [funbot](./cmd/funbot/main.go) sends funny and cute pictures
- needs env `disgo_token`, `disgo_guild_id` and `disgo_imgur` - needs env `disgo_token` and `disgo_imgur`
- TODO: make global and remove `disgo_guild_id` - if `disgo_global` is not TRUE, `disgo_guild_id` is needed
- TODO: add other apis - TODO: add other apis
- [dealsbot](./cmd/dealsbot/main.go) send deals from steam, epic and more - [dealsbot](./cmd/dealsbot/main.go) send deals from steam, epic and more
- needs env `disgo_token`, `disgo_guild_id` - needs env `disgo_token`, `disgo_guild_id`

View file

@ -23,9 +23,10 @@ import (
) )
var ( var (
token = os.Getenv("disgo_token") token = os.Getenv("disgo_token")
apiImgurKey = os.Getenv("disgo_imgur") apiImgurKey = os.Getenv("disgo_imgur")
registerGuildID = snowflake.GetEnv("disgo_guild_id") globalComandsEnv = os.Getenv("disgo_global")
registerGuildID = snowflake.GetEnv("disgo_guild_id")
// TODO: add jokes // TODO: add jokes
commands = []discord.ApplicationCommandCreate{ commands = []discord.ApplicationCommandCreate{
@ -83,6 +84,8 @@ var (
}, },
}, },
} }
noCommands []discord.ApplicationCommandCreate
) )
func main() { func main() {
@ -110,8 +113,27 @@ func main() {
defer client.Close(context.TODO()) defer client.Close(context.TODO())
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, commands); err != nil { var globalComands bool
log.Fatal("error while registering commands: ", err) 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 { if err = client.OpenGateway(context.TODO()); err != nil {