6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-27 09:18:22 +00:00

Fix svc bot so it attempts reconnect until successful (#70)

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/70
Reviewed-by: xuu <xuu@noreply@mills.io>
Co-authored-by: James Mills <james@mills.io>
Co-committed-by: James Mills <james@mills.io>
This commit is contained in:
James Mills 2022-03-27 02:11:40 +00:00 committed by xuu
parent df84b1f3b4
commit 5420bcde15
3 changed files with 15 additions and 9 deletions

1
.gitignore vendored

@ -11,6 +11,7 @@
/msgs
/dist
/certs
/saltyd
/salty-chat
/cmd/saltyd/saltyd

@ -251,14 +251,19 @@ func (s *Server) setupSvcUser() {
return
}
// Wait for things to settle
//time.Sleep(time.Second * 5)
var cli *saltyim.Client
cli, err := saltyim.NewClient(me, saltyim.WithIdentity(ident))
if err != nil {
log.WithError(err).Error("error creating svc user's client")
return
for {
cli, err = saltyim.NewClient(me, saltyim.WithIdentity(ident))
if err != nil {
log.WithError(err).Warn("error creating svc user's client")
time.Sleep(time.Second * 3)
continue
} else {
break
}
}
svc, err := saltyim.NewService(cli)
if err != nil {
log.WithError(err).Errorf("error creating service")
@ -442,7 +447,7 @@ func NewServer(bind string, options ...Option) (*Server, error) {
server.initRoutes()
go server.runStartupJobs()
server.setupSvcUser()
go server.setupSvcUser()
return server, nil
}

@ -39,10 +39,10 @@ func NewService(client *Client) (*Service, error) {
}
func (svc *Service) String() string {
buf := &bytes.Buffer{}
fmt.Fprintln(buf, "Bot: ", svc.Client.me)
svc.mu.RLock()
defer svc.mu.RUnlock()
buf := &bytes.Buffer{}
for k := range svc.textFns {
fmt.Fprintln(buf, " - TextCmd: ", k)
}