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
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
This commit is contained in:
parent
30f02a8d01
commit
f9fcba36fd
@ -72,6 +72,7 @@ func main() {
|
|||||||
signal.Notify(sign, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sign, syscall.SIGINT, syscall.SIGTERM)
|
||||||
defer close(sign)
|
defer close(sign)
|
||||||
app := api.NewApi(bot)
|
app := api.NewApi(bot)
|
||||||
|
// check for bot in db
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case update := <-updtChan:
|
case update := <-updtChan:
|
||||||
|
|||||||
@ -141,3 +141,12 @@ func (a Adapter) GetAllBotsUsers(botname string) ([]*domain.User, error) {
|
|||||||
}
|
}
|
||||||
return list, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -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")
|
a.log.Info("bot not restricted adding user to DB")
|
||||||
user.Create(update.SentFrom())
|
user.Create(update.SentFrom())
|
||||||
a.log.Info("Adding query permision to user over bot")
|
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)
|
user.AddBot(update.SentFrom().ID, a.bot.Self.UserName)
|
||||||
}
|
}
|
||||||
a.log.Error("getting user", "error", err)
|
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) {
|
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("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)
|
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)
|
_, err := user.AddBot(update.SentFrom().ID, a.bot.Self.UserName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("adding bots", "user", update.SentFrom().UserName, "bot", a.bot.Self.UserName, "error", err)
|
a.log.Error("adding bots", "user", update.SentFrom().UserName, "bot", a.bot.Self.UserName, "error", err)
|
||||||
|
|||||||
@ -14,4 +14,5 @@ type UserService interface {
|
|||||||
GetBots(int64) ([]string, error)
|
GetBots(int64) ([]string, error)
|
||||||
DeleteBot(int64, string) (bool, error)
|
DeleteBot(int64, string) (bool, error)
|
||||||
GetAllBotsUsers(string) ([]*domain.User, error)
|
GetAllBotsUsers(string) ([]*domain.User, error)
|
||||||
|
CreateBot(string)(error)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user