Compare commits

...

2 Commits

Author SHA1 Message Date
7de8a59be8 forece push
Some checks failed
dev test / test (push) Successful in 31s
dev test / vulnCheck (push) Successful in 38s
dev test / Ci-Lint (push) Failing after 32s
2024-12-13 15:37:43 -04:00
f9fcba36fd ADD bot creation on not exist
Some checks failed
dev test / test (push) Successful in 11s
dev test / vulnCheck (push) Successful in 15s
dev test / Ci-Lint (push) Failing after 46s
${{ github.actor }} executed Build Push Prod / build (push) Successful in 4m3s
${{ github.actor }} executed Build Push Prod / deploy (push) Successful in 18s
2024-12-05 00:01:46 -04:00
4 changed files with 21 additions and 1 deletions

View File

@ -48,7 +48,7 @@ func main() {
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
// bot user update channel
// bot user update chan
updtChan := bot.GetUpdatesChan(u)
// subs chann
changeChan := make(chan *nats.Msg, 64)
@ -72,6 +72,7 @@ func main() {
signal.Notify(sign, syscall.SIGINT, syscall.SIGTERM)
defer close(sign)
app := api.NewApi(bot)
// check for bot in db
for {
select {
case update := <-updtChan:

View File

@ -141,3 +141,12 @@ func (a Adapter) GetAllBotsUsers(botname string) ([]*domain.User, error) {
}
return list, nil
}
func (a Adapter) CreateBot(botname string) (error){
_, err := a.user.CreateBot(context.Background(), &tgbuser.TGBBotNameRequest{BotName: botname})
if err != nil {
a.log.Error("creating bot", "error", err)
return err
}
return nil
}

View File

@ -38,6 +38,10 @@ func (a *api) Run(update *tgbotapi.Update, dolar ports.DolarService, user ports.
a.log.Info("bot not restricted adding user to DB")
user.Create(update.SentFrom())
a.log.Info("Adding query permision to user over bot")
err = user.CreateBot(a.bot.Self.UserName)
if err != nil {
a.log.Error("creating bot", "error", err)
}
user.AddBot(update.SentFrom().ID, a.bot.Self.UserName)
}
a.log.Error("getting user", "error", err)
@ -50,6 +54,11 @@ func (a *api) Run(update *tgbotapi.Update, dolar ports.DolarService, user ports.
if !slices.Contains(bots, a.bot.Self.UserName) {
a.log.Info("bot not found in db for user", "bot", a.bot.Self.UserName)
a.log.Info("adding bots", "user", update.SentFrom().UserName, "bot", a.bot.Self.UserName)
err = user.CreateBot(a.bot.Self.UserName)
if err != nil {
a.log.Error("creating bot", "error", err)
}
_, err := user.AddBot(update.SentFrom().ID, a.bot.Self.UserName)
if err != nil {
a.log.Error("adding bots", "user", update.SentFrom().UserName, "bot", a.bot.Self.UserName, "error", err)

View File

@ -14,4 +14,5 @@ type UserService interface {
GetBots(int64) ([]string, error)
DeleteBot(int64, string) (bool, error)
GetAllBotsUsers(string) ([]*domain.User, error)
CreateBot(string)(error)
}