Skip to content

Commit

Permalink
fix: condense two responses into one for less spam
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuhanming committed May 5, 2021
1 parent 7981e36 commit 288d35b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/chat_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def generate_user_list(chat: dict, users: list[dict]) -> str:
users.sort(key=lambda x: str(x["full_name"]))
for user in users:
message += "{}\n".format(user["full_name"])
message += "\nNumber of members: {}\n".format(len(users))

message += "\nNumber of members: {}".format(len(users))

message += (
"\nIf you're not in the list, please add yourself with the /add_me command."
Expand Down Expand Up @@ -157,19 +157,21 @@ def add_me(update: Update, _: CallbackContext) -> None:
full_name=user.full_name, telegram_id=str(user.id)
)

message = ""

if SERVICES.belong_service.is_user_inside_chat(
user_id=user_dict["id"], chat_id=chat_dict["id"]
):
update.message.reply_text("You're already inside this chat group!")
message = "You're already inside this chat group!\n\n"
else:
SERVICES.belong_service.add_user_to_chat_if_not_inside(
user_id=user_dict["id"], chat_id=chat_dict["id"]
)
SERVICES.logger.info(
"Added {} to chat {}".format(user_dict["full_name"], chat_dict["title"])
)
update.message.reply_text("Added you to this chat group!")
message = "Added you to this chat group!\n\n"

user_dicts = SERVICES.belong_service.get_users_in_chat(chat_id=chat_dict["id"])
message = generate_user_list(chat_dict, user_dicts)
message += generate_user_list(chat_dict, user_dicts)
update.message.reply_html(message)

0 comments on commit 288d35b

Please sign in to comment.