From d3adddb3a28bd9c1ab42388e0204721bc0b3ffdb Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 1 Aug 2021 22:11:12 -0400 Subject: [PATCH] Add invite storage to startup Loops through every channel the bot can see and adds the invite data to --- main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.go b/main.go index 53b6f85..ce674a2 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,12 @@ import ( "github.com/wpi-25/scribe/middleware" ) +type BotContext struct { + Invites map[string][]*discordgo.Invite +} + +var BotCtx BotContext + func main() { err := godotenv.Load() if err != nil { @@ -53,11 +59,28 @@ func main() { // Add command handler to message listener router.Initialize(s) + s.StateEnabled = true + err = s.Open() if err != nil { log.Fatalln(err) } + BotCtx = BotContext{} + for _, guild := range s.State.Guilds { + log.Println(fmt.Sprintf("Storing invites for %s", guild.Name)) + for _, chann := range guild.Channels { + invs, err := s.ChannelInvites(chann.ID) + if err != nil { + log.Println(err) + } else { + for _, inv := range invs { + _ = append(BotCtx.Invites[guild.ID], inv) + } + } + } + } + log.Println("Bot running") // Keep the bot running <-make(chan struct{})