Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7de8a59be8 | |||
| f9fcba36fd |
@ -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:
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -14,4 +14,5 @@ type UserService interface {
|
||||
GetBots(int64) ([]string, error)
|
||||
DeleteBot(int64, string) (bool, error)
|
||||
GetAllBotsUsers(string) ([]*domain.User, error)
|
||||
CreateBot(string)(error)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user