repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
bwmarrin/discordgo
voice.go
udpOpen
func (v *VoiceConnection) udpOpen() (err error) { v.Lock() defer v.Unlock() if v.wsConn == nil { return fmt.Errorf("nil voice websocket") } if v.udpConn != nil { return fmt.Errorf("udp connection already open") } if v.close == nil { return fmt.Errorf("nil close channel") } if v.endpoint == "" { return fmt.Errorf("empty endpoint") } host := strings.TrimSuffix(v.endpoint, ":80") + ":" + strconv.Itoa(v.op2.Port) addr, err := net.ResolveUDPAddr("udp", host) if err != nil { v.log(LogWarning, "error resolving udp host %s, %s", host, err) return } v.log(LogInformational, "connecting to udp addr %s", addr.String()) v.udpConn, err = net.DialUDP("udp", nil, addr) if err != nil { v.log(LogWarning, "error connecting to udp addr %s, %s", addr.String(), err) return } // Create a 70 byte array and put the SSRC code from the Op 2 VoiceConnection event // into it. Then send that over the UDP connection to Discord sb := make([]byte, 70) binary.BigEndian.PutUint32(sb, v.op2.SSRC) _, err = v.udpConn.Write(sb) if err != nil { v.log(LogWarning, "udp write error to %s, %s", addr.String(), err) return } // Create a 70 byte array and listen for the initial handshake response // from Discord. Once we get it parse the IP and PORT information out // of the response. This should be our public IP and PORT as Discord // saw us. rb := make([]byte, 70) rlen, _, err := v.udpConn.ReadFromUDP(rb) if err != nil { v.log(LogWarning, "udp read error, %s, %s", addr.String(), err) return } if rlen < 70 { v.log(LogWarning, "received udp packet too small") return fmt.Errorf("received udp packet too small") } // Loop over position 4 through 20 to grab the IP address // Should never be beyond position 20. var ip string for i := 4; i < 20; i++ { if rb[i] == 0 { break } ip += string(rb[i]) } // Grab port from position 68 and 69 port := binary.LittleEndian.Uint16(rb[68:70]) // Take the data from above and send it back to Discord to finalize // the UDP connection handshake. data := voiceUDPOp{1, voiceUDPD{"udp", voiceUDPData{ip, port, "xsalsa20_poly1305"}}} v.wsMutex.Lock() err = v.wsConn.WriteJSON(data) v.wsMutex.Unlock() if err != nil { v.log(LogWarning, "udp write error, %#v, %s", data, err) return } // start udpKeepAlive go v.udpKeepAlive(v.udpConn, v.close, 5*time.Second) // TODO: find a way to check that it fired off okay return }
go
func (v *VoiceConnection) udpOpen() (err error) { v.Lock() defer v.Unlock() if v.wsConn == nil { return fmt.Errorf("nil voice websocket") } if v.udpConn != nil { return fmt.Errorf("udp connection already open") } if v.close == nil { return fmt.Errorf("nil close channel") } if v.endpoint == "" { return fmt.Errorf("empty endpoint") } host := strings.TrimSuffix(v.endpoint, ":80") + ":" + strconv.Itoa(v.op2.Port) addr, err := net.ResolveUDPAddr("udp", host) if err != nil { v.log(LogWarning, "error resolving udp host %s, %s", host, err) return } v.log(LogInformational, "connecting to udp addr %s", addr.String()) v.udpConn, err = net.DialUDP("udp", nil, addr) if err != nil { v.log(LogWarning, "error connecting to udp addr %s, %s", addr.String(), err) return } // Create a 70 byte array and put the SSRC code from the Op 2 VoiceConnection event // into it. Then send that over the UDP connection to Discord sb := make([]byte, 70) binary.BigEndian.PutUint32(sb, v.op2.SSRC) _, err = v.udpConn.Write(sb) if err != nil { v.log(LogWarning, "udp write error to %s, %s", addr.String(), err) return } // Create a 70 byte array and listen for the initial handshake response // from Discord. Once we get it parse the IP and PORT information out // of the response. This should be our public IP and PORT as Discord // saw us. rb := make([]byte, 70) rlen, _, err := v.udpConn.ReadFromUDP(rb) if err != nil { v.log(LogWarning, "udp read error, %s, %s", addr.String(), err) return } if rlen < 70 { v.log(LogWarning, "received udp packet too small") return fmt.Errorf("received udp packet too small") } // Loop over position 4 through 20 to grab the IP address // Should never be beyond position 20. var ip string for i := 4; i < 20; i++ { if rb[i] == 0 { break } ip += string(rb[i]) } // Grab port from position 68 and 69 port := binary.LittleEndian.Uint16(rb[68:70]) // Take the data from above and send it back to Discord to finalize // the UDP connection handshake. data := voiceUDPOp{1, voiceUDPD{"udp", voiceUDPData{ip, port, "xsalsa20_poly1305"}}} v.wsMutex.Lock() err = v.wsConn.WriteJSON(data) v.wsMutex.Unlock() if err != nil { v.log(LogWarning, "udp write error, %#v, %s", data, err) return } // start udpKeepAlive go v.udpKeepAlive(v.udpConn, v.close, 5*time.Second) // TODO: find a way to check that it fired off okay return }
[ "func", "(", "v", "*", "VoiceConnection", ")", "udpOpen", "(", ")", "(", "err", "error", ")", "{", "v", ".", "Lock", "(", ")", "\n", "defer", "v", ".", "Unlock", "(", ")", "\n", "if", "v", ".", "wsConn", "==", "nil", "{", "return", "fmt", ".", ...
// udpOpen opens a UDP connection to the voice server and completes the // initial required handshake. This connection is left open in the session // and can be used to send or receive audio. This should only be called // from voice.wsEvent OP2
[ "udpOpen", "opens", "a", "UDP", "connection", "to", "the", "voice", "server", "and", "completes", "the", "initial", "required", "handshake", ".", "This", "connection", "is", "left", "open", "in", "the", "session", "and", "can", "be", "used", "to", "send", ...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L524-L615
train
bwmarrin/discordgo
voice.go
udpKeepAlive
func (v *VoiceConnection) udpKeepAlive(udpConn *net.UDPConn, close <-chan struct{}, i time.Duration) { if udpConn == nil || close == nil { return } var err error var sequence uint64 packet := make([]byte, 8) ticker := time.NewTicker(i) defer ticker.Stop() for { binary.LittleEndian.PutUint64(packet, sequence) sequence++ _, err = udpConn.Write(packet) if err != nil { v.log(LogError, "write error, %s", err) return } select { case <-ticker.C: // continue loop and send keepalive case <-close: return } } }
go
func (v *VoiceConnection) udpKeepAlive(udpConn *net.UDPConn, close <-chan struct{}, i time.Duration) { if udpConn == nil || close == nil { return } var err error var sequence uint64 packet := make([]byte, 8) ticker := time.NewTicker(i) defer ticker.Stop() for { binary.LittleEndian.PutUint64(packet, sequence) sequence++ _, err = udpConn.Write(packet) if err != nil { v.log(LogError, "write error, %s", err) return } select { case <-ticker.C: // continue loop and send keepalive case <-close: return } } }
[ "func", "(", "v", "*", "VoiceConnection", ")", "udpKeepAlive", "(", "udpConn", "*", "net", ".", "UDPConn", ",", "close", "<-", "chan", "struct", "{", "}", ",", "i", "time", ".", "Duration", ")", "{", "if", "udpConn", "==", "nil", "||", "close", "==",...
// udpKeepAlive sends a udp packet to keep the udp connection open // This is still a bit of a "proof of concept"
[ "udpKeepAlive", "sends", "a", "udp", "packet", "to", "keep", "the", "udp", "connection", "open", "This", "is", "still", "a", "bit", "of", "a", "proof", "of", "concept" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L619-L650
train
bwmarrin/discordgo
voice.go
opusSender
func (v *VoiceConnection) opusSender(udpConn *net.UDPConn, close <-chan struct{}, opus <-chan []byte, rate, size int) { if udpConn == nil || close == nil { return } // VoiceConnection is now ready to receive audio packets // TODO: this needs reviewed as I think there must be a better way. v.Lock() v.Ready = true v.Unlock() defer func() { v.Lock() v.Ready = false v.Unlock() }() var sequence uint16 var timestamp uint32 var recvbuf []byte var ok bool udpHeader := make([]byte, 12) var nonce [24]byte // build the parts that don't change in the udpHeader udpHeader[0] = 0x80 udpHeader[1] = 0x78 binary.BigEndian.PutUint32(udpHeader[8:], v.op2.SSRC) // start a send loop that loops until buf chan is closed ticker := time.NewTicker(time.Millisecond * time.Duration(size/(rate/1000))) defer ticker.Stop() for { // Get data from chan. If chan is closed, return. select { case <-close: return case recvbuf, ok = <-opus: if !ok { return } // else, continue loop } v.RLock() speaking := v.speaking v.RUnlock() if !speaking { err := v.Speaking(true) if err != nil { v.log(LogError, "error sending speaking packet, %s", err) } } // Add sequence and timestamp to udpPacket binary.BigEndian.PutUint16(udpHeader[2:], sequence) binary.BigEndian.PutUint32(udpHeader[4:], timestamp) // encrypt the opus data copy(nonce[:], udpHeader) v.RLock() sendbuf := secretbox.Seal(udpHeader, recvbuf, &nonce, &v.op4.SecretKey) v.RUnlock() // block here until we're exactly at the right time :) // Then send rtp audio packet to Discord over UDP select { case <-close: return case <-ticker.C: // continue } _, err := udpConn.Write(sendbuf) if err != nil { v.log(LogError, "udp write error, %s", err) v.log(LogDebug, "voice struct: %#v\n", v) return } if (sequence) == 0xFFFF { sequence = 0 } else { sequence++ } if (timestamp + uint32(size)) >= 0xFFFFFFFF { timestamp = 0 } else { timestamp += uint32(size) } } }
go
func (v *VoiceConnection) opusSender(udpConn *net.UDPConn, close <-chan struct{}, opus <-chan []byte, rate, size int) { if udpConn == nil || close == nil { return } // VoiceConnection is now ready to receive audio packets // TODO: this needs reviewed as I think there must be a better way. v.Lock() v.Ready = true v.Unlock() defer func() { v.Lock() v.Ready = false v.Unlock() }() var sequence uint16 var timestamp uint32 var recvbuf []byte var ok bool udpHeader := make([]byte, 12) var nonce [24]byte // build the parts that don't change in the udpHeader udpHeader[0] = 0x80 udpHeader[1] = 0x78 binary.BigEndian.PutUint32(udpHeader[8:], v.op2.SSRC) // start a send loop that loops until buf chan is closed ticker := time.NewTicker(time.Millisecond * time.Duration(size/(rate/1000))) defer ticker.Stop() for { // Get data from chan. If chan is closed, return. select { case <-close: return case recvbuf, ok = <-opus: if !ok { return } // else, continue loop } v.RLock() speaking := v.speaking v.RUnlock() if !speaking { err := v.Speaking(true) if err != nil { v.log(LogError, "error sending speaking packet, %s", err) } } // Add sequence and timestamp to udpPacket binary.BigEndian.PutUint16(udpHeader[2:], sequence) binary.BigEndian.PutUint32(udpHeader[4:], timestamp) // encrypt the opus data copy(nonce[:], udpHeader) v.RLock() sendbuf := secretbox.Seal(udpHeader, recvbuf, &nonce, &v.op4.SecretKey) v.RUnlock() // block here until we're exactly at the right time :) // Then send rtp audio packet to Discord over UDP select { case <-close: return case <-ticker.C: // continue } _, err := udpConn.Write(sendbuf) if err != nil { v.log(LogError, "udp write error, %s", err) v.log(LogDebug, "voice struct: %#v\n", v) return } if (sequence) == 0xFFFF { sequence = 0 } else { sequence++ } if (timestamp + uint32(size)) >= 0xFFFFFFFF { timestamp = 0 } else { timestamp += uint32(size) } } }
[ "func", "(", "v", "*", "VoiceConnection", ")", "opusSender", "(", "udpConn", "*", "net", ".", "UDPConn", ",", "close", "<-", "chan", "struct", "{", "}", ",", "opus", "<-", "chan", "[", "]", "byte", ",", "rate", ",", "size", "int", ")", "{", "if", ...
// opusSender will listen on the given channel and send any // pre-encoded opus audio to Discord. Supposedly.
[ "opusSender", "will", "listen", "on", "the", "given", "channel", "and", "send", "any", "pre", "-", "encoded", "opus", "audio", "to", "Discord", ".", "Supposedly", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L654-L747
train
bwmarrin/discordgo
structs.go
MessageFormat
func (e *Emoji) MessageFormat() string { if e.ID != "" && e.Name != "" { if e.Animated { return "<a:" + e.APIName() + ">" } return "<:" + e.APIName() + ">" } return e.APIName() }
go
func (e *Emoji) MessageFormat() string { if e.ID != "" && e.Name != "" { if e.Animated { return "<a:" + e.APIName() + ">" } return "<:" + e.APIName() + ">" } return e.APIName() }
[ "func", "(", "e", "*", "Emoji", ")", "MessageFormat", "(", ")", "string", "{", "if", "e", ".", "ID", "!=", "\"\"", "&&", "e", ".", "Name", "!=", "\"\"", "{", "if", "e", ".", "Animated", "{", "return", "\"<a:\"", "+", "e", ".", "APIName", "(", "...
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
[ "MessageFormat", "returns", "a", "correctly", "formatted", "Emoji", "for", "use", "in", "Message", "content", "and", "embeds" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L289-L299
train
bwmarrin/discordgo
structs.go
APIName
func (e *Emoji) APIName() string { if e.ID != "" && e.Name != "" { return e.Name + ":" + e.ID } if e.Name != "" { return e.Name } return e.ID }
go
func (e *Emoji) APIName() string { if e.ID != "" && e.Name != "" { return e.Name + ":" + e.ID } if e.Name != "" { return e.Name } return e.ID }
[ "func", "(", "e", "*", "Emoji", ")", "APIName", "(", ")", "string", "{", "if", "e", ".", "ID", "!=", "\"\"", "&&", "e", ".", "Name", "!=", "\"\"", "{", "return", "e", ".", "Name", "+", "\":\"", "+", "e", ".", "ID", "\n", "}", "\n", "if", "e...
// APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
[ "APIName", "returns", "an", "correctly", "formatted", "API", "name", "for", "use", "in", "the", "MessageReactions", "endpoints", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L302-L310
train
bwmarrin/discordgo
structs.go
UnmarshalJSON
func (t *TimeStamps) UnmarshalJSON(b []byte) error { temp := struct { End float64 `json:"end,omitempty"` Start float64 `json:"start,omitempty"` }{} err := json.Unmarshal(b, &temp) if err != nil { return err } t.EndTimestamp = int64(temp.End) t.StartTimestamp = int64(temp.Start) return nil }
go
func (t *TimeStamps) UnmarshalJSON(b []byte) error { temp := struct { End float64 `json:"end,omitempty"` Start float64 `json:"start,omitempty"` }{} err := json.Unmarshal(b, &temp) if err != nil { return err } t.EndTimestamp = int64(temp.End) t.StartTimestamp = int64(temp.Start) return nil }
[ "func", "(", "t", "*", "TimeStamps", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "temp", ":=", "struct", "{", "End", "float64", "`json:\"end,omitempty\"`", "\n", "Start", "float64", "`json:\"start,omitempty\"`", "\n", "}", "{", "}", ...
// UnmarshalJSON unmarshals JSON into TimeStamps struct
[ "UnmarshalJSON", "unmarshals", "JSON", "into", "TimeStamps", "struct" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L575-L587
train
bwmarrin/discordgo
restapi.go
Request
func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) { return s.RequestWithBucketID(method, urlStr, data, strings.SplitN(urlStr, "?", 2)[0]) }
go
func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) { return s.RequestWithBucketID(method, urlStr, data, strings.SplitN(urlStr, "?", 2)[0]) }
[ "func", "(", "s", "*", "Session", ")", "Request", "(", "method", ",", "urlStr", "string", ",", "data", "interface", "{", "}", ")", "(", "response", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "s", ".", "RequestWithBucketID", "(", "meth...
// Request is the same as RequestWithBucketID but the bucket id is the same as the urlStr
[ "Request", "is", "the", "same", "as", "RequestWithBucketID", "but", "the", "bucket", "id", "is", "the", "same", "as", "the", "urlStr" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L45-L47
train
bwmarrin/discordgo
restapi.go
RequestWithLockedBucket
func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *Bucket, sequence int) (response []byte, err error) { if s.Debug { log.Printf("API REQUEST %8s :: %s\n", method, urlStr) log.Printf("API REQUEST PAYLOAD :: [%s]\n", string(b)) } req, err := http.NewRequest(method, urlStr, bytes.NewBuffer(b)) if err != nil { bucket.Release(nil) return } // Not used on initial login.. // TODO: Verify if a login, otherwise complain about no-token if s.Token != "" { req.Header.Set("authorization", s.Token) } req.Header.Set("Content-Type", contentType) // TODO: Make a configurable static variable. req.Header.Set("User-Agent", "DiscordBot (https://github.com/bwmarrin/discordgo, v"+VERSION+")") if s.Debug { for k, v := range req.Header { log.Printf("API REQUEST HEADER :: [%s] = %+v\n", k, v) } } resp, err := s.Client.Do(req) if err != nil { bucket.Release(nil) return } defer func() { err2 := resp.Body.Close() if err2 != nil { log.Println("error closing resp body") } }() err = bucket.Release(resp.Header) if err != nil { return } response, err = ioutil.ReadAll(resp.Body) if err != nil { return } if s.Debug { log.Printf("API RESPONSE STATUS :: %s\n", resp.Status) for k, v := range resp.Header { log.Printf("API RESPONSE HEADER :: [%s] = %+v\n", k, v) } log.Printf("API RESPONSE BODY :: [%s]\n\n\n", response) } switch resp.StatusCode { case http.StatusOK: case http.StatusCreated: case http.StatusNoContent: case http.StatusBadGateway: // Retry sending request if possible if sequence < s.MaxRestRetries { s.log(LogInformational, "%s Failed (%s), Retrying...", urlStr, resp.Status) response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence+1) } else { err = fmt.Errorf("Exceeded Max retries HTTP %s, %s", resp.Status, response) } case 429: // TOO MANY REQUESTS - Rate limiting rl := TooManyRequests{} err = json.Unmarshal(response, &rl) if err != nil { s.log(LogError, "rate limit unmarshal error, %s", err) return } s.log(LogInformational, "Rate Limiting %s, retry in %d", urlStr, rl.RetryAfter) s.handleEvent(rateLimitEventType, RateLimit{TooManyRequests: &rl, URL: urlStr}) time.Sleep(rl.RetryAfter * time.Millisecond) // we can make the above smarter // this method can cause longer delays than required response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence) case http.StatusUnauthorized: if strings.Index(s.Token, "Bot ") != 0 { s.log(LogInformational, ErrUnauthorized.Error()) err = ErrUnauthorized } fallthrough default: // Error condition err = newRestError(req, resp, response) } return }
go
func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *Bucket, sequence int) (response []byte, err error) { if s.Debug { log.Printf("API REQUEST %8s :: %s\n", method, urlStr) log.Printf("API REQUEST PAYLOAD :: [%s]\n", string(b)) } req, err := http.NewRequest(method, urlStr, bytes.NewBuffer(b)) if err != nil { bucket.Release(nil) return } // Not used on initial login.. // TODO: Verify if a login, otherwise complain about no-token if s.Token != "" { req.Header.Set("authorization", s.Token) } req.Header.Set("Content-Type", contentType) // TODO: Make a configurable static variable. req.Header.Set("User-Agent", "DiscordBot (https://github.com/bwmarrin/discordgo, v"+VERSION+")") if s.Debug { for k, v := range req.Header { log.Printf("API REQUEST HEADER :: [%s] = %+v\n", k, v) } } resp, err := s.Client.Do(req) if err != nil { bucket.Release(nil) return } defer func() { err2 := resp.Body.Close() if err2 != nil { log.Println("error closing resp body") } }() err = bucket.Release(resp.Header) if err != nil { return } response, err = ioutil.ReadAll(resp.Body) if err != nil { return } if s.Debug { log.Printf("API RESPONSE STATUS :: %s\n", resp.Status) for k, v := range resp.Header { log.Printf("API RESPONSE HEADER :: [%s] = %+v\n", k, v) } log.Printf("API RESPONSE BODY :: [%s]\n\n\n", response) } switch resp.StatusCode { case http.StatusOK: case http.StatusCreated: case http.StatusNoContent: case http.StatusBadGateway: // Retry sending request if possible if sequence < s.MaxRestRetries { s.log(LogInformational, "%s Failed (%s), Retrying...", urlStr, resp.Status) response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence+1) } else { err = fmt.Errorf("Exceeded Max retries HTTP %s, %s", resp.Status, response) } case 429: // TOO MANY REQUESTS - Rate limiting rl := TooManyRequests{} err = json.Unmarshal(response, &rl) if err != nil { s.log(LogError, "rate limit unmarshal error, %s", err) return } s.log(LogInformational, "Rate Limiting %s, retry in %d", urlStr, rl.RetryAfter) s.handleEvent(rateLimitEventType, RateLimit{TooManyRequests: &rl, URL: urlStr}) time.Sleep(rl.RetryAfter * time.Millisecond) // we can make the above smarter // this method can cause longer delays than required response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence) case http.StatusUnauthorized: if strings.Index(s.Token, "Bot ") != 0 { s.log(LogInformational, ErrUnauthorized.Error()) err = ErrUnauthorized } fallthrough default: // Error condition err = newRestError(req, resp, response) } return }
[ "func", "(", "s", "*", "Session", ")", "RequestWithLockedBucket", "(", "method", ",", "urlStr", ",", "contentType", "string", ",", "b", "[", "]", "byte", ",", "bucket", "*", "Bucket", ",", "sequence", "int", ")", "(", "response", "[", "]", "byte", ",",...
// RequestWithLockedBucket makes a request using a bucket that's already been locked
[ "RequestWithLockedBucket", "makes", "a", "request", "using", "a", "bucket", "that", "s", "already", "been", "locked" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L73-L171
train
bwmarrin/discordgo
restapi.go
Register
func (s *Session) Register(username string) (token string, err error) { data := struct { Username string `json:"username"` }{username} response, err := s.RequestWithBucketID("POST", EndpointRegister, data, EndpointRegister) if err != nil { return } temp := struct { Token string `json:"token"` }{} err = unmarshal(response, &temp) if err != nil { return } token = temp.Token return }
go
func (s *Session) Register(username string) (token string, err error) { data := struct { Username string `json:"username"` }{username} response, err := s.RequestWithBucketID("POST", EndpointRegister, data, EndpointRegister) if err != nil { return } temp := struct { Token string `json:"token"` }{} err = unmarshal(response, &temp) if err != nil { return } token = temp.Token return }
[ "func", "(", "s", "*", "Session", ")", "Register", "(", "username", "string", ")", "(", "token", "string", ",", "err", "error", ")", "{", "data", ":=", "struct", "{", "Username", "string", "`json:\"username\"`", "\n", "}", "{", "username", "}", "\n", "...
// Register sends a Register request to Discord, and returns the authentication token // Note that this account is temporary and should be verified for future use. // Another option is to save the authentication token external, but this isn't recommended.
[ "Register", "sends", "a", "Register", "request", "to", "Discord", "and", "returns", "the", "authentication", "token", "Note", "that", "this", "account", "is", "temporary", "and", "should", "be", "verified", "for", "future", "use", ".", "Another", "option", "is...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L223-L245
train
bwmarrin/discordgo
restapi.go
Logout
func (s *Session) Logout() (err error) { // _, err = s.Request("POST", LOGOUT, `{"token": "` + s.Token + `"}`) if s.Token == "" { return } data := struct { Token string `json:"token"` }{s.Token} _, err = s.RequestWithBucketID("POST", EndpointLogout, data, EndpointLogout) return }
go
func (s *Session) Logout() (err error) { // _, err = s.Request("POST", LOGOUT, `{"token": "` + s.Token + `"}`) if s.Token == "" { return } data := struct { Token string `json:"token"` }{s.Token} _, err = s.RequestWithBucketID("POST", EndpointLogout, data, EndpointLogout) return }
[ "func", "(", "s", "*", "Session", ")", "Logout", "(", ")", "(", "err", "error", ")", "{", "if", "s", ".", "Token", "==", "\"\"", "{", "return", "\n", "}", "\n", "data", ":=", "struct", "{", "Token", "string", "`json:\"token\"`", "\n", "}", "{", "...
// Logout sends a logout request to Discord. // This does not seem to actually invalidate the token. So you can still // make API calls even after a Logout. So, it seems almost pointless to // even use.
[ "Logout", "sends", "a", "logout", "request", "to", "Discord", ".", "This", "does", "not", "seem", "to", "actually", "invalidate", "the", "token", ".", "So", "you", "can", "still", "make", "API", "calls", "even", "after", "a", "Logout", ".", "So", "it", ...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L251-L265
train
bwmarrin/discordgo
restapi.go
UserUpdate
func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) { // NOTE: Avatar must be either the hash/id of existing Avatar or // data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG // to set a new avatar. // If left blank, avatar will be set to null/blank data := struct { Email string `json:"email,omitempty"` Password string `json:"password,omitempty"` Username string `json:"username,omitempty"` Avatar string `json:"avatar,omitempty"` NewPassword string `json:"new_password,omitempty"` }{email, password, username, avatar, newPassword} body, err := s.RequestWithBucketID("PATCH", EndpointUser("@me"), data, EndpointUsers) if err != nil { return } err = unmarshal(body, &st) return }
go
func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) { // NOTE: Avatar must be either the hash/id of existing Avatar or // data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG // to set a new avatar. // If left blank, avatar will be set to null/blank data := struct { Email string `json:"email,omitempty"` Password string `json:"password,omitempty"` Username string `json:"username,omitempty"` Avatar string `json:"avatar,omitempty"` NewPassword string `json:"new_password,omitempty"` }{email, password, username, avatar, newPassword} body, err := s.RequestWithBucketID("PATCH", EndpointUser("@me"), data, EndpointUsers) if err != nil { return } err = unmarshal(body, &st) return }
[ "func", "(", "s", "*", "Session", ")", "UserUpdate", "(", "email", ",", "password", ",", "username", ",", "avatar", ",", "newPassword", "string", ")", "(", "st", "*", "User", ",", "err", "error", ")", "{", "data", ":=", "struct", "{", "Email", "strin...
// UserUpdate updates a users settings.
[ "UserUpdate", "updates", "a", "users", "settings", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L308-L330
train
bwmarrin/discordgo
restapi.go
UserSettings
func (s *Session) UserSettings() (st *Settings, err error) { body, err := s.RequestWithBucketID("GET", EndpointUserSettings("@me"), nil, EndpointUserSettings("")) if err != nil { return } err = unmarshal(body, &st) return }
go
func (s *Session) UserSettings() (st *Settings, err error) { body, err := s.RequestWithBucketID("GET", EndpointUserSettings("@me"), nil, EndpointUserSettings("")) if err != nil { return } err = unmarshal(body, &st) return }
[ "func", "(", "s", "*", "Session", ")", "UserSettings", "(", ")", "(", "st", "*", "Settings", ",", "err", "error", ")", "{", "body", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointUserSettings", "(", "\"@me\"", ")", ","...
// UserSettings returns the settings for a given user
[ "UserSettings", "returns", "the", "settings", "for", "a", "given", "user" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L333-L342
train
bwmarrin/discordgo
restapi.go
UserConnections
func (s *Session) UserConnections() (conn []*UserConnection, err error) { response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me")) if err != nil { return nil, err } err = unmarshal(response, &conn) if err != nil { return } return }
go
func (s *Session) UserConnections() (conn []*UserConnection, err error) { response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me")) if err != nil { return nil, err } err = unmarshal(response, &conn) if err != nil { return } return }
[ "func", "(", "s", "*", "Session", ")", "UserConnections", "(", ")", "(", "conn", "[", "]", "*", "UserConnection", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointUserConnections", ...
// UserConnections returns the user's connections
[ "UserConnections", "returns", "the", "user", "s", "connections" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L366-L378
train
bwmarrin/discordgo
restapi.go
UserChannels
func (s *Session) UserChannels() (st []*Channel, err error) { body, err := s.RequestWithBucketID("GET", EndpointUserChannels("@me"), nil, EndpointUserChannels("")) if err != nil { return } err = unmarshal(body, &st) return }
go
func (s *Session) UserChannels() (st []*Channel, err error) { body, err := s.RequestWithBucketID("GET", EndpointUserChannels("@me"), nil, EndpointUserChannels("")) if err != nil { return } err = unmarshal(body, &st) return }
[ "func", "(", "s", "*", "Session", ")", "UserChannels", "(", ")", "(", "st", "[", "]", "*", "Channel", ",", "err", "error", ")", "{", "body", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointUserChannels", "(", "\"@me\"",...
// UserChannels returns an array of Channel structures for all private // channels.
[ "UserChannels", "returns", "an", "array", "of", "Channel", "structures", "for", "all", "private", "channels", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L382-L391
train
bwmarrin/discordgo
restapi.go
ChannelMessageEditComplex
func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error) { if m.Embed != nil && m.Embed.Type == "" { m.Embed.Type = "rich" } response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, "")) if err != nil { return } err = unmarshal(response, &st) return }
go
func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error) { if m.Embed != nil && m.Embed.Type == "" { m.Embed.Type = "rich" } response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, "")) if err != nil { return } err = unmarshal(response, &st) return }
[ "func", "(", "s", "*", "Session", ")", "ChannelMessageEditComplex", "(", "m", "*", "MessageEdit", ")", "(", "st", "*", "Message", ",", "err", "error", ")", "{", "if", "m", ".", "Embed", "!=", "nil", "&&", "m", ".", "Embed", ".", "Type", "==", "\"\"...
// ChannelMessageEditComplex edits an existing message, replacing it entirely with // the given MessageEdit struct
[ "ChannelMessageEditComplex", "edits", "an", "existing", "message", "replacing", "it", "entirely", "with", "the", "given", "MessageEdit", "struct" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1615-L1627
train
bwmarrin/discordgo
restapi.go
ChannelMessageDelete
func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error) { _, err = s.RequestWithBucketID("DELETE", EndpointChannelMessage(channelID, messageID), nil, EndpointChannelMessage(channelID, "")) return }
go
func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error) { _, err = s.RequestWithBucketID("DELETE", EndpointChannelMessage(channelID, messageID), nil, EndpointChannelMessage(channelID, "")) return }
[ "func", "(", "s", "*", "Session", ")", "ChannelMessageDelete", "(", "channelID", ",", "messageID", "string", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "s", ".", "RequestWithBucketID", "(", "\"DELETE\"", ",", "EndpointChannelMessage", "(", "...
// ChannelMessageDelete deletes a message from the Channel.
[ "ChannelMessageDelete", "deletes", "a", "message", "from", "the", "Channel", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1638-L1642
train
bwmarrin/discordgo
restapi.go
VoiceICE
func (s *Session) VoiceICE() (st *VoiceICE, err error) { body, err := s.RequestWithBucketID("GET", EndpointVoiceIce, nil, EndpointVoiceIce) if err != nil { return } err = unmarshal(body, &st) return }
go
func (s *Session) VoiceICE() (st *VoiceICE, err error) { body, err := s.RequestWithBucketID("GET", EndpointVoiceIce, nil, EndpointVoiceIce) if err != nil { return } err = unmarshal(body, &st) return }
[ "func", "(", "s", "*", "Session", ")", "VoiceICE", "(", ")", "(", "st", "*", "VoiceICE", ",", "err", "error", ")", "{", "body", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointVoiceIce", ",", "nil", ",", "EndpointVoiceI...
// VoiceICE returns the voice server ICE information
[ "VoiceICE", "returns", "the", "voice", "server", "ICE", "information" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1854-L1863
train
bwmarrin/discordgo
restapi.go
GatewayBot
func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) { response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot) if err != nil { return } err = unmarshal(response, &st) if err != nil { return } // Ensure the gateway always has a trailing slash. // MacOS will fail to connect if we add query params without a trailing slash on the base domain. if !strings.HasSuffix(st.URL, "/") { st.URL += "/" } return }
go
func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) { response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot) if err != nil { return } err = unmarshal(response, &st) if err != nil { return } // Ensure the gateway always has a trailing slash. // MacOS will fail to connect if we add query params without a trailing slash on the base domain. if !strings.HasSuffix(st.URL, "/") { st.URL += "/" } return }
[ "func", "(", "s", "*", "Session", ")", "GatewayBot", "(", ")", "(", "st", "*", "GatewayBotResponse", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointGatewayBot", ",", "nil", ",",...
// GatewayBot returns the websocket Gateway address and the recommended number of shards
[ "GatewayBot", "returns", "the", "websocket", "Gateway", "address", "and", "the", "recommended", "number", "of", "shards" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1898-L1917
train
bwmarrin/discordgo
restapi.go
RelationshipsMutualGet
func (s *Session) RelationshipsMutualGet(userID string) (mf []*User, err error) { body, err := s.RequestWithBucketID("GET", EndpointRelationshipsMutual(userID), nil, EndpointRelationshipsMutual(userID)) if err != nil { return } err = unmarshal(body, &mf) return }
go
func (s *Session) RelationshipsMutualGet(userID string) (mf []*User, err error) { body, err := s.RequestWithBucketID("GET", EndpointRelationshipsMutual(userID), nil, EndpointRelationshipsMutual(userID)) if err != nil { return } err = unmarshal(body, &mf) return }
[ "func", "(", "s", "*", "Session", ")", "RelationshipsMutualGet", "(", "userID", "string", ")", "(", "mf", "[", "]", "*", "User", ",", "err", "error", ")", "{", "body", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointRel...
// RelationshipsMutualGet returns an array of all the users both @me and the given user is friends with. // userID: ID of the user.
[ "RelationshipsMutualGet", "returns", "an", "array", "of", "all", "the", "users", "both" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L2212-L2220
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh channelCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelCreate); ok { eh(s, t) } }
go
func (eh channelCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelCreate); ok { eh(s, t) } }
[ "func", "(", "eh", "channelCreateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "ChannelCreate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for ChannelCreate events.
[ "Handle", "is", "the", "handler", "for", "ChannelCreate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L70-L74
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh channelDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelDelete); ok { eh(s, t) } }
go
func (eh channelDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelDelete); ok { eh(s, t) } }
[ "func", "(", "eh", "channelDeleteEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "ChannelDelete", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for ChannelDelete events.
[ "Handle", "is", "the", "handler", "for", "ChannelDelete", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L90-L94
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh channelPinsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelPinsUpdate); ok { eh(s, t) } }
go
func (eh channelPinsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelPinsUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "channelPinsUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "ChannelPinsUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for ChannelPinsUpdate events.
[ "Handle", "is", "the", "handler", "for", "ChannelPinsUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L110-L114
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh channelUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelUpdate); ok { eh(s, t) } }
go
func (eh channelUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*ChannelUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "channelUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "ChannelUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for ChannelUpdate events.
[ "Handle", "is", "the", "handler", "for", "ChannelUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L130-L134
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh connectEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Connect); ok { eh(s, t) } }
go
func (eh connectEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Connect); ok { eh(s, t) } }
[ "func", "(", "eh", "connectEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "Connect", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", "\n",...
// Handle is the handler for Connect events.
[ "Handle", "is", "the", "handler", "for", "Connect", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L145-L149
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh disconnectEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Disconnect); ok { eh(s, t) } }
go
func (eh disconnectEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Disconnect); ok { eh(s, t) } }
[ "func", "(", "eh", "disconnectEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "Disconnect", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", ...
// Handle is the handler for Disconnect events.
[ "Handle", "is", "the", "handler", "for", "Disconnect", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L160-L164
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh eventEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Event); ok { eh(s, t) } }
go
func (eh eventEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Event); ok { eh(s, t) } }
[ "func", "(", "eh", "eventEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "Event", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", "\n", "...
// Handle is the handler for Event events.
[ "Handle", "is", "the", "handler", "for", "Event", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L175-L179
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildBanAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildBanAdd); ok { eh(s, t) } }
go
func (eh guildBanAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildBanAdd); ok { eh(s, t) } }
[ "func", "(", "eh", "guildBanAddEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildBanAdd", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")",...
// Handle is the handler for GuildBanAdd events.
[ "Handle", "is", "the", "handler", "for", "GuildBanAdd", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L195-L199
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildBanRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildBanRemove); ok { eh(s, t) } }
go
func (eh guildBanRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildBanRemove); ok { eh(s, t) } }
[ "func", "(", "eh", "guildBanRemoveEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildBanRemove", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for GuildBanRemove events.
[ "Handle", "is", "the", "handler", "for", "GuildBanRemove", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L215-L219
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildCreate); ok { eh(s, t) } }
go
func (eh guildCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildCreate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildCreateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildCreate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")",...
// Handle is the handler for GuildCreate events.
[ "Handle", "is", "the", "handler", "for", "GuildCreate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L235-L239
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildDelete); ok { eh(s, t) } }
go
func (eh guildDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildDelete); ok { eh(s, t) } }
[ "func", "(", "eh", "guildDeleteEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildDelete", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")",...
// Handle is the handler for GuildDelete events.
[ "Handle", "is", "the", "handler", "for", "GuildDelete", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L255-L259
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildEmojisUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildEmojisUpdate); ok { eh(s, t) } }
go
func (eh guildEmojisUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildEmojisUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildEmojisUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildEmojisUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for GuildEmojisUpdate events.
[ "Handle", "is", "the", "handler", "for", "GuildEmojisUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L275-L279
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildIntegrationsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildIntegrationsUpdate); ok { eh(s, t) } }
go
func (eh guildIntegrationsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildIntegrationsUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildIntegrationsUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildIntegrationsUpdate", ")", ";", "ok", "{", "eh", "(", "...
// Handle is the handler for GuildIntegrationsUpdate events.
[ "Handle", "is", "the", "handler", "for", "GuildIntegrationsUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L295-L299
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildMemberAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberAdd); ok { eh(s, t) } }
go
func (eh guildMemberAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberAdd); ok { eh(s, t) } }
[ "func", "(", "eh", "guildMemberAddEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildMemberAdd", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for GuildMemberAdd events.
[ "Handle", "is", "the", "handler", "for", "GuildMemberAdd", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L315-L319
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildMemberRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberRemove); ok { eh(s, t) } }
go
func (eh guildMemberRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberRemove); ok { eh(s, t) } }
[ "func", "(", "eh", "guildMemberRemoveEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildMemberRemove", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for GuildMemberRemove events.
[ "Handle", "is", "the", "handler", "for", "GuildMemberRemove", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L335-L339
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildMemberUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberUpdate); ok { eh(s, t) } }
go
func (eh guildMemberUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMemberUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildMemberUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildMemberUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for GuildMemberUpdate events.
[ "Handle", "is", "the", "handler", "for", "GuildMemberUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L355-L359
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildMembersChunkEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMembersChunk); ok { eh(s, t) } }
go
func (eh guildMembersChunkEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildMembersChunk); ok { eh(s, t) } }
[ "func", "(", "eh", "guildMembersChunkEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildMembersChunk", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for GuildMembersChunk events.
[ "Handle", "is", "the", "handler", "for", "GuildMembersChunk", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L375-L379
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildRoleCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleCreate); ok { eh(s, t) } }
go
func (eh guildRoleCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleCreate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildRoleCreateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildRoleCreate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t"...
// Handle is the handler for GuildRoleCreate events.
[ "Handle", "is", "the", "handler", "for", "GuildRoleCreate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L395-L399
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildRoleDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleDelete); ok { eh(s, t) } }
go
func (eh guildRoleDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleDelete); ok { eh(s, t) } }
[ "func", "(", "eh", "guildRoleDeleteEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildRoleDelete", ")", ";", "ok", "{", "eh", "(", "s", ",", "t"...
// Handle is the handler for GuildRoleDelete events.
[ "Handle", "is", "the", "handler", "for", "GuildRoleDelete", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L415-L419
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildRoleUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleUpdate); ok { eh(s, t) } }
go
func (eh guildRoleUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildRoleUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildRoleUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildRoleUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t"...
// Handle is the handler for GuildRoleUpdate events.
[ "Handle", "is", "the", "handler", "for", "GuildRoleUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L435-L439
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh guildUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildUpdate); ok { eh(s, t) } }
go
func (eh guildUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*GuildUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "guildUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "GuildUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")",...
// Handle is the handler for GuildUpdate events.
[ "Handle", "is", "the", "handler", "for", "GuildUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L455-L459
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageAckEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageAck); ok { eh(s, t) } }
go
func (eh messageAckEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageAck); ok { eh(s, t) } }
[ "func", "(", "eh", "messageAckEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageAck", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", ...
// Handle is the handler for MessageAck events.
[ "Handle", "is", "the", "handler", "for", "MessageAck", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L475-L479
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageCreate); ok { eh(s, t) } }
go
func (eh messageCreateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageCreate); ok { eh(s, t) } }
[ "func", "(", "eh", "messageCreateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageCreate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for MessageCreate events.
[ "Handle", "is", "the", "handler", "for", "MessageCreate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L495-L499
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageDelete); ok { eh(s, t) } }
go
func (eh messageDeleteEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageDelete); ok { eh(s, t) } }
[ "func", "(", "eh", "messageDeleteEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageDelete", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for MessageDelete events.
[ "Handle", "is", "the", "handler", "for", "MessageDelete", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L515-L519
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageDeleteBulkEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageDeleteBulk); ok { eh(s, t) } }
go
func (eh messageDeleteBulkEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageDeleteBulk); ok { eh(s, t) } }
[ "func", "(", "eh", "messageDeleteBulkEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageDeleteBulk", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for MessageDeleteBulk events.
[ "Handle", "is", "the", "handler", "for", "MessageDeleteBulk", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L535-L539
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageReactionAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionAdd); ok { eh(s, t) } }
go
func (eh messageReactionAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionAdd); ok { eh(s, t) } }
[ "func", "(", "eh", "messageReactionAddEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageReactionAdd", ")", ";", "ok", "{", "eh", "(", "s", ",",...
// Handle is the handler for MessageReactionAdd events.
[ "Handle", "is", "the", "handler", "for", "MessageReactionAdd", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L555-L559
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageReactionRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionRemove); ok { eh(s, t) } }
go
func (eh messageReactionRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionRemove); ok { eh(s, t) } }
[ "func", "(", "eh", "messageReactionRemoveEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageReactionRemove", ")", ";", "ok", "{", "eh", "(", "s", ...
// Handle is the handler for MessageReactionRemove events.
[ "Handle", "is", "the", "handler", "for", "MessageReactionRemove", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L575-L579
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageReactionRemoveAllEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionRemoveAll); ok { eh(s, t) } }
go
func (eh messageReactionRemoveAllEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageReactionRemoveAll); ok { eh(s, t) } }
[ "func", "(", "eh", "messageReactionRemoveAllEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageReactionRemoveAll", ")", ";", "ok", "{", "eh", "(", ...
// Handle is the handler for MessageReactionRemoveAll events.
[ "Handle", "is", "the", "handler", "for", "MessageReactionRemoveAll", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L595-L599
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh messageUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageUpdate); ok { eh(s, t) } }
go
func (eh messageUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*MessageUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "messageUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "MessageUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for MessageUpdate events.
[ "Handle", "is", "the", "handler", "for", "MessageUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L615-L619
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh presenceUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*PresenceUpdate); ok { eh(s, t) } }
go
func (eh presenceUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*PresenceUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "presenceUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "PresenceUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for PresenceUpdate events.
[ "Handle", "is", "the", "handler", "for", "PresenceUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L635-L639
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh presencesReplaceEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*PresencesReplace); ok { eh(s, t) } }
go
func (eh presencesReplaceEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*PresencesReplace); ok { eh(s, t) } }
[ "func", "(", "eh", "presencesReplaceEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "PresencesReplace", ")", ";", "ok", "{", "eh", "(", "s", ",", "...
// Handle is the handler for PresencesReplace events.
[ "Handle", "is", "the", "handler", "for", "PresencesReplace", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L655-L659
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh rateLimitEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RateLimit); ok { eh(s, t) } }
go
func (eh rateLimitEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RateLimit); ok { eh(s, t) } }
[ "func", "(", "eh", "rateLimitEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "RateLimit", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", "...
// Handle is the handler for RateLimit events.
[ "Handle", "is", "the", "handler", "for", "RateLimit", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L670-L674
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh readyEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Ready); ok { eh(s, t) } }
go
func (eh readyEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Ready); ok { eh(s, t) } }
[ "func", "(", "eh", "readyEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "Ready", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", "\n", "...
// Handle is the handler for Ready events.
[ "Handle", "is", "the", "handler", "for", "Ready", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L690-L694
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh relationshipAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RelationshipAdd); ok { eh(s, t) } }
go
func (eh relationshipAddEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RelationshipAdd); ok { eh(s, t) } }
[ "func", "(", "eh", "relationshipAddEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "RelationshipAdd", ")", ";", "ok", "{", "eh", "(", "s", ",", "t"...
// Handle is the handler for RelationshipAdd events.
[ "Handle", "is", "the", "handler", "for", "RelationshipAdd", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L710-L714
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh relationshipRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RelationshipRemove); ok { eh(s, t) } }
go
func (eh relationshipRemoveEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*RelationshipRemove); ok { eh(s, t) } }
[ "func", "(", "eh", "relationshipRemoveEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "RelationshipRemove", ")", ";", "ok", "{", "eh", "(", "s", ",",...
// Handle is the handler for RelationshipRemove events.
[ "Handle", "is", "the", "handler", "for", "RelationshipRemove", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L730-L734
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh resumedEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Resumed); ok { eh(s, t) } }
go
func (eh resumedEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*Resumed); ok { eh(s, t) } }
[ "func", "(", "eh", "resumedEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "Resumed", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", "\n",...
// Handle is the handler for Resumed events.
[ "Handle", "is", "the", "handler", "for", "Resumed", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L750-L754
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh typingStartEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*TypingStart); ok { eh(s, t) } }
go
func (eh typingStartEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*TypingStart); ok { eh(s, t) } }
[ "func", "(", "eh", "typingStartEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "TypingStart", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")",...
// Handle is the handler for TypingStart events.
[ "Handle", "is", "the", "handler", "for", "TypingStart", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L770-L774
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh userGuildSettingsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserGuildSettingsUpdate); ok { eh(s, t) } }
go
func (eh userGuildSettingsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserGuildSettingsUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "userGuildSettingsUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "UserGuildSettingsUpdate", ")", ";", "ok", "{", "eh", "(", "...
// Handle is the handler for UserGuildSettingsUpdate events.
[ "Handle", "is", "the", "handler", "for", "UserGuildSettingsUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L790-L794
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh userNoteUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserNoteUpdate); ok { eh(s, t) } }
go
func (eh userNoteUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserNoteUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "userNoteUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "UserNoteUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for UserNoteUpdate events.
[ "Handle", "is", "the", "handler", "for", "UserNoteUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L810-L814
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh userSettingsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserSettingsUpdate); ok { eh(s, t) } }
go
func (eh userSettingsUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserSettingsUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "userSettingsUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "UserSettingsUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",",...
// Handle is the handler for UserSettingsUpdate events.
[ "Handle", "is", "the", "handler", "for", "UserSettingsUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L830-L834
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh userUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserUpdate); ok { eh(s, t) } }
go
func (eh userUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*UserUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "userUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "UserUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ")", ...
// Handle is the handler for UserUpdate events.
[ "Handle", "is", "the", "handler", "for", "UserUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L850-L854
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh voiceServerUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*VoiceServerUpdate); ok { eh(s, t) } }
go
func (eh voiceServerUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*VoiceServerUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "voiceServerUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "VoiceServerUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", ...
// Handle is the handler for VoiceServerUpdate events.
[ "Handle", "is", "the", "handler", "for", "VoiceServerUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L870-L874
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh voiceStateUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*VoiceStateUpdate); ok { eh(s, t) } }
go
func (eh voiceStateUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*VoiceStateUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "voiceStateUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "VoiceStateUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "...
// Handle is the handler for VoiceStateUpdate events.
[ "Handle", "is", "the", "handler", "for", "VoiceStateUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L890-L894
train
bwmarrin/discordgo
eventhandlers.go
Handle
func (eh webhooksUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*WebhooksUpdate); ok { eh(s, t) } }
go
func (eh webhooksUpdateEventHandler) Handle(s *Session, i interface{}) { if t, ok := i.(*WebhooksUpdate); ok { eh(s, t) } }
[ "func", "(", "eh", "webhooksUpdateEventHandler", ")", "Handle", "(", "s", "*", "Session", ",", "i", "interface", "{", "}", ")", "{", "if", "t", ",", "ok", ":=", "i", ".", "(", "*", "WebhooksUpdate", ")", ";", "ok", "{", "eh", "(", "s", ",", "t", ...
// Handle is the handler for WebhooksUpdate events.
[ "Handle", "is", "the", "handler", "for", "WebhooksUpdate", "events", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L910-L914
train
bwmarrin/discordgo
event.go
AddHandlerOnce
func (s *Session) AddHandlerOnce(handler interface{}) func() { eh := handlerForInterface(handler) if eh == nil { s.log(LogError, "Invalid handler type, handler will never be called") return func() {} } return s.addEventHandlerOnce(eh) }
go
func (s *Session) AddHandlerOnce(handler interface{}) func() { eh := handlerForInterface(handler) if eh == nil { s.log(LogError, "Invalid handler type, handler will never be called") return func() {} } return s.addEventHandlerOnce(eh) }
[ "func", "(", "s", "*", "Session", ")", "AddHandlerOnce", "(", "handler", "interface", "{", "}", ")", "func", "(", ")", "{", "eh", ":=", "handlerForInterface", "(", "handler", ")", "\n", "if", "eh", "==", "nil", "{", "s", ".", "log", "(", "LogError", ...
// AddHandlerOnce allows you to add an event handler that will be fired the next time // the Discord WSAPI event that matches the function fires. // See AddHandler for more details.
[ "AddHandlerOnce", "allows", "you", "to", "add", "an", "event", "handler", "that", "will", "be", "fired", "the", "next", "time", "the", "Discord", "WSAPI", "event", "that", "matches", "the", "function", "fires", ".", "See", "AddHandler", "for", "more", "detai...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/event.go#L134-L143
train
bwmarrin/discordgo
event.go
removeEventHandlerInstance
func (s *Session) removeEventHandlerInstance(t string, ehi *eventHandlerInstance) { s.handlersMu.Lock() defer s.handlersMu.Unlock() handlers := s.handlers[t] for i := range handlers { if handlers[i] == ehi { s.handlers[t] = append(handlers[:i], handlers[i+1:]...) } } onceHandlers := s.onceHandlers[t] for i := range onceHandlers { if onceHandlers[i] == ehi { s.onceHandlers[t] = append(onceHandlers[:i], handlers[i+1:]...) } } }
go
func (s *Session) removeEventHandlerInstance(t string, ehi *eventHandlerInstance) { s.handlersMu.Lock() defer s.handlersMu.Unlock() handlers := s.handlers[t] for i := range handlers { if handlers[i] == ehi { s.handlers[t] = append(handlers[:i], handlers[i+1:]...) } } onceHandlers := s.onceHandlers[t] for i := range onceHandlers { if onceHandlers[i] == ehi { s.onceHandlers[t] = append(onceHandlers[:i], handlers[i+1:]...) } } }
[ "func", "(", "s", "*", "Session", ")", "removeEventHandlerInstance", "(", "t", "string", ",", "ehi", "*", "eventHandlerInstance", ")", "{", "s", ".", "handlersMu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "handlersMu", ".", "Unlock", "(", ")", "...
// removeEventHandler instance removes an event handler instance.
[ "removeEventHandler", "instance", "removes", "an", "event", "handler", "instance", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/event.go#L146-L163
train
bwmarrin/discordgo
event.go
handle
func (s *Session) handle(t string, i interface{}) { for _, eh := range s.handlers[t] { if s.SyncEvents { eh.eventHandler.Handle(s, i) } else { go eh.eventHandler.Handle(s, i) } } if len(s.onceHandlers[t]) > 0 { for _, eh := range s.onceHandlers[t] { if s.SyncEvents { eh.eventHandler.Handle(s, i) } else { go eh.eventHandler.Handle(s, i) } } s.onceHandlers[t] = nil } }
go
func (s *Session) handle(t string, i interface{}) { for _, eh := range s.handlers[t] { if s.SyncEvents { eh.eventHandler.Handle(s, i) } else { go eh.eventHandler.Handle(s, i) } } if len(s.onceHandlers[t]) > 0 { for _, eh := range s.onceHandlers[t] { if s.SyncEvents { eh.eventHandler.Handle(s, i) } else { go eh.eventHandler.Handle(s, i) } } s.onceHandlers[t] = nil } }
[ "func", "(", "s", "*", "Session", ")", "handle", "(", "t", "string", ",", "i", "interface", "{", "}", ")", "{", "for", "_", ",", "eh", ":=", "range", "s", ".", "handlers", "[", "t", "]", "{", "if", "s", ".", "SyncEvents", "{", "eh", ".", "eve...
// Handles calling permanent and once handlers for an event type.
[ "Handles", "calling", "permanent", "and", "once", "handlers", "for", "an", "event", "type", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/event.go#L166-L185
train
bwmarrin/discordgo
event.go
setGuildIds
func setGuildIds(g *Guild) { for _, c := range g.Channels { c.GuildID = g.ID } for _, m := range g.Members { m.GuildID = g.ID } for _, vs := range g.VoiceStates { vs.GuildID = g.ID } }
go
func setGuildIds(g *Guild) { for _, c := range g.Channels { c.GuildID = g.ID } for _, m := range g.Members { m.GuildID = g.ID } for _, vs := range g.VoiceStates { vs.GuildID = g.ID } }
[ "func", "setGuildIds", "(", "g", "*", "Guild", ")", "{", "for", "_", ",", "c", ":=", "range", "g", ".", "Channels", "{", "c", ".", "GuildID", "=", "g", ".", "ID", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "g", ".", "Members", "{",...
// setGuildIds will set the GuildID on all the members of a guild. // This is done as event data does not have it set.
[ "setGuildIds", "will", "set", "the", "GuildID", "on", "all", "the", "members", "of", "a", "guild", ".", "This", "is", "done", "as", "event", "data", "does", "not", "have", "it", "set", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/event.go#L205-L217
train
bwmarrin/discordgo
event.go
onInterface
func (s *Session) onInterface(i interface{}) { switch t := i.(type) { case *Ready: for _, g := range t.Guilds { setGuildIds(g) } s.onReady(t) case *GuildCreate: setGuildIds(t.Guild) case *GuildUpdate: setGuildIds(t.Guild) case *VoiceServerUpdate: go s.onVoiceServerUpdate(t) case *VoiceStateUpdate: go s.onVoiceStateUpdate(t) } err := s.State.OnInterface(s, i) if err != nil { s.log(LogDebug, "error dispatching internal event, %s", err) } }
go
func (s *Session) onInterface(i interface{}) { switch t := i.(type) { case *Ready: for _, g := range t.Guilds { setGuildIds(g) } s.onReady(t) case *GuildCreate: setGuildIds(t.Guild) case *GuildUpdate: setGuildIds(t.Guild) case *VoiceServerUpdate: go s.onVoiceServerUpdate(t) case *VoiceStateUpdate: go s.onVoiceStateUpdate(t) } err := s.State.OnInterface(s, i) if err != nil { s.log(LogDebug, "error dispatching internal event, %s", err) } }
[ "func", "(", "s", "*", "Session", ")", "onInterface", "(", "i", "interface", "{", "}", ")", "{", "switch", "t", ":=", "i", ".", "(", "type", ")", "{", "case", "*", "Ready", ":", "for", "_", ",", "g", ":=", "range", "t", ".", "Guilds", "{", "s...
// onInterface handles all internal events and routes them to the appropriate internal handler.
[ "onInterface", "handles", "all", "internal", "events", "and", "routes", "them", "to", "the", "appropriate", "internal", "handler", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/event.go#L220-L240
train
bwmarrin/discordgo
types.go
Parse
func (t Timestamp) Parse() (time.Time, error) { return time.Parse(time.RFC3339, string(t)) }
go
func (t Timestamp) Parse() (time.Time, error) { return time.Parse(time.RFC3339, string(t)) }
[ "func", "(", "t", "Timestamp", ")", "Parse", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC3339", ",", "string", "(", "t", ")", ")", "\n", "}" ]
// Parse parses a timestamp string into a time.Time object. // The only time this can fail is if Discord changes their timestamp format.
[ "Parse", "parses", "a", "timestamp", "string", "into", "a", "time", ".", "Time", "object", ".", "The", "only", "time", "this", "can", "fail", "is", "if", "Discord", "changes", "their", "timestamp", "format", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/types.go#L23-L25
train
bwmarrin/discordgo
wsapi.go
listen
func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) { s.log(LogInformational, "called") for { messageType, message, err := wsConn.ReadMessage() if err != nil { // Detect if we have been closed manually. If a Close() has already // happened, the websocket we are listening on will be different to // the current session. s.RLock() sameConnection := s.wsConn == wsConn s.RUnlock() if sameConnection { s.log(LogWarning, "error reading from gateway %s websocket, %s", s.gateway, err) // There has been an error reading, close the websocket so that // OnDisconnect event is emitted. err := s.Close() if err != nil { s.log(LogWarning, "error closing session connection, %s", err) } s.log(LogInformational, "calling reconnect() now") s.reconnect() } return } select { case <-listening: return default: s.onEvent(messageType, message) } } }
go
func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) { s.log(LogInformational, "called") for { messageType, message, err := wsConn.ReadMessage() if err != nil { // Detect if we have been closed manually. If a Close() has already // happened, the websocket we are listening on will be different to // the current session. s.RLock() sameConnection := s.wsConn == wsConn s.RUnlock() if sameConnection { s.log(LogWarning, "error reading from gateway %s websocket, %s", s.gateway, err) // There has been an error reading, close the websocket so that // OnDisconnect event is emitted. err := s.Close() if err != nil { s.log(LogWarning, "error closing session connection, %s", err) } s.log(LogInformational, "calling reconnect() now") s.reconnect() } return } select { case <-listening: return default: s.onEvent(messageType, message) } } }
[ "func", "(", "s", "*", "Session", ")", "listen", "(", "wsConn", "*", "websocket", ".", "Conn", ",", "listening", "<-", "chan", "interface", "{", "}", ")", "{", "s", ".", "log", "(", "LogInformational", ",", "\"called\"", ")", "\n", "for", "{", "messa...
// listen polls the websocket connection for events, it will stop when the // listening channel is closed, or an error occurs.
[ "listen", "polls", "the", "websocket", "connection", "for", "events", "it", "will", "stop", "when", "the", "listening", "channel", "is", "closed", "or", "an", "error", "occurs", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L211-L255
train
bwmarrin/discordgo
wsapi.go
HeartbeatLatency
func (s *Session) HeartbeatLatency() time.Duration { return s.LastHeartbeatAck.Sub(s.LastHeartbeatSent) }
go
func (s *Session) HeartbeatLatency() time.Duration { return s.LastHeartbeatAck.Sub(s.LastHeartbeatSent) }
[ "func", "(", "s", "*", "Session", ")", "HeartbeatLatency", "(", ")", "time", ".", "Duration", "{", "return", "s", ".", "LastHeartbeatAck", ".", "Sub", "(", "s", ".", "LastHeartbeatSent", ")", "\n", "}" ]
// HeartbeatLatency returns the latency between heartbeat acknowledgement and heartbeat send.
[ "HeartbeatLatency", "returns", "the", "latency", "between", "heartbeat", "acknowledgement", "and", "heartbeat", "send", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L271-L275
train
bwmarrin/discordgo
wsapi.go
heartbeat
func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}, heartbeatIntervalMsec time.Duration) { s.log(LogInformational, "called") if listening == nil || wsConn == nil { return } var err error ticker := time.NewTicker(heartbeatIntervalMsec * time.Millisecond) defer ticker.Stop() for { s.RLock() last := s.LastHeartbeatAck s.RUnlock() sequence := atomic.LoadInt64(s.sequence) s.log(LogDebug, "sending gateway websocket heartbeat seq %d", sequence) s.wsMutex.Lock() s.LastHeartbeatSent = time.Now().UTC() err = wsConn.WriteJSON(heartbeatOp{1, sequence}) s.wsMutex.Unlock() if err != nil || time.Now().UTC().Sub(last) > (heartbeatIntervalMsec*FailedHeartbeatAcks) { if err != nil { s.log(LogError, "error sending heartbeat to gateway %s, %s", s.gateway, err) } else { s.log(LogError, "haven't gotten a heartbeat ACK in %v, triggering a reconnection", time.Now().UTC().Sub(last)) } s.Close() s.reconnect() return } s.Lock() s.DataReady = true s.Unlock() select { case <-ticker.C: // continue loop and send heartbeat case <-listening: return } } }
go
func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}, heartbeatIntervalMsec time.Duration) { s.log(LogInformational, "called") if listening == nil || wsConn == nil { return } var err error ticker := time.NewTicker(heartbeatIntervalMsec * time.Millisecond) defer ticker.Stop() for { s.RLock() last := s.LastHeartbeatAck s.RUnlock() sequence := atomic.LoadInt64(s.sequence) s.log(LogDebug, "sending gateway websocket heartbeat seq %d", sequence) s.wsMutex.Lock() s.LastHeartbeatSent = time.Now().UTC() err = wsConn.WriteJSON(heartbeatOp{1, sequence}) s.wsMutex.Unlock() if err != nil || time.Now().UTC().Sub(last) > (heartbeatIntervalMsec*FailedHeartbeatAcks) { if err != nil { s.log(LogError, "error sending heartbeat to gateway %s, %s", s.gateway, err) } else { s.log(LogError, "haven't gotten a heartbeat ACK in %v, triggering a reconnection", time.Now().UTC().Sub(last)) } s.Close() s.reconnect() return } s.Lock() s.DataReady = true s.Unlock() select { case <-ticker.C: // continue loop and send heartbeat case <-listening: return } } }
[ "func", "(", "s", "*", "Session", ")", "heartbeat", "(", "wsConn", "*", "websocket", ".", "Conn", ",", "listening", "<-", "chan", "interface", "{", "}", ",", "heartbeatIntervalMsec", "time", ".", "Duration", ")", "{", "s", ".", "log", "(", "LogInformatio...
// heartbeat sends regular heartbeats to Discord so it knows the client // is still connected. If you do not send these heartbeats Discord will // disconnect the websocket connection after a few seconds.
[ "heartbeat", "sends", "regular", "heartbeats", "to", "Discord", "so", "it", "knows", "the", "client", "is", "still", "connected", ".", "If", "you", "do", "not", "send", "these", "heartbeats", "Discord", "will", "disconnect", "the", "websocket", "connection", "...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L280-L323
train
bwmarrin/discordgo
wsapi.go
UpdateStatus
func (s *Session) UpdateStatus(idle int, game string) (err error) { return s.UpdateStatusComplex(*newUpdateStatusData(idle, GameTypeGame, game, "")) }
go
func (s *Session) UpdateStatus(idle int, game string) (err error) { return s.UpdateStatusComplex(*newUpdateStatusData(idle, GameTypeGame, game, "")) }
[ "func", "(", "s", "*", "Session", ")", "UpdateStatus", "(", "idle", "int", ",", "game", "string", ")", "(", "err", "error", ")", "{", "return", "s", ".", "UpdateStatusComplex", "(", "*", "newUpdateStatusData", "(", "idle", ",", "GameTypeGame", ",", "game...
// UpdateStatus is used to update the user's status. // If idle>0 then set status to idle. // If game!="" then set game. // if otherwise, set status to active, and no game.
[ "UpdateStatus", "is", "used", "to", "update", "the", "user", "s", "status", ".", "If", "idle", ">", "0", "then", "set", "status", "to", "idle", ".", "If", "game!", "=", "then", "set", "game", ".", "if", "otherwise", "set", "status", "to", "active", "...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L362-L364
train
bwmarrin/discordgo
wsapi.go
UpdateStreamingStatus
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) { gameType := GameTypeGame if url != "" { gameType = GameTypeStreaming } return s.UpdateStatusComplex(*newUpdateStatusData(idle, gameType, game, url)) }
go
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) { gameType := GameTypeGame if url != "" { gameType = GameTypeStreaming } return s.UpdateStatusComplex(*newUpdateStatusData(idle, gameType, game, url)) }
[ "func", "(", "s", "*", "Session", ")", "UpdateStreamingStatus", "(", "idle", "int", ",", "game", "string", ",", "url", "string", ")", "(", "err", "error", ")", "{", "gameType", ":=", "GameTypeGame", "\n", "if", "url", "!=", "\"\"", "{", "gameType", "="...
// UpdateStreamingStatus is used to update the user's streaming status. // If idle>0 then set status to idle. // If game!="" then set game. // If game!="" and url!="" then set the status type to streaming with the URL set. // if otherwise, set status to active, and no game.
[ "UpdateStreamingStatus", "is", "used", "to", "update", "the", "user", "s", "streaming", "status", ".", "If", "idle", ">", "0", "then", "set", "status", "to", "idle", ".", "If", "game!", "=", "then", "set", "game", ".", "If", "game!", "=", "and", "url!"...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L371-L377
train
bwmarrin/discordgo
wsapi.go
UpdateListeningStatus
func (s *Session) UpdateListeningStatus(game string) (err error) { return s.UpdateStatusComplex(*newUpdateStatusData(0, GameTypeListening, game, "")) }
go
func (s *Session) UpdateListeningStatus(game string) (err error) { return s.UpdateStatusComplex(*newUpdateStatusData(0, GameTypeListening, game, "")) }
[ "func", "(", "s", "*", "Session", ")", "UpdateListeningStatus", "(", "game", "string", ")", "(", "err", "error", ")", "{", "return", "s", ".", "UpdateStatusComplex", "(", "*", "newUpdateStatusData", "(", "0", ",", "GameTypeListening", ",", "game", ",", "\"...
// UpdateListeningStatus is used to set the user to "Listening to..." // If game!="" then set to what user is listening to // Else, set user to active and no game.
[ "UpdateListeningStatus", "is", "used", "to", "set", "the", "user", "to", "Listening", "to", "...", "If", "game!", "=", "then", "set", "to", "what", "user", "is", "listening", "to", "Else", "set", "user", "to", "active", "and", "no", "game", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L382-L384
train
bwmarrin/discordgo
wsapi.go
UpdateStatusComplex
func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) { s.RLock() defer s.RUnlock() if s.wsConn == nil { return ErrWSNotFound } s.wsMutex.Lock() err = s.wsConn.WriteJSON(updateStatusOp{3, usd}) s.wsMutex.Unlock() return }
go
func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) { s.RLock() defer s.RUnlock() if s.wsConn == nil { return ErrWSNotFound } s.wsMutex.Lock() err = s.wsConn.WriteJSON(updateStatusOp{3, usd}) s.wsMutex.Unlock() return }
[ "func", "(", "s", "*", "Session", ")", "UpdateStatusComplex", "(", "usd", "UpdateStatusData", ")", "(", "err", "error", ")", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "if", "s", ".", "wsConn", "==", "nil"...
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
[ "UpdateStatusComplex", "allows", "for", "sending", "the", "raw", "status", "update", "data", "untouched", "by", "discordgo", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L387-L400
train
bwmarrin/discordgo
wsapi.go
onVoiceStateUpdate
func (s *Session) onVoiceStateUpdate(st *VoiceStateUpdate) { // If we don't have a connection for the channel, don't bother if st.ChannelID == "" { return } // Check if we have a voice connection to update s.RLock() voice, exists := s.VoiceConnections[st.GuildID] s.RUnlock() if !exists { return } // We only care about events that are about us. if s.State.User.ID != st.UserID { return } // Store the SessionID for later use. voice.Lock() voice.UserID = st.UserID voice.sessionID = st.SessionID voice.ChannelID = st.ChannelID voice.Unlock() }
go
func (s *Session) onVoiceStateUpdate(st *VoiceStateUpdate) { // If we don't have a connection for the channel, don't bother if st.ChannelID == "" { return } // Check if we have a voice connection to update s.RLock() voice, exists := s.VoiceConnections[st.GuildID] s.RUnlock() if !exists { return } // We only care about events that are about us. if s.State.User.ID != st.UserID { return } // Store the SessionID for later use. voice.Lock() voice.UserID = st.UserID voice.sessionID = st.SessionID voice.ChannelID = st.ChannelID voice.Unlock() }
[ "func", "(", "s", "*", "Session", ")", "onVoiceStateUpdate", "(", "st", "*", "VoiceStateUpdate", ")", "{", "if", "st", ".", "ChannelID", "==", "\"\"", "{", "return", "\n", "}", "\n", "s", ".", "RLock", "(", ")", "\n", "voice", ",", "exists", ":=", ...
// onVoiceStateUpdate handles Voice State Update events on the data websocket.
[ "onVoiceStateUpdate", "handles", "Voice", "State", "Update", "events", "on", "the", "data", "websocket", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L663-L689
train
bwmarrin/discordgo
wsapi.go
onVoiceServerUpdate
func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) { s.log(LogInformational, "called") s.RLock() voice, exists := s.VoiceConnections[st.GuildID] s.RUnlock() // If no VoiceConnection exists, just skip this if !exists { return } // If currently connected to voice ws/udp, then disconnect. // Has no effect if not connected. voice.Close() // Store values for later use voice.Lock() voice.token = st.Token voice.endpoint = st.Endpoint voice.GuildID = st.GuildID voice.Unlock() // Open a connection to the voice server err := voice.open() if err != nil { s.log(LogError, "onVoiceServerUpdate voice.open, %s", err) } }
go
func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) { s.log(LogInformational, "called") s.RLock() voice, exists := s.VoiceConnections[st.GuildID] s.RUnlock() // If no VoiceConnection exists, just skip this if !exists { return } // If currently connected to voice ws/udp, then disconnect. // Has no effect if not connected. voice.Close() // Store values for later use voice.Lock() voice.token = st.Token voice.endpoint = st.Endpoint voice.GuildID = st.GuildID voice.Unlock() // Open a connection to the voice server err := voice.open() if err != nil { s.log(LogError, "onVoiceServerUpdate voice.open, %s", err) } }
[ "func", "(", "s", "*", "Session", ")", "onVoiceServerUpdate", "(", "st", "*", "VoiceServerUpdate", ")", "{", "s", ".", "log", "(", "LogInformational", ",", "\"called\"", ")", "\n", "s", ".", "RLock", "(", ")", "\n", "voice", ",", "exists", ":=", "s", ...
// onVoiceServerUpdate handles the Voice Server Update data websocket event. // // This is also fired if the Guild's voice region changes while connected // to a voice channel. In that case, need to re-establish connection to // the new region endpoint.
[ "onVoiceServerUpdate", "handles", "the", "Voice", "Server", "Update", "data", "websocket", "event", ".", "This", "is", "also", "fired", "if", "the", "Guild", "s", "voice", "region", "changes", "while", "connected", "to", "a", "voice", "channel", ".", "In", "...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L696-L725
train
bwmarrin/discordgo
wsapi.go
identify
func (s *Session) identify() error { properties := identifyProperties{runtime.GOOS, "Discordgo v" + VERSION, "", "", "", } data := identifyData{s.Token, properties, 250, s.Compress, nil, } if s.ShardCount > 1 { if s.ShardID >= s.ShardCount { return ErrWSShardBounds } data.Shard = &[2]int{s.ShardID, s.ShardCount} } op := identifyOp{2, data} s.wsMutex.Lock() err := s.wsConn.WriteJSON(op) s.wsMutex.Unlock() return err }
go
func (s *Session) identify() error { properties := identifyProperties{runtime.GOOS, "Discordgo v" + VERSION, "", "", "", } data := identifyData{s.Token, properties, 250, s.Compress, nil, } if s.ShardCount > 1 { if s.ShardID >= s.ShardCount { return ErrWSShardBounds } data.Shard = &[2]int{s.ShardID, s.ShardCount} } op := identifyOp{2, data} s.wsMutex.Lock() err := s.wsConn.WriteJSON(op) s.wsMutex.Unlock() return err }
[ "func", "(", "s", "*", "Session", ")", "identify", "(", ")", "error", "{", "properties", ":=", "identifyProperties", "{", "runtime", ".", "GOOS", ",", "\"Discordgo v\"", "+", "VERSION", ",", "\"\"", ",", "\"\"", ",", "\"\"", ",", "}", "\n", "data", ":=...
// identify sends the identify packet to the gateway
[ "identify", "sends", "the", "identify", "packet", "to", "the", "gateway" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/wsapi.go#L749-L781
train
bwmarrin/discordgo
oauth2.go
Applications
func (s *Session) Applications() (st []*Application, err error) { body, err := s.RequestWithBucketID("GET", EndpointApplications, nil, EndpointApplications) if err != nil { return } err = unmarshal(body, &st) return }
go
func (s *Session) Applications() (st []*Application, err error) { body, err := s.RequestWithBucketID("GET", EndpointApplications, nil, EndpointApplications) if err != nil { return } err = unmarshal(body, &st) return }
[ "func", "(", "s", "*", "Session", ")", "Applications", "(", ")", "(", "st", "[", "]", "*", "Application", ",", "err", "error", ")", "{", "body", ",", "err", ":=", "s", ".", "RequestWithBucketID", "(", "\"GET\"", ",", "EndpointApplications", ",", "nil",...
// Applications returns all applications for the authenticated user
[ "Applications", "returns", "all", "applications", "for", "the", "authenticated", "user" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/oauth2.go#L46-L55
train
bwmarrin/discordgo
logging.go
log
func (s *Session) log(msgL int, format string, a ...interface{}) { if msgL > s.LogLevel { return } msglog(msgL, 2, format, a...) }
go
func (s *Session) log(msgL int, format string, a ...interface{}) { if msgL > s.LogLevel { return } msglog(msgL, 2, format, a...) }
[ "func", "(", "s", "*", "Session", ")", "log", "(", "msgL", "int", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "if", "msgL", ">", "s", ".", "LogLevel", "{", "return", "\n", "}", "\n", "msglog", "(", "msgL", ",", "2...
// helper function that wraps msglog for the Session struct // This adds a check to insure the message is only logged // if the session log level is equal or higher than the // message log level
[ "helper", "function", "that", "wraps", "msglog", "for", "the", "Session", "struct", "This", "adds", "a", "check", "to", "insure", "the", "message", "is", "only", "logged", "if", "the", "session", "log", "level", "is", "equal", "or", "higher", "than", "the"...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/logging.go#L71-L78
train
bwmarrin/discordgo
logging.go
log
func (v *VoiceConnection) log(msgL int, format string, a ...interface{}) { if msgL > v.LogLevel { return } msglog(msgL, 2, format, a...) }
go
func (v *VoiceConnection) log(msgL int, format string, a ...interface{}) { if msgL > v.LogLevel { return } msglog(msgL, 2, format, a...) }
[ "func", "(", "v", "*", "VoiceConnection", ")", "log", "(", "msgL", "int", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "if", "msgL", ">", "v", ".", "LogLevel", "{", "return", "\n", "}", "\n", "msglog", "(", "msgL", "...
// helper function that wraps msglog for the VoiceConnection struct // This adds a check to insure the message is only logged // if the voice connection log level is equal or higher than the // message log level
[ "helper", "function", "that", "wraps", "msglog", "for", "the", "VoiceConnection", "struct", "This", "adds", "a", "check", "to", "insure", "the", "message", "is", "only", "logged", "if", "the", "voice", "connection", "log", "level", "is", "equal", "or", "high...
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/logging.go#L84-L91
train
bwmarrin/discordgo
examples/airhorn/main.go
loadSound
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) } }
go
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) } }
[ "func", "loadSound", "(", ")", "error", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "\"airhorn.dca\"", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"Error opening dca file :\"", ",", "err", ")", "\n", "return", "er...
// loadSound attempts to load an encoded sound file from disk.
[ "loadSound", "attempts", "to", "load", "an", "encoded", "sound", "file", "from", "disk", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/examples/airhorn/main.go#L138-L179
train
bwmarrin/discordgo
examples/airhorn/main.go
playSound
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 }
go
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 }
[ "func", "playSound", "(", "s", "*", "discordgo", ".", "Session", ",", "guildID", ",", "channelID", "string", ")", "(", "err", "error", ")", "{", "vc", ",", "err", ":=", "s", ".", "ChannelVoiceJoin", "(", "guildID", ",", "channelID", ",", "false", ",", ...
// playSound plays the current buffer to the provided channel.
[ "playSound", "plays", "the", "current", "buffer", "to", "the", "provided", "channel", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/examples/airhorn/main.go#L182-L211
train
bwmarrin/discordgo
message.go
NewMessageEdit
func NewMessageEdit(channelID string, messageID string) *MessageEdit { return &MessageEdit{ Channel: channelID, ID: messageID, } }
go
func NewMessageEdit(channelID string, messageID string) *MessageEdit { return &MessageEdit{ Channel: channelID, ID: messageID, } }
[ "func", "NewMessageEdit", "(", "channelID", "string", ",", "messageID", "string", ")", "*", "MessageEdit", "{", "return", "&", "MessageEdit", "{", "Channel", ":", "channelID", ",", "ID", ":", "messageID", ",", "}", "\n", "}" ]
// NewMessageEdit returns a MessageEdit struct, initialized // with the Channel and ID.
[ "NewMessageEdit", "returns", "a", "MessageEdit", "struct", "initialized", "with", "the", "Channel", "and", "ID", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/message.go#L120-L125
train
bwmarrin/discordgo
message.go
SetContent
func (m *MessageEdit) SetContent(str string) *MessageEdit { m.Content = &str return m }
go
func (m *MessageEdit) SetContent(str string) *MessageEdit { m.Content = &str return m }
[ "func", "(", "m", "*", "MessageEdit", ")", "SetContent", "(", "str", "string", ")", "*", "MessageEdit", "{", "m", ".", "Content", "=", "&", "str", "\n", "return", "m", "\n", "}" ]
// SetContent is the same as setting the variable Content, // except it doesn't take a pointer.
[ "SetContent", "is", "the", "same", "as", "setting", "the", "variable", "Content", "except", "it", "doesn", "t", "take", "a", "pointer", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/message.go#L129-L132
train
bwmarrin/discordgo
message.go
SetEmbed
func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit { m.Embed = embed return m }
go
func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit { m.Embed = embed return m }
[ "func", "(", "m", "*", "MessageEdit", ")", "SetEmbed", "(", "embed", "*", "MessageEmbed", ")", "*", "MessageEdit", "{", "m", ".", "Embed", "=", "embed", "\n", "return", "m", "\n", "}" ]
// SetEmbed is a convenience function for setting the embed, // so you can chain commands.
[ "SetEmbed", "is", "a", "convenience", "function", "for", "setting", "the", "embed", "so", "you", "can", "chain", "commands", "." ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/message.go#L136-L139
train
bwmarrin/discordgo
message.go
ContentWithMentionsReplaced
func (m *Message) ContentWithMentionsReplaced() (content string) { content = m.Content for _, user := range m.Mentions { content = strings.NewReplacer( "<@"+user.ID+">", "@"+user.Username, "<@!"+user.ID+">", "@"+user.Username, ).Replace(content) } return }
go
func (m *Message) ContentWithMentionsReplaced() (content string) { content = m.Content for _, user := range m.Mentions { content = strings.NewReplacer( "<@"+user.ID+">", "@"+user.Username, "<@!"+user.ID+">", "@"+user.Username, ).Replace(content) } return }
[ "func", "(", "m", "*", "Message", ")", "ContentWithMentionsReplaced", "(", ")", "(", "content", "string", ")", "{", "content", "=", "m", ".", "Content", "\n", "for", "_", ",", "user", ":=", "range", "m", ".", "Mentions", "{", "content", "=", "strings",...
// ContentWithMentionsReplaced will replace all @<id> mentions with the // username of the mention.
[ "ContentWithMentionsReplaced", "will", "replace", "all" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/message.go#L230-L240
train
bwmarrin/discordgo
message.go
ContentWithMoreMentionsReplaced
func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, err error) { content = m.Content if !s.StateEnabled { content = m.ContentWithMentionsReplaced() return } channel, err := s.State.Channel(m.ChannelID) if err != nil { content = m.ContentWithMentionsReplaced() return } for _, user := range m.Mentions { nick := user.Username member, err := s.State.Member(channel.GuildID, user.ID) if err == nil && member.Nick != "" { nick = member.Nick } content = strings.NewReplacer( "<@"+user.ID+">", "@"+user.Username, "<@!"+user.ID+">", "@"+nick, ).Replace(content) } for _, roleID := range m.MentionRoles { role, err := s.State.Role(channel.GuildID, roleID) if err != nil || !role.Mentionable { continue } content = strings.Replace(content, "<@&"+role.ID+">", "@"+role.Name, -1) } content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string { channel, err := s.State.Channel(mention[2 : len(mention)-1]) if err != nil || channel.Type == ChannelTypeGuildVoice { return mention } return "#" + channel.Name }) return }
go
func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, err error) { content = m.Content if !s.StateEnabled { content = m.ContentWithMentionsReplaced() return } channel, err := s.State.Channel(m.ChannelID) if err != nil { content = m.ContentWithMentionsReplaced() return } for _, user := range m.Mentions { nick := user.Username member, err := s.State.Member(channel.GuildID, user.ID) if err == nil && member.Nick != "" { nick = member.Nick } content = strings.NewReplacer( "<@"+user.ID+">", "@"+user.Username, "<@!"+user.ID+">", "@"+nick, ).Replace(content) } for _, roleID := range m.MentionRoles { role, err := s.State.Role(channel.GuildID, roleID) if err != nil || !role.Mentionable { continue } content = strings.Replace(content, "<@&"+role.ID+">", "@"+role.Name, -1) } content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string { channel, err := s.State.Channel(mention[2 : len(mention)-1]) if err != nil || channel.Type == ChannelTypeGuildVoice { return mention } return "#" + channel.Name }) return }
[ "func", "(", "m", "*", "Message", ")", "ContentWithMoreMentionsReplaced", "(", "s", "*", "Session", ")", "(", "content", "string", ",", "err", "error", ")", "{", "content", "=", "m", ".", "Content", "\n", "if", "!", "s", ".", "StateEnabled", "{", "cont...
// ContentWithMoreMentionsReplaced will replace all @<id> mentions with the // username of the mention, but also role IDs and more.
[ "ContentWithMoreMentionsReplaced", "will", "replace", "all" ]
8325a6bf6dd6c91ed4040a1617b07287b8fb0eba
https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/message.go#L246-L291
train
markbates/goth
provider.go
UseProviders
func UseProviders(viders ...Provider) { for _, provider := range viders { providers[provider.Name()] = provider } }
go
func UseProviders(viders ...Provider) { for _, provider := range viders { providers[provider.Name()] = provider } }
[ "func", "UseProviders", "(", "viders", "...", "Provider", ")", "{", "for", "_", ",", "provider", ":=", "range", "viders", "{", "providers", "[", "provider", ".", "Name", "(", ")", "]", "=", "provider", "\n", "}", "\n", "}" ]
// UseProviders adds a list of available providers for use with Goth. // Can be called multiple times. If you pass the same provider more // than once, the last will be used.
[ "UseProviders", "adds", "a", "list", "of", "available", "providers", "for", "use", "with", "Goth", ".", "Can", "be", "called", "multiple", "times", ".", "If", "you", "pass", "the", "same", "provider", "more", "than", "once", "the", "last", "will", "be", ...
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/provider.go#L34-L38
train
markbates/goth
provider.go
GetProvider
func GetProvider(name string) (Provider, error) { provider := providers[name] if provider == nil { return nil, fmt.Errorf("no provider for %s exists", name) } return provider, nil }
go
func GetProvider(name string) (Provider, error) { provider := providers[name] if provider == nil { return nil, fmt.Errorf("no provider for %s exists", name) } return provider, nil }
[ "func", "GetProvider", "(", "name", "string", ")", "(", "Provider", ",", "error", ")", "{", "provider", ":=", "providers", "[", "name", "]", "\n", "if", "provider", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no provider for %s ...
// GetProvider returns a previously created provider. If Goth has not // been told to use the named provider it will return an error.
[ "GetProvider", "returns", "a", "previously", "created", "provider", ".", "If", "Goth", "has", "not", "been", "told", "to", "use", "the", "named", "provider", "it", "will", "return", "an", "error", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/provider.go#L47-L53
train
markbates/goth
provider.go
ContextForClient
func ContextForClient(h *http.Client) context.Context { if h == nil { return oauth2.NoContext } return context.WithValue(oauth2.NoContext, oauth2.HTTPClient, h) }
go
func ContextForClient(h *http.Client) context.Context { if h == nil { return oauth2.NoContext } return context.WithValue(oauth2.NoContext, oauth2.HTTPClient, h) }
[ "func", "ContextForClient", "(", "h", "*", "http", ".", "Client", ")", "context", ".", "Context", "{", "if", "h", "==", "nil", "{", "return", "oauth2", ".", "NoContext", "\n", "}", "\n", "return", "context", ".", "WithValue", "(", "oauth2", ".", "NoCon...
// ContextForClient provides a context for use with oauth2.
[ "ContextForClient", "provides", "a", "context", "for", "use", "with", "oauth2", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/provider.go#L62-L67
train
markbates/goth
provider.go
HTTPClientWithFallBack
func HTTPClientWithFallBack(h *http.Client) *http.Client { if h != nil { return h } return http.DefaultClient }
go
func HTTPClientWithFallBack(h *http.Client) *http.Client { if h != nil { return h } return http.DefaultClient }
[ "func", "HTTPClientWithFallBack", "(", "h", "*", "http", ".", "Client", ")", "*", "http", ".", "Client", "{", "if", "h", "!=", "nil", "{", "return", "h", "\n", "}", "\n", "return", "http", ".", "DefaultClient", "\n", "}" ]
// HTTPClientWithFallBack to be used in all fetch operations.
[ "HTTPClientWithFallBack", "to", "be", "used", "in", "all", "fetch", "operations", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/provider.go#L70-L75
train
markbates/goth
providers/xero/session.go
Authorize
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) { p := provider.(*Provider) if p.Method == "private" { return p.ClientKey, nil } accessToken, err := p.consumer.AuthorizeToken(s.RequestToken, params.Get("oauth_verifier")) if err != nil { return "", err } s.AccessTokenExpires = time.Now().UTC().Add(30 * time.Minute) s.AccessToken = accessToken return accessToken.Token, err }
go
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) { p := provider.(*Provider) if p.Method == "private" { return p.ClientKey, nil } accessToken, err := p.consumer.AuthorizeToken(s.RequestToken, params.Get("oauth_verifier")) if err != nil { return "", err } s.AccessTokenExpires = time.Now().UTC().Add(30 * time.Minute) s.AccessToken = accessToken return accessToken.Token, err }
[ "func", "(", "s", "*", "Session", ")", "Authorize", "(", "provider", "goth", ".", "Provider", ",", "params", "goth", ".", "Params", ")", "(", "string", ",", "error", ")", "{", "p", ":=", "provider", ".", "(", "*", "Provider", ")", "\n", "if", "p", ...
// Authorize the session with Xero and return the access token to be stored for future use.
[ "Authorize", "the", "session", "with", "Xero", "and", "return", "the", "access", "token", "to", "be", "stored", "for", "future", "use", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/xero/session.go#L30-L44
train
markbates/goth
providers/xero/session.go
Marshal
func (s Session) Marshal() string { b, _ := json.Marshal(s) return string(b) }
go
func (s Session) Marshal() string { b, _ := json.Marshal(s) return string(b) }
[ "func", "(", "s", "Session", ")", "Marshal", "(", ")", "string", "{", "b", ",", "_", ":=", "json", ".", "Marshal", "(", "s", ")", "\n", "return", "string", "(", "b", ")", "\n", "}" ]
// Marshal the session into a string
[ "Marshal", "the", "session", "into", "a", "string" ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/xero/session.go#L47-L50
train
markbates/goth
providers/influxcloud/influxcloud.go
New
func New(clientKey, secret, callbackURL string, scopes ...string) *Provider { domain := os.Getenv(domainEnvKey) if domain == "" { domain = defaultDomain } tokenURL := fmt.Sprintf("https://%s%s", domain, tokenPath) authURL := fmt.Sprintf("https://%s%s", domain, authPath) userAPIEndpoint := fmt.Sprintf("https://%s%s", domain, userAPIPath) return NewCustomisedURL(clientKey, secret, callbackURL, authURL, tokenURL, userAPIEndpoint, scopes...) }
go
func New(clientKey, secret, callbackURL string, scopes ...string) *Provider { domain := os.Getenv(domainEnvKey) if domain == "" { domain = defaultDomain } tokenURL := fmt.Sprintf("https://%s%s", domain, tokenPath) authURL := fmt.Sprintf("https://%s%s", domain, authPath) userAPIEndpoint := fmt.Sprintf("https://%s%s", domain, userAPIPath) return NewCustomisedURL(clientKey, secret, callbackURL, authURL, tokenURL, userAPIEndpoint, scopes...) }
[ "func", "New", "(", "clientKey", ",", "secret", ",", "callbackURL", "string", ",", "scopes", "...", "string", ")", "*", "Provider", "{", "domain", ":=", "os", ".", "Getenv", "(", "domainEnvKey", ")", "\n", "if", "domain", "==", "\"\"", "{", "domain", "...
// New creates a new influx provider, and sets up important connection details. // You should always call `influxcloud.New` to get a new Provider. Never try to create // one manually.
[ "New", "creates", "a", "new", "influx", "provider", "and", "sets", "up", "important", "connection", "details", ".", "You", "should", "always", "call", "influxcloud", ".", "New", "to", "get", "a", "new", "Provider", ".", "Never", "try", "to", "create", "one...
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/influxcloud/influxcloud.go#L34-L44
train
markbates/goth
providers/influxcloud/influxcloud.go
RefreshToken
func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error) { return nil, errors.New("Refresh token is not provided by influxcloud") }
go
func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error) { return nil, errors.New("Refresh token is not provided by influxcloud") }
[ "func", "(", "p", "*", "Provider", ")", "RefreshToken", "(", "refreshToken", "string", ")", "(", "*", "oauth2", ".", "Token", ",", "error", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"Refresh token is not provided by influxcloud\"", ")", "\...
//RefreshToken refresh token is not provided by influxcloud
[ "RefreshToken", "refresh", "token", "is", "not", "provided", "by", "influxcloud" ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/influxcloud/influxcloud.go#L174-L176
train
markbates/goth
providers/tumblr/tumblr.go
FetchUser
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { sess := session.(*Session) user := goth.User{ Provider: p.Name(), } if sess.AccessToken == nil { // data is not yet retrieved since accessToken is still empty return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName) } response, err := p.consumer.Get(endpointProfile, map[string]string{}, sess.AccessToken) if err != nil { return user, err } defer response.Body.Close() if response.StatusCode != http.StatusOK { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } if err = json.NewDecoder(response.Body).Decode(&user.RawData); err != nil { return user, err } res, ok := user.RawData["response"].(map[string]interface{}) if !ok { return user, errors.New("could not decode response") } resUser, ok := res["user"].(map[string]interface{}) if !ok { return user, errors.New("could not decode user") } user.Name = resUser["name"].(string) user.NickName = resUser["name"].(string) user.AccessToken = sess.AccessToken.Token user.AccessTokenSecret = sess.AccessToken.Secret return user, err }
go
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { sess := session.(*Session) user := goth.User{ Provider: p.Name(), } if sess.AccessToken == nil { // data is not yet retrieved since accessToken is still empty return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName) } response, err := p.consumer.Get(endpointProfile, map[string]string{}, sess.AccessToken) if err != nil { return user, err } defer response.Body.Close() if response.StatusCode != http.StatusOK { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode) } if err = json.NewDecoder(response.Body).Decode(&user.RawData); err != nil { return user, err } res, ok := user.RawData["response"].(map[string]interface{}) if !ok { return user, errors.New("could not decode response") } resUser, ok := res["user"].(map[string]interface{}) if !ok { return user, errors.New("could not decode user") } user.Name = resUser["name"].(string) user.NickName = resUser["name"].(string) user.AccessToken = sess.AccessToken.Token user.AccessTokenSecret = sess.AccessToken.Secret return user, err }
[ "func", "(", "p", "*", "Provider", ")", "FetchUser", "(", "session", "goth", ".", "Session", ")", "(", "goth", ".", "User", ",", "error", ")", "{", "sess", ":=", "session", ".", "(", "*", "Session", ")", "\n", "user", ":=", "goth", ".", "User", "...
// FetchUser will go to Tumblr and access basic information about the user.
[ "FetchUser", "will", "go", "to", "Tumblr", "and", "access", "basic", "information", "about", "the", "user", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/tumblr/tumblr.go#L89-L128
train
markbates/goth
providers/yandex/yandex.go
FetchUser
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { sess := session.(*Session) user := goth.User{ AccessToken: sess.AccessToken, Provider: p.Name(), RefreshToken: sess.RefreshToken, ExpiresAt: sess.ExpiresAt, } if user.AccessToken == "" { // data is not yet retrieved since accessToken is still empty return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName) } req, err := http.NewRequest("GET", profileEndpoint, nil) if err != nil { return user, err } req.Header.Set("Authorization", "OAuth " + sess.AccessToken) resp, err := p.Client().Do(req) if err != nil { if resp != nil { resp.Body.Close() } return user, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } bits, err := ioutil.ReadAll(resp.Body) if err != nil { return user, err } err = json.NewDecoder(bytes.NewReader(bits)).Decode(&user.RawData) if err != nil { return user, err } err = userFromReader(bytes.NewReader(bits), &user) return user, err }
go
func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { sess := session.(*Session) user := goth.User{ AccessToken: sess.AccessToken, Provider: p.Name(), RefreshToken: sess.RefreshToken, ExpiresAt: sess.ExpiresAt, } if user.AccessToken == "" { // data is not yet retrieved since accessToken is still empty return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName) } req, err := http.NewRequest("GET", profileEndpoint, nil) if err != nil { return user, err } req.Header.Set("Authorization", "OAuth " + sess.AccessToken) resp, err := p.Client().Do(req) if err != nil { if resp != nil { resp.Body.Close() } return user, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode) } bits, err := ioutil.ReadAll(resp.Body) if err != nil { return user, err } err = json.NewDecoder(bytes.NewReader(bits)).Decode(&user.RawData) if err != nil { return user, err } err = userFromReader(bytes.NewReader(bits), &user) return user, err }
[ "func", "(", "p", "*", "Provider", ")", "FetchUser", "(", "session", "goth", ".", "Session", ")", "(", "goth", ".", "User", ",", "error", ")", "{", "sess", ":=", "session", ".", "(", "*", "Session", ")", "\n", "user", ":=", "goth", ".", "User", "...
// FetchUser will go to Yandex and access basic information about the user.
[ "FetchUser", "will", "go", "to", "Yandex", "and", "access", "basic", "information", "about", "the", "user", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/yandex/yandex.go#L74-L118
train
markbates/goth
providers/steam/session.go
Authorize
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) { p := provider.(*Provider) if params.Get("openid.mode") != "id_res" { return "", errors.New("Mode must equal to \"id_res\".") } if params.Get("openid.return_to") != s.CallbackURL { return "", errors.New("The \"return_to url\" must match the url of current request.") } v := make(url.Values) v.Set("openid.assoc_handle", params.Get("openid.assoc_handle")) v.Set("openid.signed", params.Get("openid.signed")) v.Set("openid.sig", params.Get("openid.sig")) v.Set("openid.ns", params.Get("openid.ns")) split := strings.Split(params.Get("openid.signed"), ",") for _, item := range split { v.Set("openid."+item, params.Get("openid."+item)) } v.Set("openid.mode", "check_authentication") resp, err := p.Client().PostForm(apiLoginEndpoint, v) if err != nil { return "", err } defer resp.Body.Close() content, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } response := strings.Split(string(content), "\n") if response[0] != "ns:"+openIDNs { return "", errors.New("Wrong ns in the response.") } if response[1] == "is_valid:false" { return "", errors.New("Unable validate openId.") } openIDURL := params.Get("openid.claimed_id") validationRegExp := regexp.MustCompile("^(http|https)://steamcommunity.com/openid/id/[0-9]{15,25}$") if !validationRegExp.MatchString(openIDURL) { return "", errors.New("Invalid Steam ID pattern.") } s.SteamID = regexp.MustCompile("\\D+").ReplaceAllString(openIDURL, "") s.ResponseNonce = params.Get("openid.response_nonce") return s.ResponseNonce, nil }
go
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) { p := provider.(*Provider) if params.Get("openid.mode") != "id_res" { return "", errors.New("Mode must equal to \"id_res\".") } if params.Get("openid.return_to") != s.CallbackURL { return "", errors.New("The \"return_to url\" must match the url of current request.") } v := make(url.Values) v.Set("openid.assoc_handle", params.Get("openid.assoc_handle")) v.Set("openid.signed", params.Get("openid.signed")) v.Set("openid.sig", params.Get("openid.sig")) v.Set("openid.ns", params.Get("openid.ns")) split := strings.Split(params.Get("openid.signed"), ",") for _, item := range split { v.Set("openid."+item, params.Get("openid."+item)) } v.Set("openid.mode", "check_authentication") resp, err := p.Client().PostForm(apiLoginEndpoint, v) if err != nil { return "", err } defer resp.Body.Close() content, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } response := strings.Split(string(content), "\n") if response[0] != "ns:"+openIDNs { return "", errors.New("Wrong ns in the response.") } if response[1] == "is_valid:false" { return "", errors.New("Unable validate openId.") } openIDURL := params.Get("openid.claimed_id") validationRegExp := regexp.MustCompile("^(http|https)://steamcommunity.com/openid/id/[0-9]{15,25}$") if !validationRegExp.MatchString(openIDURL) { return "", errors.New("Invalid Steam ID pattern.") } s.SteamID = regexp.MustCompile("\\D+").ReplaceAllString(openIDURL, "") s.ResponseNonce = params.Get("openid.response_nonce") return s.ResponseNonce, nil }
[ "func", "(", "s", "*", "Session", ")", "Authorize", "(", "provider", "goth", ".", "Provider", ",", "params", "goth", ".", "Params", ")", "(", "string", ",", "error", ")", "{", "p", ":=", "provider", ".", "(", "*", "Provider", ")", "\n", "if", "para...
// Authorize the session with Steam and return the unique response_nonce by OpenID.
[ "Authorize", "the", "session", "with", "Steam", "and", "return", "the", "unique", "response_nonce", "by", "OpenID", "." ]
9db62076e0965a39b5a282e506e0aec27d2b1625
https://github.com/markbates/goth/blob/9db62076e0965a39b5a282e506e0aec27d2b1625/providers/steam/session.go#L32-L83
train