util.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains utility functions for the discordgo package. These
  7. // functions are not exported and are likely to change substantially in
  8. // the future to match specific needs of the discordgo package itself.
  9. package discordgo
  10. import (
  11. "bytes"
  12. "encoding/json"
  13. "fmt"
  14. "log"
  15. )
  16. // printEvent prints out a WSAPI event.
  17. func printEvent(e *Event) {
  18. log.Println(fmt.Sprintf("Event. Type: %s, State: %d Operation: %d Direction: %d", e.Type, e.State, e.Operation, e.Direction))
  19. printJSON(e.RawData)
  20. }
  21. // printJSON is a helper function to display JSON data in a easy to read format.
  22. func printJSON(body []byte) {
  23. var prettyJSON bytes.Buffer
  24. error := json.Indent(&prettyJSON, body, "", "\t")
  25. if error != nil {
  26. log.Print("JSON parse error: ", error)
  27. }
  28. log.Println(string(prettyJSON.Bytes()))
  29. }