Spaces:
Running
Running
Download internal/bot/client.go from codebydante/BrodyFileStreamBot: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/codebydante/BrodyFileStreamBot/resolve/bd894b382ed6a42e3879e3846027d7e6d427f3f2/internal/bot/client.go
- Command line
-
hf download hf://spaces/codebydante/BrodyFileStreamBot@bd894b382ed6a42e3879e3846027d7e6d427f3f2/internal/bot/client.go
-
curl -L -o client.go https://huggingface.co/spaces/codebydante/BrodyFileStreamBot/resolve/bd894b382ed6a42e3879e3846027d7e6d427f3f2/internal/bot/client.go
1.42 kB
| package bot | |
| import ( | |
| "EverythingSuckz/fsb/config" | |
| "EverythingSuckz/fsb/internal/commands" | |
| "context" | |
| "time" | |
| "go.uber.org/zap" | |
| "github.com/celestix/gotgproto" | |
| "github.com/celestix/gotgproto/sessionMaker" | |
| "github.com/glebarez/sqlite" | |
| ) | |
| var Bot *gotgproto.Client | |
| func StartClient(log *zap.Logger) (*gotgproto.Client, error) { | |
| ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) | |
| defer cancel() | |
| resultChan := make(chan struct { | |
| client *gotgproto.Client | |
| err error | |
| }) | |
| go func(ctx context.Context) { | |
| client, err := gotgproto.NewClient( | |
| int(config.ValueOf.ApiID), | |
| config.ValueOf.ApiHash, | |
| gotgproto.ClientTypeBot(config.ValueOf.BotToken), | |
| &gotgproto.ClientOpts{ | |
| Session: sessionMaker.SqlSession( | |
| sqlite.Open("fsb.session"), | |
| ), | |
| DisableCopyright: true, | |
| }, | |
| ) | |
| resultChan <- struct { | |
| client *gotgproto.Client | |
| err error | |
| }{client, err} | |
| }(ctx) | |
| select { | |
| case <-ctx.Done(): | |
| return nil, ctx.Err() | |
| case result := <-resultChan: | |
| if result.err != nil { | |
| return nil, result.err | |
| } | |
| commands.Load(log, result.client.Dispatcher) | |
| if err := commands.RegisterCommands(); err != nil { | |
| log.Error("Failed to register commands", zap.Error(err)) | |
| } | |
| log.Info("Client started", zap.String("username", result.client.Self.Username)) | |
| Bot = result.client | |
| return result.client, nil | |
| } | |
| } | |