2023-10-19 18:08:38 -04:00
package main
import (
botEvents "corn-util/bot/events"
"corn-util/bot/loaders"
2023-10-24 21:08:44 -04:00
"corn-util/bot/utils"
2023-10-19 18:08:38 -04:00
"os"
"os/signal"
"runtime"
"strings"
"syscall"
2023-10-23 03:36:40 -04:00
"time"
2023-10-19 18:08:38 -04:00
"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" ) )
2023-10-23 19:11:51 -04:00
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
2023-10-23 03:36:40 -04:00
go func ( ) {
2023-10-23 19:11:51 -04:00
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
}
}
} ( )
2023-10-19 18:08:38 -04:00
s := make ( chan os . Signal , 1 )
signal . Notify ( s , syscall . SIGINT , syscall . SIGTERM , os . Interrupt )
<- s
}