feat: login

This commit is contained in:
Rogee
2024-09-02 14:50:51 +08:00
parent 97e0731e2e
commit d739ca0184
7 changed files with 80 additions and 51 deletions

View File

@@ -30,9 +30,10 @@ type TClient struct {
// t.block <- struct{}{}
// }
func NewClient(config *config.Config) *TClient {
func NewClient(logger *zap.Logger, config *config.Config) *TClient {
c := &TClient{
Config: config,
logger: logger,
Client: telegram.NewClient(config.AppID, config.AppHash, telegram.Options{
Logger: logger,
UpdateHandler: nil,
@@ -50,28 +51,8 @@ func (t *TClient) WithMedia() *TClient {
return t
}
// func (t *TClient) Run(ctx context.Context) {
// err := t.Client.Run(ctx, func(ctx context.Context) error {
// flow := auth.NewFlow(Terminal{PhoneNumber: t.Config.Phone}, auth.SendCodeOptions{})
// if err := t.Client.Auth().IfNecessary(ctx, flow); err != nil {
// return errors.Wrap(err, "auth")
// }
// t.api = t.Client.API()
// t.waitLogin <- nil
// <-t.block
// return nil
// })
// if err != nil {
// t.waitLogin <- err
// }
// }
// func (t *TClient) Wait() <-chan error {
// return t.waitLogin
// }
func (t *TClient) Login(ctx context.Context) error {
t.logger.Info("login phone", zap.String("phone", t.Config.Phone))
flow := auth.NewFlow(Terminal{PhoneNumber: client.Config.Phone}, auth.SendCodeOptions{})
if err := t.Client.Auth().IfNecessary(context.Background(), flow); err != nil {
return errors.Wrap(err, "auth")