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

65 lines
1.7 KiB
Go
Raw Permalink Normal View History

2023-10-19 18:08:38 -04:00
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")
}
2023-10-20 01:18:13 -04:00
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)
2023-10-19 18:08:38 -04:00
2024-01-29 03:52:39 -05:00
/* go func() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
2023-10-23 03:36:40 -04:00
for {
select {
case <-ticker.C:
2023-10-24 21:08:44 -04:00
utils.BanRecordsSheet()
2023-10-23 03:36:40 -04:00
}
}
2024-01-29 03:52:39 -05:00
}() */
2023-10-23 03:36:40 -04:00
2023-10-19 18:08:38 -04:00
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
}