Skip to content

Commit

Permalink
Merge pull request #44 from Picred/new-welcomes-v2
Browse files Browse the repository at this point in the history
Nuovi messaggi di benvenuto
  • Loading branch information
domenicoblanco authored Oct 25, 2023
2 parents eab2a39 + c926392 commit bad59da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 19 additions & 2 deletions src/welcome.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bad59da

Please sign in to comment.