main.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "encoding/base64"
  4. "flag"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. "github.com/bwmarrin/discordgo"
  9. )
  10. // Variables used for command line parameters
  11. var (
  12. Email string
  13. Password string
  14. Token string
  15. Avatar string
  16. BotID string
  17. BotUsername string
  18. )
  19. func init() {
  20. flag.StringVar(&Email, "e", "", "Account Email")
  21. flag.StringVar(&Password, "p", "", "Account Password")
  22. flag.StringVar(&Token, "t", "", "Account Token")
  23. flag.StringVar(&Avatar, "f", "./avatar.jpg", "Avatar File Name")
  24. flag.Parse()
  25. }
  26. func main() {
  27. // Create a new Discord session using the provided login information.
  28. // Use discordgo.New(Token) to just use a token for login.
  29. dg, err := discordgo.New(Email, Password, Token)
  30. if err != nil {
  31. fmt.Println("error creating Discord session,", err)
  32. return
  33. }
  34. bot, err := dg.User("@me")
  35. if err != nil {
  36. fmt.Println("error fetching the bot details,", err)
  37. return
  38. }
  39. BotID = bot.ID
  40. BotUsername = bot.Username
  41. changeAvatar(dg)
  42. fmt.Println("Bot is now running. Press CTRL-C to exit.")
  43. // Simple way to keep program running until CTRL-C is pressed.
  44. <-make(chan struct{})
  45. return
  46. }
  47. // Helper function to change the avatar
  48. func changeAvatar(s *discordgo.Session) {
  49. img, err := ioutil.ReadFile(Avatar)
  50. if err != nil {
  51. fmt.Println(err)
  52. }
  53. base64 := base64.StdEncoding.EncodeToString(img)
  54. avatar := fmt.Sprintf("data:%s;base64,%s", http.DetectContentType(img), base64)
  55. _, err = s.UserUpdate("", "", BotUsername, avatar, "")
  56. if err != nil {
  57. fmt.Println(err)
  58. }
  59. }