From c2b5def149b87a8925866d339e136b4c92107ee0 Mon Sep 17 00:00:00 2001 From: Picred Date: Sat, 21 Oct 2023 09:04:07 +0200 Subject: [PATCH] feat: welcome message enhancement --- data/welcome.json | 9 ++++++++- module/commands/welcome.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/data/welcome.json b/data/welcome.json index 35a6bae..cf8a575 100644 --- a/data/welcome.json +++ b/data/welcome.json @@ -1,4 +1,11 @@ { "it": ["Benvenuto USER nel nostro gruppo ^-^","Ciao USER!","Salve USER!"], - "en": ["Welcome USER to our group ^-^","Hello USER!","Howdy USER!"] + "en": ["Welcome USER to our group ^-^","Hello USER!","Howdy USER!"], + "readme": "https://t.me/c/1095167198/67194", + "utils": [ + "Se hai idee o suggerimenti, condividili con noi. Siamo aperti a nuove prospettive!", + "Non esitare a fare domande se hai bisogno di aiuto.", + "Speriamo che ti possa sentire come a casa tua.", + "Ricorda di rispettare le opinioni degli altri membri, anche se non sempre concordi. La diversità ci arricchisce." + ] } \ No newline at end of file diff --git a/module/commands/welcome.py b/module/commands/welcome.py index 3d50da3..4e80358 100644 --- a/module/commands/welcome.py +++ b/module/commands/welcome.py @@ -23,6 +23,14 @@ def generate_welcome(new_member: User) -> str: def send_welcome(update: Update, _: CallbackContext) -> None: - for new_member in update['message']['new_chat_members']: - if not new_member['is_bot']: - update.message.reply_text(f'{generate_welcome(new_member)}') + if update.message.new_chat_members: + for new_member in update.message.new_chat_members: + if not new_member.is_bot: + handle_welcome(update, new_member) + + +def handle_welcome(update: Update, new_member: User) -> None: + welcome_msg = f'{generate_welcome(new_member)}\n' + \ + f"- Dai un'occhiata al [README]({welcome['readme']})\n" + \ + f"- {welcome['utils'][randrange(0, len(welcome['utils']))]}" + update.message.reply_markdown(welcome_msg, disable_web_page_preview=True)