From 8e5908e2287b26190b0e4078f3413b321be49321 Mon Sep 17 00:00:00 2001 From: ennucore Date: Wed, 22 Jun 2022 12:32:30 +0300 Subject: [PATCH] Checking --- community.py | 4 +--- templates.txt | 12 ++++++++++++ user.py | 2 +- views.py | 11 ++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/community.py b/community.py index 6e14171..4b16c26 100644 --- a/community.py +++ b/community.py @@ -93,9 +93,7 @@ class Community: def add_answer(self, user_id: typing.Union[int, bool], answer: bool, bot: Bot): answer = bool(answer) - if user_id not in self.users_to_poll(): - return - if user_id in self.pool: + while user_id in self.pool: self.pool.remove(user_id) self.pool += [user_id] * answer self.default_answers[user_id] = bool(answer) diff --git a/templates.txt b/templates.txt index c538389..3079a74 100644 --- a/templates.txt +++ b/templates.txt @@ -87,3 +87,15 @@ Canceled //| ru |// Отменено +||<| err_not_private |>|| +//| en |// +This command can only be used in private chats. +//| ru |// +Эта команда может быть использована только в личных чатах. + +||<| err_not_community |>|| +//| en |// +This command can only be used in groups. +//| ru |// +Эта команда может быть использована только в группах. + diff --git a/user.py b/user.py index d0ca572..054f147 100644 --- a/user.py +++ b/user.py @@ -2,10 +2,10 @@ from __future__ import annotations from dataclasses import dataclass, field, asdict import typing import time +from community import Community if typing.TYPE_CHECKING: from bot import Bot - from community import Community @dataclass diff --git a/views.py b/views.py index 87cf511..fcb5152 100644 --- a/views.py +++ b/views.py @@ -28,14 +28,19 @@ def views(bot: Bot): @bot.handle_commands(['/request', '📝 Request a meeting', '📝 Запросить встречу']) def request_meeting(msg, user, _args): - # todo: don't allow this command in chats - comm_ids_and_names = [(community.chat_id, community.name) for community in user.communities] + if msg.chat.type != 'private': + bot.reply_with_template(msg, 'err_not_private') + return + comm_ids_and_names = [(community.chat_id, community.name) for community in user.get_communities(bot)] bot.reply_with_template(msg, 'request_meeting', comm_list=comm_ids_and_names) @bot.handle_commands(['/join']) def join_community(msg, user, args): + # check if it really is a community + if msg.chat.type == 'private': + bot.reply_with_template(msg, 'err_not_community') + return # send community link - # todo: check if it really is a community community = Community.by_id(msg.chat.id, bot) bot.reply_with_template(msg, 'welcome', community=community, join=True)