Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b23fbd1d8e | ||
|
ff76b5842d | ||
|
de084cbd21 |
40
map.go
40
map.go
@ -1,12 +1,8 @@
|
|||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"git.belvedersky.ru/common/logger/service"
|
"git.belvedersky.ru/common/logger/service"
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/puzpuzpuz/xsync"
|
"github.com/puzpuzpuz/xsync"
|
||||||
"gopkg.in/telebot.v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bots struct {
|
type Bots struct {
|
||||||
@ -20,39 +16,3 @@ func NewMap(Log *service.LoggerService) *Bots {
|
|||||||
I: xsync.NewMapOf[*Bot](),
|
I: xsync.NewMapOf[*Bot](),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bots) Get(c *fiber.Ctx) error {
|
|
||||||
name := c.Params("name")
|
|
||||||
if name != "" {
|
|
||||||
b.log.Log.Println("Запрос на получение бота", name)
|
|
||||||
_b, ok := b.I.Load(name)
|
|
||||||
if !ok {
|
|
||||||
botId, err := strconv.Atoi(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.I.Range(func(key string, bot *Bot) bool {
|
|
||||||
if bot.Self().ID == int64(botId) {
|
|
||||||
_b = bot
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if _b == nil {
|
|
||||||
return c.Status(404).SendString("not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c.JSON(_b.Self())
|
|
||||||
}
|
|
||||||
return c.Status(404).SendString("not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bots) GetAll(c *fiber.Ctx) error {
|
|
||||||
bots := []*telebot.User{}
|
|
||||||
b.I.Range(func(key string, value *Bot) bool {
|
|
||||||
bot := value
|
|
||||||
bots = append(bots, bot.Self())
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
return c.JSON(bots)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user