summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai/main.go60
-rw-r--r--go.mod11
-rw-r--r--go.sum12
3 files changed, 80 insertions, 3 deletions
diff --git a/ai/main.go b/ai/main.go
index 433dab2..6359515 100644
--- a/ai/main.go
+++ b/ai/main.go
@@ -4,9 +4,65 @@ import (
"ai/config"
"ai/types"
"ai/utils/logger"
- "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/bwmarrin/discordgo"
+)
+
+const (
+ ProcessPrefix = "Main Process"
+)
+
+var (
+ session *discordgo.Session
+ err error
)
+func init() {
+ session, err = discordgo.New("Bot " + config.Config.DiscordToken)
+ if err != nil {
+ logger.Log("error creating Discord session,", types.LogOptions{Fatal: true, Prefix: ProcessPrefix, Level: types.Error})
+ }
+
+ session.Identify.Intents |= discordgo.IntentsAllWithoutPrivileged
+ session.AddHandler(ready)
+}
+
func main() {
- logger.Log(fmt.Sprintf("Bot Started. Config: %+v", config.Config), types.LogOptions{})
+ err = session.Open()
+ if err != nil {
+ logger.Log("error opening connection,", types.LogOptions{Fatal: true, Prefix: ProcessPrefix, Level: types.Error})
+ }
+
+ // Wait here until CTRL-C or other term signal is received.
+ logger.Log("Bot is now running. Press CTRL-C to exit.", types.LogOptions{Prefix: ProcessPrefix})
+ defer session.Close()
+
+ session_close := make(chan os.Signal, 1)
+ signal.Notify(session_close, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
+
+ <-session_close
+
+ logger.Log("Recived SIGINT. Shutting down gracefully.", types.LogOptions{Prefix: ProcessPrefix})
+}
+
+func ready(s *discordgo.Session, event *discordgo.Ready) {
+ logger.Log("Bot is ready.", types.LogOptions{Prefix: ProcessPrefix, Level: types.Success})
+
+ switch config.Config.Activity {
+ case types.PLAYING:
+ err = s.UpdateGameStatus(0, config.Config.ActivityMessage)
+ case types.WATCHING:
+ err = s.UpdateWatchStatus(0, config.Config.ActivityMessage)
+ case types.LISTENING:
+ err = s.UpdateListeningStatus(config.Config.ActivityMessage)
+ case types.STREAMING:
+ err = s.UpdateStreamingStatus(0, config.Config.ActivityMessage, config.Config.ActivityURL)
+ }
+
+ if err != nil {
+ logger.Log("Error attempting to set activity.", types.LogOptions{Prefix: ProcessPrefix, Level: types.Error})
+ }
}
diff --git a/go.mod b/go.mod
index 5b27d12..926ebe4 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,13 @@ module ai
go 1.24.1
-require github.com/joho/godotenv v1.5.1
+require (
+ github.com/bwmarrin/discordgo v0.28.1
+ github.com/joho/godotenv v1.5.1
+)
+
+require (
+ github.com/gorilla/websocket v1.4.2 // indirect
+ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
+ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
+)
diff --git a/go.sum b/go.sum
index d61b19e..1a619be 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +1,14 @@
+github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
+github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
+github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
+github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
+golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
+golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=