toast
fb3e0da610
All checks were successful
Build and push container image / build (push) Successful in 38s
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
botEvents "corn-util/bot/events"
|
|
"corn-util/bot/loaders"
|
|
"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")
|
|
}
|
|
|
|
log.Infof("Client ready!")
|
|
log.Infof("Running Disgo %v & Go %v", 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
|
|
}
|