diff options
Diffstat (limited to 'vendor/github.com/matterbridge/discordgo')
9 files changed, 161 insertions, 638 deletions
diff --git a/vendor/github.com/matterbridge/discordgo/.travis.yml b/vendor/github.com/matterbridge/discordgo/.travis.yml new file mode 100644 index 00000000..fe626fcf --- /dev/null +++ b/vendor/github.com/matterbridge/discordgo/.travis.yml @@ -0,0 +1,14 @@ +language: go +go: + - 1.7.x + - 1.8.x + - 1.9.x +install: + - go get github.com/bwmarrin/discordgo + - go get -v . + - go get -v github.com/golang/lint/golint +script: + - diff <(gofmt -d .) <(echo -n) + - go vet -x ./... + - golint -set_exit_status ./... + - go test -v -race ./... diff --git a/vendor/github.com/matterbridge/discordgo/README.md b/vendor/github.com/matterbridge/discordgo/README.md new file mode 100644 index 00000000..acc72bf1 --- /dev/null +++ b/vendor/github.com/matterbridge/discordgo/README.md @@ -0,0 +1,130 @@ +# DiscordGo + +[![GoDoc](https://godoc.org/github.com/bwmarrin/discordgo?status.svg)](https://godoc.org/github.com/bwmarrin/discordgo) [![Go report](http://goreportcard.com/badge/bwmarrin/discordgo)](http://goreportcard.com/report/bwmarrin/discordgo) [![Build Status](https://travis-ci.org/bwmarrin/discordgo.svg?branch=master)](https://travis-ci.org/bwmarrin/discordgo) [![Discord Gophers](https://img.shields.io/badge/Discord%20Gophers-%23discordgo-blue.svg)](https://discord.gg/0f1SbxBZjYoCtNPP) [![Discord API](https://img.shields.io/badge/Discord%20API-%23go_discordgo-blue.svg)](https://discord.gg/0SBTUU1wZTWT6sqd) + +<img align="right" src="http://bwmarrin.github.io/discordgo/img/discordgo.png"> + +DiscordGo is a [Go](https://golang.org/) package that provides low level +bindings to the [Discord](https://discordapp.com/) chat client API. DiscordGo +has nearly complete support for all of the Discord API endpoints, websocket +interface, and voice interface. + +If you would like to help the DiscordGo package please use +[this link](https://discordapp.com/oauth2/authorize?client_id=173113690092994561&scope=bot) +to add the official DiscordGo test bot **dgo** to your server. This provides +indispensable help to this project. + +* See [dgVoice](https://github.com/bwmarrin/dgvoice) package for an example of +additional voice helper functions and features for DiscordGo + +* See [dca](https://github.com/bwmarrin/dca) for an **experimental** stand alone +tool that wraps `ffmpeg` to create opus encoded audio appropriate for use with +Discord (and DiscordGo) + +**For help with this package or general Go discussion, please join the [Discord +Gophers](https://discord.gg/0f1SbxBZjYq9jLBk) chat server.** + +## Getting Started + +### master vs develop Branch +* The master branch represents the latest released version of DiscordGo. This +branch will always have a stable and tested version of the library. Each release +is tagged and you can easily download a specific release and view release notes +on the github [releases](https://github.com/bwmarrin/discordgo/releases) page. + +* The develop branch is where all development happens and almost always has +new features over the master branch. However breaking changes are frequently +added to develop and even sometimes bugs are introduced. Bugs get fixed and +the breaking changes get documented before pushing to master. + +*So, what should you use?* + +If you can accept the constant changing nature of *develop* then it is the +recommended branch to use. Otherwise, if you want to tail behind development +slightly and have a more stable package with documented releases then use *master* + +### Installing + +This assumes you already have a working Go environment, if not please see +[this page](https://golang.org/doc/install) first. + +`go get` *will always pull the latest released version from the master branch.* + +```sh +go get github.com/bwmarrin/discordgo +``` + +If you want to use the develop branch, follow these steps next. + +```sh +cd $GOPATH/src/github.com/bwmarrin/discordgo +git checkout develop +``` + +### Usage + +Import the package into your project. + +```go +import "github.com/bwmarrin/discordgo" +``` + +Construct a new Discord client which can be used to access the variety of +Discord API functions and to set callback functions for Discord events. + +```go +discord, err := discordgo.New("Bot " + "authentication token") +``` + +See Documentation and Examples below for more detailed information. + + +## Documentation + +**NOTICE** : This library and the Discord API are unfinished. +Because of that there may be major changes to library in the future. + +The DiscordGo code is fairly well documented at this point and is currently +the only documentation available. Both GoDoc and GoWalker (below) present +that information in a nice format. + +- [![GoDoc](https://godoc.org/github.com/bwmarrin/discordgo?status.svg)](https://godoc.org/github.com/bwmarrin/discordgo) +- [![Go Walker](http://gowalker.org/api/v1/badge)](https://gowalker.org/github.com/bwmarrin/discordgo) +- Hand crafted documentation coming eventually. + + +## Examples + +Below is a list of examples and other projects using DiscordGo. Please submit +an issue if you would like your project added or removed from this list + +- [DiscordGo Examples](https://github.com/bwmarrin/discordgo/tree/master/examples) A collection of example programs written with DiscordGo +- [Awesome DiscordGo](https://github.com/bwmarrin/discordgo/wiki/Awesome-DiscordGo) A curated list of high quality projects using DiscordGo + +## Troubleshooting +For help with common problems please reference the +[Troubleshooting](https://github.com/bwmarrin/discordgo/wiki/Troubleshooting) +section of the project wiki. + + +## Contributing +Contributions are very welcomed, however please follow the below guidelines. + +- First open an issue describing the bug or enhancement so it can be +discussed. +- Fork the develop branch and make your changes. +- Try to match current naming conventions as closely as possible. +- This package is intended to be a low level direct mapping of the Discord API +so please avoid adding enhancements outside of that scope without first +discussing it. +- Create a Pull Request with your changes against the develop branch. + + +## List of Discord APIs + +See [this chart](https://abal.moe/Discord/Libraries.html) for a feature +comparison and list of other Discord API libraries. + +## Special Thanks + +[Chris Rhodes](https://github.com/iopred) - For the DiscordGo logo and tons of PRs diff --git a/vendor/github.com/matterbridge/discordgo/examples/airhorn/main.go b/vendor/github.com/matterbridge/discordgo/examples/airhorn/main.go deleted file mode 100644 index 21ceb76b..00000000 --- a/vendor/github.com/matterbridge/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/matterbridge/discordgo/examples/appmaker/main.go b/vendor/github.com/matterbridge/discordgo/examples/appmaker/main.go deleted file mode 100644 index 5581dd93..00000000 --- a/vendor/github.com/matterbridge/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/matterbridge/discordgo/examples/avatar/main.go b/vendor/github.com/matterbridge/discordgo/examples/avatar/main.go deleted file mode 100644 index e0a9c880..00000000 --- a/vendor/github.com/matterbridge/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/matterbridge/discordgo/examples/mytoken/main.go b/vendor/github.com/matterbridge/discordgo/examples/mytoken/main.go deleted file mode 100644 index 9375eadc..00000000 --- a/vendor/github.com/matterbridge/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/matterbridge/discordgo/examples/pingpong/main.go b/vendor/github.com/matterbridge/discordgo/examples/pingpong/main.go deleted file mode 100644 index 155e782f..00000000 --- a/vendor/github.com/matterbridge/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!") - } -} diff --git a/vendor/github.com/matterbridge/discordgo/mkdocs.yml b/vendor/github.com/matterbridge/discordgo/mkdocs.yml new file mode 100644 index 00000000..3ee8eb37 --- /dev/null +++ b/vendor/github.com/matterbridge/discordgo/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: DiscordGo +site_author: Bruce Marriner +site_url: http://bwmarrin.github.io/discordgo/ +repo_url: https://github.com/bwmarrin/discordgo + +dev_addr: 0.0.0.0:8000 +theme: yeti + +markdown_extensions: + - smarty + - toc: + permalink: True + - sane_lists + +pages: + - 'Home': 'index.md' + - 'Getting Started': 'GettingStarted.md' diff --git a/vendor/github.com/matterbridge/discordgo/tools/cmd/eventhandlers/main.go b/vendor/github.com/matterbridge/discordgo/tools/cmd/eventhandlers/main.go deleted file mode 100644 index 839f009d..00000000 --- a/vendor/github.com/matterbridge/discordgo/tools/cmd/eventhandlers/main.go +++ /dev/null @@ -1,124 +0,0 @@ -package main - -import ( - "bytes" - "go/format" - "go/parser" - "go/token" - "io/ioutil" - "log" - "path/filepath" - "regexp" - "sort" - "strings" - "text/template" -) - -var eventHandlerTmpl = template.Must(template.New("eventHandler").Funcs(template.FuncMap{ - "constName": constName, - "isDiscordEvent": isDiscordEvent, - "privateName": privateName, -}).Parse(`// Code generated by \"eventhandlers\"; DO NOT EDIT -// See events.go - -package discordgo - -// Following are all the event types. -// Event type values are used to match the events returned by Discord. -// EventTypes surrounded by __ are synthetic and are internal to DiscordGo. -const ({{range .}} - {{privateName .}}EventType = "{{constName .}}"{{end}} -) -{{range .}} -// {{privateName .}}EventHandler is an event handler for {{.}} events. -type {{privateName .}}EventHandler func(*Session, *{{.}}) - -// Type returns the event type for {{.}} events. -func (eh {{privateName .}}EventHandler) Type() string { - return {{privateName .}}EventType -} -{{if isDiscordEvent .}} -// New returns a new instance of {{.}}. -func (eh {{privateName .}}EventHandler) New() interface{} { - return &{{.}}{} -}{{end}} -// Handle is the handler for {{.}} events. -func (eh {{privateName .}}EventHandler) Handle(s *Session, i interface{}) { - if t, ok := i.(*{{.}}); ok { - eh(s, t) - } -} - -{{end}} -func handlerForInterface(handler interface{}) EventHandler { - switch v := handler.(type) { - case func(*Session, interface{}): - return interfaceEventHandler(v){{range .}} - case func(*Session, *{{.}}): - return {{privateName .}}EventHandler(v){{end}} - } - - return nil -} - -func init() { {{range .}}{{if isDiscordEvent .}} - registerInterfaceProvider({{privateName .}}EventHandler(nil)){{end}}{{end}} -} -`)) - -func main() { - var buf bytes.Buffer - dir := filepath.Dir(".") - - fs := token.NewFileSet() - parsedFile, err := parser.ParseFile(fs, "events.go", nil, 0) - if err != nil { - log.Fatalf("warning: internal error: could not parse events.go: %s", err) - return - } - - names := []string{} - for object := range parsedFile.Scope.Objects { - names = append(names, object) - } - sort.Strings(names) - eventHandlerTmpl.Execute(&buf, names) - - src, err := format.Source(buf.Bytes()) - if err != nil { - log.Println("warning: internal error: invalid Go generated:", err) - src = buf.Bytes() - } - - err = ioutil.WriteFile(filepath.Join(dir, strings.ToLower("eventhandlers.go")), src, 0644) - if err != nil { - log.Fatal(buf, "writing output: %s", err) - } -} - -var constRegexp = regexp.MustCompile("([a-z])([A-Z])") - -func constCase(name string) string { - return strings.ToUpper(constRegexp.ReplaceAllString(name, "${1}_${2}")) -} - -func isDiscordEvent(name string) bool { - switch { - case name == "Connect", name == "Disconnect", name == "Event", name == "RateLimit", name == "Interface": - return false - default: - return true - } -} - -func constName(name string) string { - if !isDiscordEvent(name) { - return "__" + constCase(name) + "__" - } - - return constCase(name) -} - -func privateName(name string) string { - return strings.ToLower(string(name[0])) + name[1:] -} |