Browse Source

Templates, requesting meetings

master
Lev 2 years ago
parent
commit
cb034901d3
  1. 1
      README.md
  2. 2
      community.py
  3. 30
      templates.txt
  4. 9
      views.py

1
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 4. The bot sends the matches and links to their Telegram accounts
TODO: TODO:
- A button to request a meeting
- Add commands like info - Add commands like info
- In templates replace "this week" with "soon" - In templates replace "this week" with "soon"

2
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 # Check if there isn't a meeting in archived_meetings with its scheduling date today or yesterday
return not any( return not any(
r in [date.today(), date.today() - timedelta(days=1)] and user_id in [l, m] 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: def add_member(self, user_id: int, bot: Bot) -> bool:
chat_member_info: ChatMember = bot.get_chat_member(self.chat_id, user_id) chat_member_info: ChatMember = bot.get_chat_member(self.chat_id, user_id)

30
templates.txt

@ -1,14 +1,16 @@
||<| start |>|| ||<| info |>||
//| ru |// //| ru |//
Здравствуйте, <b>{{ tg_user.first_name }}</b>! {% if start %}Привет, <b>{{ tg_user.first_name }}</b>!{% endif %}
//| en |// Этот бота создан для неформальных 1-1 встреч с людьми в чатах. {#
Hello, <b>{{ tg_user.first_name }}</b>! #}Бот назначает людям партнеров (как правило, раз в неделю), после чего они встречаются очно или онлайн и знакомятся.
Приятного общения!
||<| help |>||
//| en |// //| en |//
/help - Help {% if start %}Hello, <b>{{ tg_user.first_name }}</b>!{% endif %}
//| ru |// This bot is created for non-formal 1-1 meetings with people in chat. {#
/help - помощь #}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 |>|| ||<| admin_stats |>||
//| |// //| |//
@ -63,6 +65,18 @@ What community do you want to have a meeting in?
>>| {{ name }} :-: request_meeting_{{ id }} |<< >>| {{ name }} :-: request_meeting_{{ id }} |<<
{% endfor %} {% endfor %}
||<| request_meeting_success |>||
//| en |//
You have successfully requested a meeting in the community <b>{{ community.name }}</b>. You'll get your match soon.
//| ru |//
Вы успешно запросили встречу в сообществе <b>{{ community.name }}</b>. Вам придет сообщение с партнером в ближайшее время.
||<| request_meeting_failure |>||
//| en |//
You have already requested a meeting in the community <b>{{ community.name }}</b> recently. You'll be able to request another meeting in a few days.
//| ru |//
Вы уже запрашивали встречу в сообществе <b>{{ community.name }}</b> недавно. Вы сможете запросить еще одну встречу через несколько дней.
||<| canceled |>|| ||<| canceled |>||
//| en |// //| en |//
Canceled Canceled

9
views.py

@ -1,3 +1,5 @@
from datetime import date
from bot import Bot from bot import Bot
from community import Community from community import Community
@ -17,11 +19,11 @@ def views(bot: Bot):
bot.reply_with_template(msg, 'community_added', community=community, already_member=False) bot.reply_with_template(msg, 'community_added', community=community, already_member=False)
else: else:
bot.reply_with_template(msg, 'err_not_a_member', community=community) 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', ' О боте']) @bot.handle_commands(['/help', ' About', ' О боте'])
def handle_help(msg, _user, _args): 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', '📝 Запросить встречу']) @bot.handle_commands(['/request', '📝 Request a meeting', '📝 Запросить встречу'])
def request_meeting(msg, user, _args): def request_meeting(msg, user, _args):
@ -32,7 +34,8 @@ def views(bot: Bot):
def request_meeting_callback(msg, user, args): def request_meeting_callback(msg, user, args):
community = Community.by_id(int(args), bot) community = Community.by_id(int(args), bot)
if community.can_user_request_a_meeting(user.user_id): 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) bot.reply_with_template(msg, 'request_meeting_success', community=community)
else: else:
bot.reply_with_template(msg, 'request_meeting_failure', community=community) bot.reply_with_template(msg, 'request_meeting_failure', community=community)

Loading…
Cancel
Save