This commit is contained in:
2023-08-14 00:17:42 +07:00
parent 6ce7cee5bc
commit fd88563096
5 changed files with 47 additions and 16 deletions
+5 -4
View File
@@ -2,6 +2,7 @@ package bot_all
import (
"context"
"fmt"
"strings"
"github.com/samber/lo"
@@ -27,21 +28,21 @@ func NewBotAll(
}
func (bot *botAll) Process(ctx context.Context, msg *messenger.Message) error {
if err := bot.storage.UpsertUser(ctx, storage.User{ChatID: msg.ChatID, UserID: msg.UserID}); err != nil {
if err := bot.storage.UpsertUser(ctx, &storage.User{ChatID: msg.ChatID, UserID: msg.UserID}); err != nil {
return err
}
if !strings.Contains(msg.Text, "@all") {
if !strings.Contains(msg.Text, "@all") && !strings.Contains(msg.Text, "@все") && strings.ToLower(msg.Text) != "ау" {
return nil
}
users, err := bot.storage.GetAllUsersByChatID(ctx, msg.ChatID)
if err != nil {
return err
}
usernames := lo.FilterMap(users, func(item storage.User, _ int) (string, bool) {
usernames := lo.FilterMap(users, func(item *storage.User, _ int) (string, bool) {
if item.UserID == msg.UserID {
return "", false
}
return item.UserID, true
return fmt.Sprintf("@%s", item.UserID), true
})
if len(usernames) > 0 {
bot.messenger.SendMessage(