app.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package ui
  2. import (
  3. "github.com/ayntgl/discordgo"
  4. "github.com/ayntgl/discordo/config"
  5. "github.com/rivo/tview"
  6. )
  7. type App struct {
  8. *tview.Application
  9. ChannelsTreeView *tview.TreeView
  10. MessagesTextView *tview.TextView
  11. MessageInputField *tview.InputField
  12. Session *discordgo.Session
  13. }
  14. func NewApp() *App {
  15. s, _ := discordgo.New()
  16. return &App{
  17. Application: tview.NewApplication(),
  18. ChannelsTreeView: tview.NewTreeView(),
  19. MessagesTextView: tview.NewTextView(),
  20. MessageInputField: tview.NewInputField(),
  21. Session: s,
  22. }
  23. }
  24. func (app *App) Connect(token string) error {
  25. app.Session.Token = token
  26. app.Session.UserAgent = config.General.UserAgent
  27. app.Session.Identify.Token = token
  28. app.Session.Identify.Compress = false
  29. app.Session.Identify.Intents = 0
  30. app.Session.Identify.LargeThreshold = 0
  31. app.Session.Identify.Properties.Device = ""
  32. app.Session.Identify.Properties.Browser = "Firefox"
  33. app.Session.Identify.Properties.OS = "Linux"
  34. // app.Session.AddHandlerOnce(onSessionReady)
  35. // app.Session.AddHandler(onSessionMessageCreate)
  36. return app.Session.Open()
  37. }