summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bwmarrin/discordgo/examples
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-08-06 21:47:05 +0200
committerWim <wim@42.be>2018-08-06 21:47:05 +0200
commit51062863a5c34d81e296cf15c61140911037cf3b (patch)
tree9b5e044672486326c7a0ca8fb26430f37bf4d83c /vendor/github.com/bwmarrin/discordgo/examples
parent4fb4b7aa6c02a54db8ad8dd98e4d321396926c0d (diff)
downloadmatterbridge-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')
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/airhorn/main.go211
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/appmaker/main.go103
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/avatar/main.go89
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/mytoken/main.go40
-rw-r--r--vendor/github.com/bwmarrin/discordgo/examples/pingpong/main.go71
5 files changed, 0 insertions, 514 deletions
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/airhorn/main.go b/vendor/github.com/bwmarrin/discordgo/examples/airhorn/main.go
deleted file mode 100644
index 21ceb76b..00000000
--- a/vendor/github.com/bwmarrin/discordgo/examples/airhorn/main.go
+++ /dev/null
@@ -1,211 +0,0 @@
-package main
-
-import (
- "encoding/binary"
- "flag"
- "fmt"
- "io"
- "os"
- "os/signal"
- "strings"
- "syscall"
- "time"
-
- "github.com/bwmarrin/discordgo"
-)
-
-func init() {
- flag.StringVar(&token, "t", "", "Bot Token")
- flag.Parse()
-}
-
-var token string
-var buffer = make([][]byte, 0)
-
-func main() {
-
- if token == "" {
- fmt.Println("No token provided. Please run: airhorn -t <bot token>")
- return
- }
-
- // Load the sound file.
- err := loadSound()
- if err != nil {
- fmt.Println("Error loading sound: ", err)
- fmt.Println("Please copy $GOPATH/src/github.com/bwmarrin/examples/airhorn/airhorn.dca to this directory.")
- return
- }
-
- // Create a new Discord session using the provided bot token.
- dg, err := discordgo.New("Bot " + token)
- if err != nil {
- fmt.Println("Error creating Discord session: ", err)
- return
- }
-
- // Register ready as a callback for the ready events.
- dg.AddHandler(ready)
-
- // Register messageCreate as a callback for the messageCreate events.
- dg.AddHandler(messageCreate)
-
- // Register guildCreate as a callback for the guildCreate events.
- dg.AddHandler(guildCreate)
-
- // Open the websocket and begin listening.
- err = dg.Open()
- if err != nil {
- fmt.Println("Error opening Discord session: ", err)
- }
-
- // Wait here until CTRL-C or other term signal is received.
- fmt.Println("Airhorn is now running. Press CTRL-C to exit.")
- sc := make(chan os.Signal, 1)
- signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
- <-sc
-
- // Cleanly close down the Discord session.
- dg.Close()
-}
-
-// This function will be called (due to AddHandler above) when the bot receives
-// the "ready" event from Discord.
-func ready(s *discordgo.Session, event *discordgo.Ready) {
-
- // Set the playing status.
- s.UpdateStatus(0, "!airhorn")
-}
-
-// This function will be called (due to AddHandler above) every time a new
-// message is created on any channel that the autenticated bot has access to.
-func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
-
- // Ignore all messages created by the bot itself
- // This isn't required in this specific example but it's a good practice.
- if m.Author.ID == s.State.User.ID {
- return
- }
-
- // check if the message is "!airhorn"
- if strings.HasPrefix(m.Content, "!airhorn") {
-
- // Find the channel that the message came from.
- c, err := s.State.Channel(m.ChannelID)
- if err != nil {
- // Could not find channel.
- return
- }
-
- // Find the guild for that channel.
- g, err := s.State.Guild(c.GuildID)
- if err != nil {
- // Could not find guild.
- return
- }
-
- // Look for the message sender in that guild's current voice states.
- for _, vs := range g.VoiceStates {
- if vs.UserID == m.Author.ID {
- err = playSound(s, g.ID, vs.ChannelID)
- if err != nil {
- fmt.Println("Error playing sound:", err)
- }
-
- return
- }
- }
- }
-}
-
-// This function will be called (due to AddHandler above) every time a new
-// guild is joined.
-func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
-
- if event.Guild.Unavailable {
- return
- }
-
- for _, channel := range event.Guild.Channels {
- if channel.ID == event.Guild.ID {
- _, _ = s.ChannelMessageSend(channel.ID, "Airhorn is ready! Type !airhorn while in a voice channel to play a sound.")
- return
- }
- }
-}
-
-// loadSound attempts to load an encoded sound file from disk.
-func loadSound() error {
-
- file, err := os.Open("airhorn.dca")
- if err != nil {
- fmt.Println("Error opening dca file :", err)
- return err
- }
-
- var opuslen int16
-
- for {
- // Read opus frame length from dca file.
- err = binary.Read(file, binary.LittleEndian, &opuslen)
-
- // If this is the end of the file, just return.
- if err == io.EOF || err == io.ErrUnexpectedEOF {
- err := file.Close()
- if err != nil {
- return err
- }
- return nil
- }
-
- if err != nil {
- fmt.Println("Error reading from dca file :", err)
- return err
- }
-
- // Read encoded pcm from dca file.
- InBuf := make([]byte, opuslen)
- err = binary.Read(file, binary.LittleEndian, &InBuf)
-
- // Should not be any end of file errors
- if err != nil {
- fmt.Println("Error reading from dca file :", err)
- return err
- }
-
- // Append encoded pcm data to the buffer.
- buffer = append(buffer, InBuf)
- }
-}
-
-// playSound plays the current buffer to the provided channel.
-func playSound(s *discordgo.Session, guildID, channelID string) (err error) {
-
- // Join the provided voice channel.
- vc, err := s.ChannelVoiceJoin(guildID, channelID, false, true)
- if err != nil {
- return err
- }
-
- // Sleep for a specified amount of time before playing the sound
- time.Sleep(250 * time.Millisecond)
-
- // Start speaking.
- vc.Speaking(true)
-
- // Send the buffer data.
- for _, buff := range buffer {
- vc.OpusSend <- buff
- }
-
- // Stop speaking
- vc.Speaking(false)
-
- // Sleep for a specificed amount of time before ending.
- time.Sleep(250 * time.Millisecond)
-
- // Disconnect from the provided voice channel.
- vc.Disconnect()
-
- return nil
-}
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/appmaker/main.go b/vendor/github.com/bwmarrin/discordgo/examples/appmaker/main.go
deleted file mode 100644
index 5581dd93..00000000
--- a/vendor/github.com/bwmarrin/discordgo/examples/appmaker/main.go
+++ /dev/null
@@ -1,103 +0,0 @@
-package main
-
-import (
- "encoding/json"
- "flag"
- "fmt"
- "os"
-
- "github.com/bwmarrin/discordgo"
-)
-
-// Variables used for command line options
-var (
- Token string
- Name string
- DeleteID string
- ListOnly bool
-)
-
-func init() {
-
- flag.StringVar(&Token, "t", "", "Owner Account Token")
- flag.StringVar(&Name, "n", "", "Name to give App/Bot")
- flag.StringVar(&DeleteID, "d", "", "Application ID to delete")
- flag.BoolVar(&ListOnly, "l", false, "List Applications Only")
- flag.Parse()
-
- if Token == "" {
- flag.Usage()
- os.Exit(1)
- }
-}
-
-func main() {
-
- var err error
-
- // Create a new Discord session using the provided login information.
- dg, err := discordgo.New(Token)
- if err != nil {
- fmt.Println("error creating Discord session,", err)
- return
- }
-
- // If -l set, only display a list of existing applications
- // for the given account.
- if ListOnly {
-
- aps, err := dg.Applications()
- if err != nil {
- fmt.Println("error fetching applications,", err)
- return
- }
-
- for _, v := range aps {
- fmt.Println("-----------------------------------------------------")
- b, _ := json.MarshalIndent(v, "", " ")
- fmt.Println(string(b))
- }
- return
- }
-
- // if -d set, delete the given Application
- if DeleteID != "" {
- err = dg.ApplicationDelete(DeleteID)
- if err != nil {
- fmt.Println("error deleting application,", err)
- }
- return
- }
-
- if Name == "" {
- flag.Usage()
- os.Exit(1)
- }
-
- // Create a new application.
- ap := &discordgo.Application{}
- ap.Name = Name
- ap, err = dg.ApplicationCreate(ap)
- if err != nil {
- fmt.Println("error creating new application,", err)
- return
- }
-
- fmt.Printf("Application created successfully:\n")
- b, _ := json.MarshalIndent(ap, "", " ")
- fmt.Println(string(b))
-
- // Create the bot account under the application we just created
- bot, err := dg.ApplicationBotCreate(ap.ID)
- if err != nil {
- fmt.Println("error creating bot account,", err)
- return
- }
-
- fmt.Printf("Bot account created successfully.\n")
- b, _ = json.MarshalIndent(bot, "", " ")
- fmt.Println(string(b))
-
- fmt.Println("Please save the above posted info in a secure place.")
- fmt.Println("You will need that information to login with your bot account.")
-}
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)
- }
-}
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/mytoken/main.go b/vendor/github.com/bwmarrin/discordgo/examples/mytoken/main.go
deleted file mode 100644
index 9375eadc..00000000
--- a/vendor/github.com/bwmarrin/discordgo/examples/mytoken/main.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package main
-
-import (
- "flag"
- "fmt"
- "os"
-
- "github.com/bwmarrin/discordgo"
-)
-
-// Variables used for command line parameters
-var (
- Email string
- Password string
-)
-
-func init() {
-
- flag.StringVar(&Email, "e", "", "Account Email")
- flag.StringVar(&Password, "p", "", "Account Password")
- flag.Parse()
-
- if Email == "" || Password == "" {
- flag.Usage()
- os.Exit(1)
- }
-}
-
-func main() {
-
- // Create a new Discord session using the provided login information.
- dg, err := discordgo.New(Email, Password)
- if err != nil {
- fmt.Println("error creating Discord session,", err)
- return
- }
-
- // Print out your token.
- fmt.Printf("Your Authentication Token is:\n\n%s\n", dg.Token)
-}
diff --git a/vendor/github.com/bwmarrin/discordgo/examples/pingpong/main.go b/vendor/github.com/bwmarrin/discordgo/examples/pingpong/main.go
deleted file mode 100644
index 155e782f..00000000
--- a/vendor/github.com/bwmarrin/discordgo/examples/pingpong/main.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package main
-
-import (
- "flag"
- "fmt"
- "os"
- "os/signal"
- "syscall"
-
- "github.com/bwmarrin/discordgo"
-)
-
-// Variables used for command line parameters
-var (
- Token string
-)
-
-func init() {
-
- flag.StringVar(&Token, "t", "", "Bot Token")
- flag.Parse()
-}
-
-func main() {
-
- // Create a new Discord session using the provided bot token.
- dg, err := discordgo.New("Bot " + Token)
- if err != nil {
- fmt.Println("error creating Discord session,", err)
- return
- }
-
- // Register the messageCreate func as a callback for MessageCreate events.
- dg.AddHandler(messageCreate)
-
- // Open a websocket connection to Discord and begin listening.
- err = dg.Open()
- if err != nil {
- fmt.Println("error opening connection,", err)
- return
- }
-
- // Wait here until CTRL-C or other term signal is received.
- fmt.Println("Bot is now running. Press CTRL-C to exit.")
- sc := make(chan os.Signal, 1)
- signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
- <-sc
-
- // Cleanly close down the Discord session.
- dg.Close()
-}
-
-// This function will be called (due to AddHandler above) every time a new
-// message is created on any channel that the autenticated bot has access to.
-func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
-
- // Ignore all messages created by the bot itself
- // This isn't required in this specific example but it's a good practice.
- if m.Author.ID == s.State.User.ID {
- return
- }
- // If the message is "ping" reply with "Pong!"
- if m.Content == "ping" {
- s.ChannelMessageSend(m.ChannelID, "Pong!")
- }
-
- // If the message is "pong" reply with "Ping!"
- if m.Content == "pong" {
- s.ChannelMessageSend(m.ChannelID, "Ping!")
- }
-}