MCPcopy
hub / github.com/EverythingSuckz/TG-FileStreamBot / StartClient

Function StartClient

internal/bot/client.go:18–55  ·  view source on GitHub ↗
(log *zap.Logger)

Source from the content-addressed store, hash-verified

16var Bot *gotgproto.Client
17
18func 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}

Callers 1

runAppFunction · 0.92

Calls 2

LoadFunction · 0.92
StringMethod · 0.80

Tested by

no test coverage detected