main.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/bwmarrin/discordgo"
  6. )
  7. // Variables used for command line options
  8. var (
  9. Email string
  10. Password string
  11. Token string
  12. AppName string
  13. DeleteID string
  14. ListOnly bool
  15. )
  16. func init() {
  17. flag.StringVar(&Email, "e", "", "Account Email")
  18. flag.StringVar(&Password, "p", "", "Account Password")
  19. flag.StringVar(&Token, "t", "", "Account Token")
  20. flag.StringVar(&DeleteID, "d", "", "Application ID to delete")
  21. flag.BoolVar(&ListOnly, "l", false, "List Applications Only")
  22. flag.StringVar(&AppName, "a", "", "App/Bot Name")
  23. flag.Parse()
  24. }
  25. func main() {
  26. var err error
  27. // Create a new Discord session using the provided login information.
  28. dg, err := discordgo.New(Email, Password, Token)
  29. if err != nil {
  30. fmt.Println("error creating Discord session,", err)
  31. return
  32. }
  33. // If -l set, only display a list of existing applications
  34. // for the given account.
  35. if ListOnly {
  36. aps, err2 := dg.Applications()
  37. if err2 != nil {
  38. fmt.Println("error fetching applications,", err)
  39. return
  40. }
  41. for k, v := range aps {
  42. fmt.Printf("%d : --------------------------------------\n", k)
  43. fmt.Printf("ID: %s\n", v.ID)
  44. fmt.Printf("Name: %s\n", v.Name)
  45. fmt.Printf("Secret: %s\n", v.Secret)
  46. fmt.Printf("Description: %s\n", v.Description)
  47. }
  48. return
  49. }
  50. // if -d set, delete the given Application
  51. if DeleteID != "" {
  52. err = dg.ApplicationDelete(DeleteID)
  53. if err != nil {
  54. fmt.Println("error deleting application,", err)
  55. }
  56. return
  57. }
  58. // Create a new application.
  59. ap := &discordgo.Application{}
  60. ap.Name = AppName
  61. ap, err = dg.ApplicationCreate(ap)
  62. if err != nil {
  63. fmt.Println("error creating new applicaiton,", err)
  64. return
  65. }
  66. fmt.Printf("Application created successfully:\n")
  67. fmt.Printf("ID: %s\n", ap.ID)
  68. fmt.Printf("Name: %s\n", ap.Name)
  69. fmt.Printf("Secret: %s\n\n", ap.Secret)
  70. // Create the bot account under the application we just created
  71. bot, err := dg.ApplicationBotCreate(ap.ID)
  72. if err != nil {
  73. fmt.Println("error creating bot account,", err)
  74. return
  75. }
  76. fmt.Printf("Bot account created successfully.\n")
  77. fmt.Printf("ID: %s\n", bot.ID)
  78. fmt.Printf("Username: %s\n", bot.Username)
  79. fmt.Printf("Token: %s\n\n", bot.Token)
  80. fmt.Println("Please save the above posted info in a secure place.")
  81. fmt.Println("You will need that information to login with your bot account.")
  82. return
  83. }