From e7fccffd2e04ed9bbd9e68a5e3c8730e9f770bba Mon Sep 17 00:00:00 2001 From: ayntgl <90600421+ayntgl@users.noreply.github.com> Date: Fri, 2 Sep 2022 14:20:23 +0530 Subject: [PATCH] Add essential intents for bot accounts (#205) --- main.go | 13 ++++++++++--- ui/core.go | 16 ++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 4aea6f9..f70c7c0 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" + "github.com/ayntgl/discordo/config" "github.com/ayntgl/discordo/ui" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" @@ -44,9 +45,15 @@ func init() { func main() { flag.Parse() - c := ui.NewCore(configPath) + cfg := config.New(configPath) + err := cfg.Load() + if err != nil { + log.Fatal(err) + } + + c := ui.NewCore(cfg) if token != "" { - err := c.Run(token) + err = c.Run(token) if err != nil { log.Fatal(err) } @@ -109,7 +116,7 @@ func main() { tview.Styles.BorderColor = tcell.GetColor(lua.LVAsString(border)) tview.Styles.TitleColor = tcell.GetColor(lua.LVAsString(title)) - err := c.Application.Run() + err = c.Application.Run() if err != nil { log.Fatal(err) } diff --git a/ui/core.go b/ui/core.go index 556dd5c..a422715 100644 --- a/ui/core.go +++ b/ui/core.go @@ -42,12 +42,12 @@ type Core struct { focused focused } -func NewCore(path string) *Core { +func NewCore(cfg *config.Config) *Core { c := &Core{ Application: tview.NewApplication(), MainFlex: tview.NewFlex(), - Config: config.New(path), + Config: cfg, } c.MainFlex.SetInputCapture(c.onInputCapture) @@ -59,13 +59,8 @@ func NewCore(path string) *Core { } func (c *Core) Run(token string) error { - err := c.Config.Load() - if err != nil { - return err - } - c.register() - err = c.Config.State.DoString(string(config.LuaConfig)) + err := c.Config.State.DoString(string(config.LuaConfig)) if err != nil { return err } @@ -92,11 +87,12 @@ func (c *Core) Run(token string) error { Compress: false, })) - // For user accounts, all of the guilds, the user is in, are dispatched in the READY gateway event. - // Whereas, for bot accounts, the guilds are dispatched discretely in the GUILD_CREATE gateway events. + // For user accounts, all of the guilds, the user is in, are dispatched in the READY gateway event. Whereas, the guilds are dispatched discretely in the GUILD_CREATE gateway events for bot accounts. if !strings.HasPrefix(c.State.Token, "Bot") { api.UserAgent = userAgent c.State.AddHandler(c.onStateReady) + } else { + c.State.AddIntents(gateway.IntentGuilds | gateway.IntentGuildMessages) } c.State.AddHandler(c.onStateGuildCreate)