main.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/bwmarrin/discordgo"
  6. )
  7. var (
  8. Email string
  9. Password string
  10. Token string
  11. AppName string
  12. ConvToken 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.StringVar(&ConvToken, "c", "", "Token of account to convert.")
  24. flag.Parse()
  25. }
  26. func main() {
  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, err := dg.Applications()
  37. if err != 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. // If ConvToken is set, then this will convert an existing account
  72. // into a bot account under the application we just created.
  73. bot, err := dg.ApplicationBotCreate(ap.ID, ConvToken)
  74. if err != nil {
  75. fmt.Println("error creating bot account,", err)
  76. return
  77. }
  78. fmt.Printf("Bot account created successfully.\n")
  79. fmt.Printf("ID: %s\n", bot.ID)
  80. fmt.Printf("Username: %s\n", bot.Username)
  81. fmt.Printf("Token: %s\n\n", bot.Token)
  82. fmt.Println("Please save the above posted info in a secure place.")
  83. fmt.Println("You will need that information to login with your bot account.")
  84. return
  85. }