add AddUserInChat
This commit is contained in:
parent
c4a39056d8
commit
9d5b5c2a2f
4
db/db.go
4
db/db.go
|
@ -30,7 +30,7 @@ func AddChat(chatID int64) error {
|
||||||
|
|
||||||
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
|
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 result.Err() == mongo.ErrNoDocuments {
|
||||||
if _, err := collection.InsertOne(ctx, &chatDTO{ChatID: chatID}); err != nil {
|
if _, err := collection.InsertOne(ctx, &chatDTO{ChatID: chatID}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -56,7 +56,7 @@ func AddUserInChat(chatID int64, username string) error {
|
||||||
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
|
collection := client.Database(cfg.DBName).Collection(cfg.ChatsCollectionName)
|
||||||
_, err = collection.UpdateOne(
|
_, err = collection.UpdateOne(
|
||||||
ctx,
|
ctx,
|
||||||
bson.E{Key: "chat_id", Value: chatID},
|
bson.M{"chat_id": chatID},
|
||||||
bson.M{"addToSet": bson.M{"users": username}},
|
bson.M{"addToSet": bson.M{"users": username}},
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
|
|
2
main.go
2
main.go
|
@ -89,7 +89,7 @@ func run() {
|
||||||
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
|
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
|
||||||
switch command {
|
switch command {
|
||||||
case commands.Start:
|
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)
|
_ = db.AddChat(chatID)
|
||||||
case commands.Help:
|
case commands.Help:
|
||||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Позвать всех"))
|
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Позвать всех"))
|
||||||
|
|
Loading…
Reference in New Issue