mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-09-20 16:25:54 +08:00
fixed nonauth client
This commit is contained in:
parent
20bca7952e
commit
ca06088900
|
@ -246,9 +246,9 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
|
|||
dispatcher := tg.NewUpdateDispatcher()
|
||||
loggedIn := qrlogin.OnLoginToken(dispatcher)
|
||||
sessionStorage := &session.StorageMemory{}
|
||||
tgClient := utils.GetNonAuthClient(dispatcher, sessionStorage)
|
||||
tgClient, stop, _ := utils.StartNonAuthClient(dispatcher, sessionStorage)
|
||||
|
||||
tgClient.Run(c, func(ctx context.Context) error {
|
||||
defer stop()
|
||||
|
||||
for {
|
||||
message := &SocketMessage{}
|
||||
|
@ -256,7 +256,7 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
|
|||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
return
|
||||
}
|
||||
if message.AuthType == "qr" {
|
||||
go func() {
|
||||
|
@ -343,6 +343,5 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
|
|||
}()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -115,17 +115,25 @@ func GetAuthClient(ctx context.Context, sessionStr string, userId int64) (*teleg
|
|||
return client, nil
|
||||
}
|
||||
|
||||
func GetNonAuthClient(handler telegram.UpdateHandler, storage telegram.SessionStorage) *telegram.Client {
|
||||
func StartNonAuthClient(handler telegram.UpdateHandler, storage telegram.SessionStorage) (*telegram.Client, bg.StopFunc, error) {
|
||||
middlewares := []telegram.Middleware{}
|
||||
if config.RateLimit {
|
||||
middlewares = append(middlewares, ratelimit.New(rate.Every(time.Millisecond*100), 5))
|
||||
}
|
||||
client := telegram.NewClient(config.AppId, config.AppHash, telegram.Options{
|
||||
SessionStorage: storage,
|
||||
Middlewares: middlewares,
|
||||
Device: getDeviceConfig(),
|
||||
UpdateHandler: handler,
|
||||
ReconnectionBackoff: reconnectionBackoff,
|
||||
RetryInterval: 5 * time.Second,
|
||||
MaxRetries: 5,
|
||||
})
|
||||
|
||||
return client
|
||||
stop, err := bg.Connect(client)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return client, stop, nil
|
||||
}
|
||||
|
||||
func startBotClient(ctx context.Context, client *telegram.Client, token string) (bg.StopFunc, error) {
|
||||
|
|
Loading…
Reference in a new issue