Skip to content

Commit

Permalink
Merge pull request #70 from LucaBernstein/admin-notif-also-to-sender
Browse files Browse the repository at this point in the history
Also send admin notifications to sender
  • Loading branch information
LucaBernstein authored Dec 22, 2021
2 parents 0662ca1 + e694566 commit 4fc9944
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (bc *BotController) commandAdminNofify(m *tb.Message) {
target = command[1]
}

receivers := bc.Repo.IndividualsWithNotifications(m.Chat.ID, target)
receivers := bc.Repo.IndividualsWithNotifications(target)
if len(receivers) == 0 {
_, err := bc.Bot.Send(m.Sender, "No receivers found to send notification to (you being excluded).")
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions db/crud/auth_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,20 @@ func (r *Repo) UserIsAdmin(m *tb.Message) bool {
return isAdmin
}

func (r *Repo) IndividualsWithNotifications(myChatId int64, chatId string) (recipients []string) {
func (r *Repo) IndividualsWithNotifications(chatId string) (recipients []string) {
query := `
SELECT "tgChatId"
FROM "auth::user"
WHERE "tgUserId" = "tgChatId" -- is a private chat
AND "tgChatId" != $1
`
params := []interface{}{myChatId}
params := []interface{}{}

if chatId != "" {
i, err := strconv.ParseInt(chatId, 10, 64)
if err != nil {
LogDbf(r, helpers.ERROR, nil, "Error while parsing chatId to int64: %s", err.Error())
}
query += `AND "tgChatId" = $2`
query += `AND "tgChatId" = $1`
params = append(params, i)
}
rows, err := r.db.Query(query, params...)
Expand Down

0 comments on commit 4fc9944

Please sign in to comment.