discordBots/cmd/funbot/main.go

74 lines
2 KiB
Go
Raw Normal View History

2023-01-25 23:37:53 +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-09 22:37:01 +00:00
"grow.rievo.dev/discordBots/cmd/funbot/command"
"grow.rievo.dev/discordBots/cmd/funbot/config"
"log"
2023-01-25 23:37:53 +00:00
"os"
"os/signal"
"strings"
"syscall"
)
func main() {
log.Printf("INFO: starting funbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
2023-01-25 23:37:53 +00:00
// permissions:
// intent:
2023-03-09 22:37:01 +00:00
client, err := disgo.New(config.Token,
2023-01-25 23:37:53 +00:00
bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentsNone),
),
bot.WithCacheConfigOpts(
cache.WithCaches(
cache.FlagsNone,
),
),
2023-03-09 22:37:01 +00:00
bot.WithEventListenerFunc(command.Listener),
2023-01-25 23:37:53 +00:00
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
return
}
defer client.Close(context.TODO())
2023-01-26 19:10:40 +00:00
var globalComands bool
2023-03-09 22:37:01 +00:00
if strings.ToUpper(config.GlobalCommands) == "TRUE" {
2023-01-26 19:10:40 +00:00
globalComands = true
}
if globalComands {
2023-03-09 22:37:01 +00:00
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), config.Commands); err != nil {
2023-01-26 19:10:40 +00:00
log.Fatal("error while registering commands: ", err)
}
2023-03-09 22:37:01 +00:00
if config.RegisterGuildID != 0 {
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), config.RegisterGuildID, config.NoCommands); err != nil {
log.Printf("INFO: error deleting guild commands %v", err)
2023-01-26 19:10:40 +00:00
}
}
} else {
2023-03-09 22:37:01 +00:00
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), config.RegisterGuildID, config.Commands); err != nil {
2023-01-26 19:10:40 +00:00
log.Fatal("error while registering commands: ", err)
}
2023-03-09 22:37:01 +00:00
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), config.NoCommands); err != nil {
log.Printf("INFO: error deleting global commands %v", err)
2023-01-26 19:10:40 +00:00
}
2023-01-25 23:37:53 +00:00
}
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
}
log.Printf("INFO: funbot is now running. Press CTRL-C to exit.")
2023-01-25 23:37:53 +00:00
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
}