This repository has been archived on 2024-05-11. You can view files and clone it, but cannot push or open issues or pull requests.
Corn-Utility/main.go
toast c4ddf77a7b
All checks were successful
Build and push container image / build (push) Successful in 41s
Upload the rest of files
2023-10-20 09:08:38 +11:00

57 lines
1.5 KiB
Go

package main
import (
botEvents "corn-util/bot/events"
"corn-util/bot/loaders"
"fmt"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/httpserver"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)
func main() {
client, err := disgo.New(loaders.TokenLoader("bot"),
bot.WithHTTPServerConfigOpts(loaders.TokenLoader("botPublicKey"),
httpserver.WithAddress(":23242"),
httpserver.WithURL("/"),
),
bot.WithEventListeners(&events.ListenerAdapter{OnApplicationCommandInteraction: botEvents.ListenForCommand}),
)
if err != nil {
panic(err)
}
if err = client.OpenHTTPServer(); err != nil {
panic(err)
}
if loaders.IsCmdsDeployable() {
log.Infof("Commands deployment is enabled, deploying...")
if _, err := client.Rest().SetGlobalCommands(client.ApplicationID(), commandsJSON()); err != nil {
log.Errorf("failed to set global commands: %v", err)
}
} else {
log.Infof("Commands deployment is disabled")
}
fmt.Printf("Client ready!\n")
fmt.Printf("Running Disgo %v & Go %v\n", disgo.Version, strings.TrimPrefix(runtime.Version(), "go"))
client.Rest().CreateWebhookMessage(snowflake.MustParse(loaders.TokenLoader("hookId")), loaders.TokenLoader("hookToken"), discord.WebhookMessageCreate{
Content: "Container has been reloaded.",
}, true, 0)
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
}