mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-27 14:39:24 +00:00
Update vendor (#1297)
This commit is contained in:
82
vendor/github.com/Rhymen/go-whatsapp/conn.go
generated
vendored
82
vendor/github.com/Rhymen/go-whatsapp/conn.go
generated
vendored
@ -116,31 +116,59 @@ Creates a new connection with a given timeout. The websocket connection to the W
|
||||
The goroutine for handling incoming messages is started
|
||||
*/
|
||||
func NewConn(timeout time.Duration) (*Conn, error) {
|
||||
wac := &Conn{
|
||||
handler: make([]Handler, 0),
|
||||
msgCount: 0,
|
||||
msgTimeout: timeout,
|
||||
Store: newStore(),
|
||||
|
||||
longClientName: "github.com/rhymen/go-whatsapp",
|
||||
shortClientName: "go-whatsapp",
|
||||
clientVersion: "0.1.0",
|
||||
}
|
||||
return wac, wac.connect()
|
||||
return NewConnWithOptions(&Options{
|
||||
Timeout: timeout,
|
||||
})
|
||||
}
|
||||
|
||||
// NewConnWithProxy Create a new connect with a given timeout and a http proxy.
|
||||
func NewConnWithProxy(timeout time.Duration, proxy func(*http.Request) (*url.URL, error)) (*Conn, error) {
|
||||
return NewConnWithOptions(&Options{
|
||||
Timeout: timeout,
|
||||
Proxy: proxy,
|
||||
})
|
||||
}
|
||||
|
||||
// NewConnWithOptions Create a new connect with a given options.
|
||||
type Options struct {
|
||||
Proxy func(*http.Request) (*url.URL, error)
|
||||
Timeout time.Duration
|
||||
Handler []Handler
|
||||
ShortClientName string
|
||||
LongClientName string
|
||||
ClientVersion string
|
||||
Store *Store
|
||||
}
|
||||
func NewConnWithOptions(opt *Options) (*Conn, error) {
|
||||
if opt == nil {
|
||||
return nil, ErrOptionsNotProvided
|
||||
}
|
||||
wac := &Conn{
|
||||
handler: make([]Handler, 0),
|
||||
msgCount: 0,
|
||||
msgTimeout: timeout,
|
||||
msgTimeout: opt.Timeout,
|
||||
Store: newStore(),
|
||||
|
||||
longClientName: "github.com/rhymen/go-whatsapp",
|
||||
longClientName: "github.com/Rhymen/go-whatsapp",
|
||||
shortClientName: "go-whatsapp",
|
||||
clientVersion: "0.1.0",
|
||||
Proxy: proxy,
|
||||
}
|
||||
if opt.Handler != nil {
|
||||
wac.handler = opt.Handler
|
||||
}
|
||||
if opt.Store != nil {
|
||||
wac.Store = opt.Store
|
||||
}
|
||||
if opt.Proxy != nil {
|
||||
wac.Proxy = opt.Proxy
|
||||
}
|
||||
if len(opt.ShortClientName) != 0 {
|
||||
wac.shortClientName = opt.ShortClientName
|
||||
}
|
||||
if len(opt.LongClientName) != 0 {
|
||||
wac.longClientName = opt.LongClientName
|
||||
}
|
||||
if len(opt.ClientVersion) != 0 {
|
||||
wac.clientVersion = opt.ClientVersion
|
||||
}
|
||||
return wac, wac.connect()
|
||||
}
|
||||
@ -249,10 +277,26 @@ func (wac *Conn) keepAlive(minIntervalMs int, maxIntervalMs int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wac *Conn) GetConnected() bool {
|
||||
return wac.connected
|
||||
// IsConnected returns whether the server connection is established or not
|
||||
func (wac *Conn) IsConnected() bool {
|
||||
return wac.connected
|
||||
}
|
||||
|
||||
func (wac *Conn) GetLoggedIn() bool {
|
||||
return wac.loggedIn
|
||||
// GetConnected returns whether the server connection is established or not
|
||||
//
|
||||
// Deprecated: function name is not go idiomatic, use IsConnected instead
|
||||
func (wac *Conn) GetConnected() bool {
|
||||
return wac.connected
|
||||
}
|
||||
|
||||
//IsLoggedIn returns whether the you are logged in or not
|
||||
func (wac *Conn) IsLoggedIn() bool {
|
||||
return wac.loggedIn
|
||||
}
|
||||
|
||||
// GetLoggedIn returns whether the you are logged in or not
|
||||
//
|
||||
// Deprecated: function name is not go idiomatic, use IsLoggedIn instead.
|
||||
func (wac *Conn) GetLoggedIn() bool {
|
||||
return wac.loggedIn
|
||||
}
|
||||
|
2
vendor/github.com/Rhymen/go-whatsapp/errors.go
generated
vendored
2
vendor/github.com/Rhymen/go-whatsapp/errors.go
generated
vendored
@ -22,6 +22,8 @@ var (
|
||||
ErrMediaDownloadFailedWith404 = errors.New("download failed with status code 404")
|
||||
ErrMediaDownloadFailedWith410 = errors.New("download failed with status code 410")
|
||||
ErrInvalidWebsocket = errors.New("invalid websocket")
|
||||
ErrMessageTypeNotImplemented = errors.New("message type not implemented")
|
||||
ErrOptionsNotProvided = errors.New("new conn options not provided")
|
||||
)
|
||||
|
||||
type ErrConnectionFailed struct {
|
||||
|
1
vendor/github.com/Rhymen/go-whatsapp/go.sum
generated
vendored
1
vendor/github.com/Rhymen/go-whatsapp/go.sum
generated
vendored
@ -32,5 +32,6 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
|
36
vendor/github.com/Rhymen/go-whatsapp/media.go
generated
vendored
36
vendor/github.com/Rhymen/go-whatsapp/media.go
generated
vendored
@ -38,7 +38,7 @@ func Download(url string, mediaKey []byte, appInfo MediaType, fileLength int) ([
|
||||
return nil, err
|
||||
}
|
||||
if len(data) != fileLength {
|
||||
return nil, fmt.Errorf("file length does not match")
|
||||
return nil, fmt.Errorf("file length does not match. Expected: %v, got: %v", fileLength, len(data))
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
@ -93,21 +93,21 @@ func downloadMedia(url string) (file []byte, mac []byte, err error) {
|
||||
return data[:n-10], data[n-10 : n], nil
|
||||
}
|
||||
|
||||
|
||||
type MediaConn struct {
|
||||
Status int `json:"status"`
|
||||
MediaConn struct {
|
||||
Auth string `json:"auth"`
|
||||
TTL int `json:"ttl"`
|
||||
Hosts []struct {
|
||||
Hostname string `json:"hostname"`
|
||||
IPs []interface{} `json:"ips"`
|
||||
} `json:"hosts"`
|
||||
} `json:"media_conn"`
|
||||
type MediaConn struct {
|
||||
Status int `json:"status"`
|
||||
MediaConn struct {
|
||||
Auth string `json:"auth"`
|
||||
TTL int `json:"ttl"`
|
||||
Hosts []struct {
|
||||
Hostname string `json:"hostname"`
|
||||
IPs []struct {
|
||||
IP4 string `json:"ip4"`
|
||||
IP6 string `json:"ip6"`
|
||||
} `json:"ips"`
|
||||
} `json:"hosts"`
|
||||
} `json:"media_conn"`
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
|
||||
queryReq := []interface{}{"query", "mediaConn"}
|
||||
ch, err := wac.writeJson(queryReq)
|
||||
@ -131,7 +131,7 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
|
||||
|
||||
var host string
|
||||
for _, h := range resp.MediaConn.Hosts {
|
||||
if h.Hostname!="" {
|
||||
if h.Hostname != "" {
|
||||
host = h.Hostname
|
||||
break
|
||||
}
|
||||
@ -143,10 +143,10 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
|
||||
}
|
||||
|
||||
var mediaTypeMap = map[MediaType]string{
|
||||
MediaImage: "/mms/image",
|
||||
MediaVideo: "/mms/video",
|
||||
MediaImage: "/mms/image",
|
||||
MediaVideo: "/mms/video",
|
||||
MediaDocument: "/mms/document",
|
||||
MediaAudio: "/mms/audio",
|
||||
MediaAudio: "/mms/audio",
|
||||
}
|
||||
|
||||
func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string, mediaKey []byte, fileEncSha256 []byte, fileSha256 []byte, fileLength uint64, err error) {
|
||||
|
17
vendor/github.com/Rhymen/go-whatsapp/message.go
generated
vendored
17
vendor/github.com/Rhymen/go-whatsapp/message.go
generated
vendored
@ -238,7 +238,7 @@ func getMessageInfo(msg *proto.WebMessageInfo) MessageInfo {
|
||||
return MessageInfo{
|
||||
Id: msg.GetKey().GetId(),
|
||||
RemoteJid: msg.GetKey().GetRemoteJid(),
|
||||
SenderJid: msg.GetKey().GetParticipant(),
|
||||
SenderJid: msg.GetParticipant(),
|
||||
FromMe: msg.GetKey().GetFromMe(),
|
||||
Timestamp: msg.GetMessageTimestamp(),
|
||||
Status: MessageStatus(msg.GetStatus()),
|
||||
@ -838,19 +838,16 @@ func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
|
||||
|
||||
default:
|
||||
//cannot match message
|
||||
|
||||
return ErrMessageTypeNotImplemented
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
BatteryMessage represents a battery level and charging state.
|
||||
*/
|
||||
type BatteryMessage struct {
|
||||
Plugged bool
|
||||
Powersave bool
|
||||
Plugged bool
|
||||
Powersave bool
|
||||
Percentage int
|
||||
}
|
||||
|
||||
@ -859,8 +856,8 @@ func getBatteryMessage(msg map[string]string) BatteryMessage {
|
||||
powersave, _ := strconv.ParseBool(msg["powersave"])
|
||||
percentage, _ := strconv.Atoi(msg["value"])
|
||||
batteryMessage := BatteryMessage{
|
||||
Plugged: plugged,
|
||||
Powersave: powersave,
|
||||
Plugged: plugged,
|
||||
Powersave: powersave,
|
||||
Percentage: percentage,
|
||||
}
|
||||
|
||||
@ -869,7 +866,7 @@ func getBatteryMessage(msg map[string]string) BatteryMessage {
|
||||
|
||||
func getNewContact(msg map[string]string) Contact {
|
||||
contact := Contact{
|
||||
Jid: msg["jid"],
|
||||
Jid: msg["jid"],
|
||||
Notify: msg["notify"],
|
||||
}
|
||||
|
||||
|
4
vendor/github.com/Rhymen/go-whatsapp/read.go
generated
vendored
4
vendor/github.com/Rhymen/go-whatsapp/read.go
generated
vendored
@ -62,6 +62,10 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error {
|
||||
data[0] = "!"
|
||||
}
|
||||
|
||||
if len(data) == 2 && len(data[1]) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(data) != 2 || len(data[1]) == 0 {
|
||||
return ErrInvalidWsData
|
||||
}
|
||||
|
Reference in New Issue
Block a user