| 16 | var Bot *gotgproto.Client |
| 17 | |
| 18 | func StartClient(log *zap.Logger) (*gotgproto.Client, error) { |
| 19 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 20 | defer cancel() |
| 21 | resultChan := make(chan struct { |
| 22 | client *gotgproto.Client |
| 23 | err error |
| 24 | }) |
| 25 | go func(ctx context.Context) { |
| 26 | client, err := gotgproto.NewClient( |
| 27 | int(config.ValueOf.ApiID), |
| 28 | config.ValueOf.ApiHash, |
| 29 | gotgproto.ClientTypeBot(config.ValueOf.BotToken), |
| 30 | &gotgproto.ClientOpts{ |
| 31 | Session: sessionMaker.SqlSession( |
| 32 | sqlite.Open("fsb.session"), |
| 33 | ), |
| 34 | DisableCopyright: true, |
| 35 | }, |
| 36 | ) |
| 37 | resultChan <- struct { |
| 38 | client *gotgproto.Client |
| 39 | err error |
| 40 | }{client, err} |
| 41 | }(ctx) |
| 42 | |
| 43 | select { |
| 44 | case <-ctx.Done(): |
| 45 | return nil, ctx.Err() |
| 46 | case result := <-resultChan: |
| 47 | if result.err != nil { |
| 48 | return nil, result.err |
| 49 | } |
| 50 | commands.Load(log, result.client.Dispatcher) |
| 51 | log.Info("Client started", zap.String("username", result.client.Self.Username)) |
| 52 | Bot = result.client |
| 53 | return result.client, nil |
| 54 | } |
| 55 | } |