diff options
author | Wim <wim@42.be> | 2018-08-06 21:47:05 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2018-08-06 21:47:05 +0200 |
commit | 51062863a5c34d81e296cf15c61140911037cf3b (patch) | |
tree | 9b5e044672486326c7a0ca8fb26430f37bf4d83c /vendor/github.com/bwmarrin/discordgo/examples/avatar | |
parent | 4fb4b7aa6c02a54db8ad8dd98e4d321396926c0d (diff) | |
download | matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.gz matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.bz2 matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.zip |
Use mod vendor for vendored directory (backwards compatible)
Diffstat (limited to 'vendor/github.com/bwmarrin/discordgo/examples/avatar')
-rw-r--r-- | vendor/github.com/bwmarrin/discordgo/examples/avatar/main.go | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/avatar/main.go b/vendor/github.com/bwmarrin/discordgo/examples/avatar/main.go deleted file mode 100644 index e0a9c880..00000000 --- a/vendor/github.com/bwmarrin/discordgo/examples/avatar/main.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - "encoding/base64" - "flag" - "fmt" - "io/ioutil" - "net/http" - "os" - - "github.com/bwmarrin/discordgo" -) - -// Variables used for command line parameters -var ( - Token string - AvatarFile string - AvatarURL string -) - -func init() { - - flag.StringVar(&Token, "t", "", "Bot Token") - flag.StringVar(&AvatarFile, "f", "", "Avatar File Name") - flag.StringVar(&AvatarURL, "u", "", "URL to the avatar image") - flag.Parse() - - if Token == "" || (AvatarFile == "" && AvatarURL == "") { - flag.Usage() - os.Exit(1) - } -} - -func main() { - - // Create a new Discord session using the provided login information. - dg, err := discordgo.New("Bot " + Token) - if err != nil { - fmt.Println("error creating Discord session,", err) - return - } - - // Declare these here so they can be used in the below two if blocks and - // still carry over to the end of this function. - var base64img string - var contentType string - - // If we're using a URL link for the Avatar - if AvatarURL != "" { - - resp, err := http.Get(AvatarURL) - if err != nil { - fmt.Println("Error retrieving the file, ", err) - return - } - - defer func() { - _ = resp.Body.Close() - }() - - img, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println("Error reading the response, ", err) - return - } - - contentType = http.DetectContentType(img) - base64img = base64.StdEncoding.EncodeToString(img) - } - - // If we're using a local file for the Avatar - if AvatarFile != "" { - img, err := ioutil.ReadFile(AvatarFile) - if err != nil { - fmt.Println(err) - } - - contentType = http.DetectContentType(img) - base64img = base64.StdEncoding.EncodeToString(img) - } - - // Now lets format our base64 image into the proper format Discord wants - // and then call UserUpdate to set it as our user's Avatar. - avatar := fmt.Sprintf("data:%s;base64,%s", contentType, base64img) - _, err = dg.UserUpdate("", "", "", avatar, "") - if err != nil { - fmt.Println(err) - } -} |