main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "runtime"
  6. "github.com/ayntgl/discordo/config"
  7. "github.com/ayntgl/discordo/ui"
  8. "github.com/diamondburned/arikawa/v3/api"
  9. "github.com/diamondburned/arikawa/v3/gateway"
  10. "github.com/rivo/tview"
  11. "github.com/zalando/go-keyring"
  12. )
  13. func init() {
  14. tview.Borders.TopLeftFocus = tview.Borders.TopLeft
  15. tview.Borders.TopRightFocus = tview.Borders.TopRight
  16. tview.Borders.BottomLeftFocus = tview.Borders.BottomLeft
  17. tview.Borders.BottomRightFocus = tview.Borders.BottomRight
  18. tview.Borders.HorizontalFocus = tview.Borders.Horizontal
  19. tview.Borders.VerticalFocus = tview.Borders.Vertical
  20. tview.Borders.TopLeft = 0
  21. tview.Borders.TopRight = 0
  22. tview.Borders.BottomLeft = 0
  23. tview.Borders.BottomRight = 0
  24. tview.Borders.Horizontal = 0
  25. tview.Borders.Vertical = 0
  26. api.UserAgent = fmt.Sprintf("%s/%s %s/%s", config.Name, "0.1", "arikawa", "v3")
  27. gateway.DefaultIdentity = gateway.IdentifyProperties{
  28. OS: runtime.GOOS,
  29. Browser: config.Name,
  30. Device: "",
  31. }
  32. }
  33. func main() {
  34. cfg := config.New()
  35. err := cfg.Load()
  36. if err != nil {
  37. log.Fatal(err)
  38. }
  39. c := ui.NewCore(cfg)
  40. token, _ := keyring.Get(config.Name, "token")
  41. if token != "" {
  42. err = c.Run(token)
  43. if err != nil {
  44. log.Fatal(err)
  45. }
  46. c.Draw()
  47. } else {
  48. loginView := ui.NewLoginView(c)
  49. c.App.SetRoot(loginView, true)
  50. }
  51. err = c.App.Run()
  52. if err != nil {
  53. log.Fatal(err)
  54. }
  55. }