summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bwmarrin/discordgo/examples/avatar
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-09-19 20:53:26 +0200
committerWim <wim@42.be>2016-09-19 20:53:26 +0200
commita0b84beb9bae3514940a0cde40948e885184f555 (patch)
tree0e8d22c5e2292c24e46699e59f442795b6158b3a /vendor/github.com/bwmarrin/discordgo/examples/avatar
parent0816e968318be5a4b165ac8fd30c032c6ecce61c (diff)
downloadmatterbridge-msglm-a0b84beb9bae3514940a0cde40948e885184f555.tar.gz
matterbridge-msglm-a0b84beb9bae3514940a0cde40948e885184f555.tar.bz2
matterbridge-msglm-a0b84beb9bae3514940a0cde40948e885184f555.zip
Add Discord support
Diffstat (limited to 'vendor/github.com/bwmarrin/discordgo/examples/avatar')
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/avatar/localfile/main.go73
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/avatar/url/main.go86
2 files changed, 159 insertions, 0 deletions
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/avatar/localfile/main.go b/vendor/github.com/bwmarrin/discordgo/examples/avatar/localfile/main.go
new file mode 100644
index 00000000..adfe0b1d
--- /dev/null
+++ b/vendor/github.com/bwmarrin/discordgo/examples/avatar/localfile/main.go
@@ -0,0 +1,73 @@
+package main
+
+import (
+ "encoding/base64"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/bwmarrin/discordgo"
+)
+
+// Variables used for command line parameters
+var (
+ Email string
+ Password string
+ Token string
+ Avatar string
+ BotID string
+ BotUsername string
+)
+
+func init() {
+
+ flag.StringVar(&Email, "e", "", "Account Email")
+ flag.StringVar(&Password, "p", "", "Account Password")
+ flag.StringVar(&Token, "t", "", "Account Token")
+ flag.StringVar(&Avatar, "f", "./avatar.jpg", "Avatar File Name")
+ flag.Parse()
+}
+
+func main() {
+
+ // Create a new Discord session using the provided login information.
+ // Use discordgo.New(Token) to just use a token for login.
+ dg, err := discordgo.New(Email, Password, Token)
+ if err != nil {
+ fmt.Println("error creating Discord session,", err)
+ return
+ }
+
+ bot, err := dg.User("@me")
+ if err != nil {
+ fmt.Println("error fetching the bot details,", err)
+ return
+ }
+
+ BotID = bot.ID
+ BotUsername = bot.Username
+ changeAvatar(dg)
+
+ fmt.Println("Bot is now running. Press CTRL-C to exit.")
+ // Simple way to keep program running until CTRL-C is pressed.
+ <-make(chan struct{})
+ return
+}
+
+// Helper function to change the avatar
+func changeAvatar(s *discordgo.Session) {
+ img, err := ioutil.ReadFile(Avatar)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ base64 := base64.StdEncoding.EncodeToString(img)
+
+ avatar := fmt.Sprintf("data:%s;base64,%s", http.DetectContentType(img), base64)
+
+ _, err = s.UserUpdate("", "", BotUsername, avatar, "")
+ if err != nil {
+ fmt.Println(err)
+ }
+}
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/avatar/url/main.go b/vendor/github.com/bwmarrin/discordgo/examples/avatar/url/main.go
new file mode 100644
index 00000000..26170df5
--- /dev/null
+++ b/vendor/github.com/bwmarrin/discordgo/examples/avatar/url/main.go
@@ -0,0 +1,86 @@
+package main
+
+import (
+ "encoding/base64"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/bwmarrin/discordgo"
+)
+
+// Variables used for command line parameters
+var (
+ Email string
+ Password string
+ Token string
+ URL string
+ BotID string
+ BotUsername string
+)
+
+func init() {
+
+ flag.StringVar(&Email, "e", "", "Account Email")
+ flag.StringVar(&Password, "p", "", "Account Password")
+ flag.StringVar(&Token, "t", "", "Account Token")
+ flag.StringVar(&URL, "l", "http://bwmarrin.github.io/discordgo/img/discordgo.png", "Link to the avatar image")
+ flag.Parse()
+}
+
+func main() {
+
+ // Create a new Discord session using the provided login information.
+ // Use discordgo.New(Token) to just use a token for login.
+ dg, err := discordgo.New(Email, Password, Token)
+ if err != nil {
+ fmt.Println("error creating Discord session,", err)
+ return
+ }
+
+ bot, err := dg.User("@me")
+ if err != nil {
+ fmt.Println("error fetching the bot details,", err)
+ return
+ }
+
+ BotID = bot.ID
+ BotUsername = bot.Username
+ changeAvatar(dg)
+
+ fmt.Println("Bot is now running. Press CTRL-C to exit.")
+ // Simple way to keep program running until CTRL-C is pressed.
+ <-make(chan struct{})
+ return
+}
+
+// Helper function to change the avatar
+func changeAvatar(s *discordgo.Session) {
+
+ resp, err := http.Get(URL)
+ 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
+ }
+
+ base64 := base64.StdEncoding.EncodeToString(img)
+
+ avatar := fmt.Sprintf("data:%s;base64,%s", http.DetectContentType(img), base64)
+
+ _, err = s.UserUpdate("", "", BotUsername, avatar, "")
+ if err != nil {
+ fmt.Println("Error setting the avatar, ", err)
+ }
+
+}