main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "path/filepath"
  7. "runtime"
  8. "github.com/ayntgl/discordo/config"
  9. "github.com/ayntgl/discordo/ui"
  10. "github.com/diamondburned/arikawa/v3/api"
  11. "github.com/diamondburned/arikawa/v3/gateway"
  12. "github.com/rivo/tview"
  13. "github.com/zalando/go-keyring"
  14. )
  15. func init() {
  16. path, err := os.UserCacheDir()
  17. if err != nil {
  18. log.Fatal(err)
  19. }
  20. path = filepath.Join(path, config.Name)
  21. err = os.MkdirAll(path, os.ModePerm)
  22. if err != nil {
  23. log.Fatal(err)
  24. }
  25. path = filepath.Join(path, "out.log")
  26. f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, os.ModePerm)
  27. if err != nil {
  28. log.Fatal(err)
  29. }
  30. log.SetOutput(f)
  31. log.SetFlags(log.LstdFlags | log.Lshortfile)
  32. tview.Borders.TopLeftFocus = tview.Borders.TopLeft
  33. tview.Borders.TopRightFocus = tview.Borders.TopRight
  34. tview.Borders.BottomLeftFocus = tview.Borders.BottomLeft
  35. tview.Borders.BottomRightFocus = tview.Borders.BottomRight
  36. tview.Borders.HorizontalFocus = tview.Borders.Horizontal
  37. tview.Borders.VerticalFocus = tview.Borders.Vertical
  38. tview.Borders.TopLeft = 0
  39. tview.Borders.TopRight = 0
  40. tview.Borders.BottomLeft = 0
  41. tview.Borders.BottomRight = 0
  42. tview.Borders.Horizontal = 0
  43. tview.Borders.Vertical = 0
  44. api.UserAgent = fmt.Sprintf("%s/%s %s/%s", config.Name, "0.1", "arikawa", "v3")
  45. gateway.DefaultIdentity = gateway.IdentifyProperties{
  46. OS: runtime.GOOS,
  47. Browser: config.Name,
  48. Device: "",
  49. }
  50. }
  51. func main() {
  52. cfg := config.New()
  53. err := cfg.Load()
  54. if err != nil {
  55. log.Fatal(err)
  56. }
  57. token, err := keyring.Get(config.Name, "token")
  58. if err != nil {
  59. log.Println(err)
  60. }
  61. c := ui.NewCore(cfg)
  62. if token != "" {
  63. err = c.Run(token)
  64. if err != nil {
  65. log.Fatal(err)
  66. }
  67. c.Draw()
  68. } else {
  69. loginView := ui.NewLoginView(c)
  70. c.App.SetRoot(loginView, true)
  71. }
  72. err = c.App.Run()
  73. if err != nil {
  74. log.Fatal(err)
  75. }
  76. }