-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
695 changed files
with
214 additions
and
30 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
package internal | ||
|
||
//go:generate go run github.com/ernado/td/gen/cmd/gotdgen --clean --package mt --target mt --schema _schema/schema.tl | ||
|
||
//go:generate go run github.com/ernado/td/gen/cmd/gotdgen --clean --package tg --target tg --schema _schema/telegram.tl | ||
//go:generate go run github.com/ernado/td/cmd/gotdgen --clean --package mt --target mt --schema _schema/schema.tl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// Package td implements MTProto encoding and decoding. | ||
package td | ||
|
||
//go:generate go run github.com/ernado/td/cmd/gotdgen --clean --package tg --target tg --schema _schema/telegram.tl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package telegram | ||
|
||
import ( | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/ernado/td/bin" | ||
"github.com/ernado/td/internal/proto" | ||
) | ||
|
||
func (c *Client) gzip(b *bin.Buffer) (*bin.Buffer, error) { | ||
var content proto.GZIP | ||
if err := content.Decode(b); err != nil { | ||
return nil, xerrors.Errorf("failed to decode: %w", err) | ||
} | ||
return &bin.Buffer{Buf: content.Data}, nil | ||
} | ||
|
||
func (c *Client) handleGZIP(b *bin.Buffer) error { | ||
content, err := c.gzip(b) | ||
if err != nil { | ||
return xerrors.Errorf("failed to unzip: %w", err) | ||
} | ||
return c.handleMessage(content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package telegram | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/ernado/td/bin" | ||
"github.com/ernado/td/tg" | ||
) | ||
|
||
func (c *Client) processUpdates(updates tg.UpdatesClass) error { | ||
if c.updateHandler == nil { | ||
// Ignoring. Probably we should ACK. | ||
return nil | ||
} | ||
switch u := updates.(type) { | ||
case *tg.Updates: | ||
go func() { | ||
if c.updateHandler == nil { | ||
return | ||
} | ||
// We should send ACK here. | ||
if err := c.updateHandler(u); err != nil { | ||
c.log.With(zap.Error(err)).Error("Update handler returning error") | ||
} | ||
}() | ||
return nil | ||
default: | ||
c.log.With(zap.String("update_type", fmt.Sprintf("%T", u))).Debug("Ignoring update") | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Client) handleUpdates(b *bin.Buffer) error { | ||
updates, err := tg.DecodeUpdates(b) | ||
if err != nil { | ||
return xerrors.Errorf("failed to decode updates: %w", err) | ||
} | ||
return c.processUpdates(updates) | ||
} | ||
|
||
// SetUpdateHandler sets handler as default update handler. | ||
// | ||
// Provided handler will be called on received update. | ||
func (c *Client) SetUpdateHandler(handler func(u *tg.Updates) error) { | ||
c.updateHandler = handler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.