(l *zap.Logger)
| 18 | var UserBot *UserBotStruct = &UserBotStruct{} |
| 19 | |
| 20 | func StartUserBot(l *zap.Logger) { |
| 21 | log := l.Named("USERBOT") |
| 22 | if config.ValueOf.UserSession == "" { |
| 23 | log.Warn("User session is empty") |
| 24 | return |
| 25 | } |
| 26 | log.Sugar().Infoln("Starting userbot") |
| 27 | client, err := gotgproto.NewClient( |
| 28 | int(config.ValueOf.ApiID), |
| 29 | config.ValueOf.ApiHash, |
| 30 | gotgproto.ClientTypePhone(""), |
| 31 | &gotgproto.ClientOpts{ |
| 32 | Session: sessionMaker.PyrogramSession(config.ValueOf.UserSession), |
| 33 | DisableCopyright: true, |
| 34 | }, |
| 35 | ) |
| 36 | if err != nil { |
| 37 | log.Error("Failed to start userbot", zap.Error(err)) |
| 38 | return |
| 39 | } |
| 40 | UserBot.log = log |
| 41 | UserBot.client = client |
| 42 | log.Info("Userbot started", zap.String("username", client.Self.Username), zap.String("FirstName", client.Self.FirstName), zap.String("LastName", client.Self.LastName)) |
| 43 | if err := UserBot.AddBotsAsAdmins(); err != nil { |
| 44 | log.Error("Failed to add bots as admins", zap.Error(err)) |
| 45 | return |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func (u *UserBotStruct) AddBotsAsAdmins() error { |
| 50 | u.log.Info("Preparing to add bots as admins") |
no test coverage detected