From cb034901d311d75de33f2cc37379d4f546e2395d Mon Sep 17 00:00:00 2001 From: ennucore Date: Wed, 22 Jun 2022 08:50:15 +0300 Subject: [PATCH] Templates, requesting meetings --- README.md | 1 - community.py | 2 +- templates.txt | 30 ++++++++++++++++++++++-------- views.py | 9 ++++++--- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8b1d1c9..2fbff4e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,5 @@ Random meetings for chats, kind of like RandomCoffee. 4. The bot sends the matches and links to their Telegram accounts TODO: -- A button to request a meeting - Add commands like info - In templates replace "this week" with "soon" diff --git a/community.py b/community.py index 1414c97..6e14171 100644 --- a/community.py +++ b/community.py @@ -74,7 +74,7 @@ class Community: # Check if there isn't a meeting in archived_meetings with its scheduling date today or yesterday return not any( r in [date.today(), date.today() - timedelta(days=1)] and user_id in [l, m] - for l, m, r in self.scheduled_meetings + self.archived_meetings) + for l, m, r in self.scheduled_meetings + self.archived_meetings) and user_id not in self.pool def add_member(self, user_id: int, bot: Bot) -> bool: chat_member_info: ChatMember = bot.get_chat_member(self.chat_id, user_id) diff --git a/templates.txt b/templates.txt index b18bc9d..ceda139 100644 --- a/templates.txt +++ b/templates.txt @@ -1,14 +1,16 @@ -||<| start |>|| +||<| info |>|| //| ru |// -Здравствуйте, {{ tg_user.first_name }}! -//| en |// -Hello, {{ tg_user.first_name }}! +{% if start %}Привет, {{ tg_user.first_name }}!{% endif %} +Этот бота создан для неформальных 1-1 встреч с людьми в чатах. {# +#}Бот назначает людям партнеров (как правило, раз в неделю), после чего они встречаются очно или онлайн и знакомятся. +Приятного общения! -||<| help |>|| //| en |// -/help - Help -//| ru |// -/help - помощь +{% if start %}Hello, {{ tg_user.first_name }}!{% endif %} +This bot is created for non-formal 1-1 meetings with people in chat. {# +#}The bot assigns people partners (usually once a week), after which they meet online or in person and get to know each other. +Have a nice chat! +{# todo: add commands and information on adding to a chat #} ||<| admin_stats |>|| //| |// @@ -63,6 +65,18 @@ What community do you want to have a meeting in? >>| {{ name }} :-: request_meeting_{{ id }} |<< {% endfor %} +||<| request_meeting_success |>|| +//| en |// +You have successfully requested a meeting in the community {{ community.name }}. You'll get your match soon. +//| ru |// +Вы успешно запросили встречу в сообществе {{ community.name }}. Вам придет сообщение с партнером в ближайшее время. + +||<| request_meeting_failure |>|| +//| en |// +You have already requested a meeting in the community {{ community.name }} recently. You'll be able to request another meeting in a few days. +//| ru |// +Вы уже запрашивали встречу в сообществе {{ community.name }} недавно. Вы сможете запросить еще одну встречу через несколько дней. + ||<| canceled |>|| //| en |// Canceled diff --git a/views.py b/views.py index 712c1b5..b94df61 100644 --- a/views.py +++ b/views.py @@ -1,3 +1,5 @@ +from datetime import date + from bot import Bot from community import Community @@ -17,11 +19,11 @@ def views(bot: Bot): bot.reply_with_template(msg, 'community_added', community=community, already_member=False) else: bot.reply_with_template(msg, 'err_not_a_member', community=community) - bot.reply_with_template(msg, 'start') + bot.reply_with_template(msg, 'info', start=True) @bot.handle_commands(['/help', 'ℹ️ About', 'ℹ️ О боте']) def handle_help(msg, _user, _args): - bot.reply_with_template(msg, 'help') + bot.reply_with_template(msg, 'info', start=False) @bot.handle_commands(['/request', '📝 Request a meeting', '📝 Запросить встречу']) def request_meeting(msg, user, _args): @@ -32,7 +34,8 @@ def views(bot: Bot): def request_meeting_callback(msg, user, args): community = Community.by_id(int(args), bot) if community.can_user_request_a_meeting(user.user_id): - # todo: request the meeting and write the template + community.polled[user.user_id] = date.today() + community.pool.append(user.user_id) bot.reply_with_template(msg, 'request_meeting_success', community=community) else: bot.reply_with_template(msg, 'request_meeting_failure', community=community)