Skip to content

Commit

Permalink
count number of users, make the process smoother
Browse files Browse the repository at this point in the history
  • Loading branch information
brucewzj99 committed May 3, 2024
1 parent 92e297a commit 54ba8f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bot/telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ def add_backlog_entry(update, context) -> int:
def send_new_feature_message(context, new_feature_message):
users = db.get_all_user_id()
no_of_users = 0
no_of_error_users = 0
errors = []

for user_id in users:
Expand All @@ -1002,11 +1003,11 @@ def send_new_feature_message(context, new_feature_message):
username = chat.username if chat.username else "?"
except Exception:
username = "?"

no_of_error_users += 1
errors.append(f"Username @{username} (ID: {user_id}): {e}")

error_message = "\n".join(errors)
return no_of_users, error_message
return no_of_users, no_of_error_users, error_message


def notify_all(update, context):
Expand All @@ -1027,19 +1028,21 @@ def notify_all(update, context):
f"Preview:\n{new_feature_message}",
reply_markup=reply_markup,
)
else:
update.message.reply_text("You are not authorized to use this command.")


def notify_preview(update, context):
query = update.callback_query
query.answer()
query.edit_message_text(
text=f"Sending message to all in progress...",
reply_markup=InlineKeyboardMarkup([]),
)
if query.data == "confirm_send":
new_feature_message = query.message.text.partition("\n")[2]
no_of_users, error_message = send_new_feature_message(
no_of_users, no_of_error_users, error_message = send_new_feature_message(
context, new_feature_message
)
response = f"Message sent to {no_of_users} users."
response = f"Message sent to {no_of_users} users.\n{no_of_error_users} users failed to receive the message."
if error_message:
response += f"\nErrors:\n{error_message}"
query.edit_message_text(text=response)
Expand Down
4 changes: 4 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Release Notes
## Version 2.3.7 - Date 3 May 2024
### Quick Fix 🛠️
- Add number of error users for /notifyall command

## Version 2.3.6 - Date 3 May 2024
### Quick Fix 🛠️
- Fix parse mode for /notifyall command
Expand Down

0 comments on commit 54ba8f9

Please sign in to comment.