From d9f1de323a47d35b67d5b06d72c692a2a41c970e Mon Sep 17 00:00:00 2001 From: Picred Date: Wed, 25 Oct 2023 01:00:40 +0200 Subject: [PATCH 1/2] feat: new welcome messages --- src/main.py | 11 +++++++++-- src/welcome.json | 21 +++++++++++++++++++-- tests/main_test.py | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 2288e6e..1b68b1a 100644 --- a/src/main.py +++ b/src/main.py @@ -21,13 +21,20 @@ def generate_welcome(new_member: User) -> str: with open("src/welcome.json", "r") as f: wlc_mess_list = load(f)[lan_code] - return wlc_mess_list[randrange(0, len(wlc_mess_list))].replace("USER", new_member_username) + return wlc_mess_list['sentences'][randrange(0, len(wlc_mess_list))].replace("USER", new_member_username) async def send_welcome(update: Update, _: CallbackContext) -> None: for new_member in update['message']['new_chat_members']: if not new_member['is_bot']: - await update.message.reply_text(f'{generate_welcome(new_member)}') + lan_code = new_member["language_code"] or "it" + with open("src/welcome.json", "r") as f: + welcome_file = load(f) + + welcome_msg = f'{generate_welcome(new_member)}\n'\ + f'- README: 👉 {welcome_file["readme"]}\n'\ + f'- {welcome_file[lan_code]["utils"][randrange(0, len(welcome_file[lan_code]["utils"]))]}' + await update.message.reply_text(f'{welcome_msg}') def main() -> None: token = getenv("QDBotToken") diff --git a/src/welcome.json b/src/welcome.json index 35a6bae..4154f38 100644 --- a/src/welcome.json +++ b/src/welcome.json @@ -1,4 +1,21 @@ { - "it": ["Benvenuto USER nel nostro gruppo ^-^","Ciao USER!","Salve USER!"], - "en": ["Welcome USER to our group ^-^","Hello USER!","Howdy USER!"] + "it": { + "sentences" : ["Benvenuto USER nel nostro gruppo ^-^","Ciao USER!","Salve USER!"], + "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" + ] + }, + "en": { + "sentences" : ["Welcome USER to our group ^-^","Hello USER!","Howdy USER!"], + "utils" : [ + "If you have ideas or suggestions, please share them with us. We are open to new perspectives!", + "Don't hesitate to ask questions if you need help", + "We hope you can feel at home", + "Remember to respect other members' opinions, even if you don't always agree. Diversity enriches us." + ] + }, + "readme" : "https://t.me/c/1095167198/67194" } \ No newline at end of file diff --git a/tests/main_test.py b/tests/main_test.py index 9b602fd..71b01de 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -9,7 +9,7 @@ def get_wel(lan_code: str) -> str: with open("src/welcome.json", "r") as f: - wlc_mess_list = main.load(f)[lan_code] + wlc_mess_list = main.load(f)[lan_code]["sentences"] #first element of the list return wlc_mess_list[0].replace("USER","@user") From c92639252372c3d5e6c7d7e8cda5fce2339afd04 Mon Sep 17 00:00:00 2001 From: Picred Date: Wed, 25 Oct 2023 01:03:43 +0200 Subject: [PATCH 2/2] refactor: changed annotation --- tests/main_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/main_test.py b/tests/main_test.py index 71b01de..d841df2 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -9,7 +9,7 @@ def get_wel(lan_code: str) -> str: with open("src/welcome.json", "r") as f: - wlc_mess_list = main.load(f)[lan_code]["sentences"] + wlc_mess_list = main.load(f)[lan_code]['sentences'] #first element of the list return wlc_mess_list[0].replace("USER","@user")