add AddUserInChat

This commit is contained in:
Владимир Фёдоров 2022-04-25 02:57:53 +07:00
parent c4a39056d8
commit 9d5b5c2a2f
2 changed files with 3 additions and 3 deletions

View File

@ -30,7 +30,7 @@ func AddChat(chatID int64) error {
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
result := collection.FindOne(ctx, bson.E{Key: "chat_id", Value: chatID})
result := collection.FindOne(ctx, bson.M{"chat_id": chatID})
if result.Err() == mongo.ErrNoDocuments {
if _, err := collection.InsertOne(ctx, &chatDTO{ChatID: chatID}); err != nil {
return err
@ -56,7 +56,7 @@ func AddUserInChat(chatID int64, username string) error {
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
_, err = collection.UpdateOne(
ctx,
bson.E{Key: "chat_id", Value: chatID},
bson.M{"chat_id": chatID},
bson.M{"addToSet": bson.M{"users": username}},
)
return err

View File

@ -89,7 +89,7 @@ func run() {
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
switch command {
case commands.Start:
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здравствуйте, я Волтер (v1.0.2), ваш дворецкий (%d).", chatID)))
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здравствуйте, я Волтер (v1.1.0), ваш дворецкий (%d).", chatID)))
_ = db.AddChat(chatID)
case commands.Help:
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Позвать всех"))