Add essential intents for bot accounts (#205)
This commit is contained in:
parent
35458a7e3a
commit
e7fccffd2e
2 changed files with 16 additions and 13 deletions
13
main.go
13
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)
|
||||
}
|
||||
|
|
|
|||
16
ui/core.go
16
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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue