Browse Source

Checking

master
Lev 2 years ago
parent
commit
8e5908e228
  1. 4
      community.py
  2. 12
      templates.txt
  3. 2
      user.py
  4. 11
      views.py

4
community.py

@ -93,9 +93,7 @@ class Community:
def add_answer(self, user_id: typing.Union[int, bool], answer: bool, bot: Bot): def add_answer(self, user_id: typing.Union[int, bool], answer: bool, bot: Bot):
answer = bool(answer) answer = bool(answer)
if user_id not in self.users_to_poll(): while user_id in self.pool:
return
if user_id in self.pool:
self.pool.remove(user_id) self.pool.remove(user_id)
self.pool += [user_id] * answer self.pool += [user_id] * answer
self.default_answers[user_id] = bool(answer) self.default_answers[user_id] = bool(answer)

12
templates.txt

@ -87,3 +87,15 @@ Canceled
//| ru |// //| 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 |//
Эта команда может быть использована только в группах.

2
user.py

@ -2,10 +2,10 @@ from __future__ import annotations
from dataclasses import dataclass, field, asdict from dataclasses import dataclass, field, asdict
import typing import typing
import time import time
from community import Community
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from bot import Bot from bot import Bot
from community import Community
@dataclass @dataclass

11
views.py

@ -28,14 +28,19 @@ def views(bot: Bot):
@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):
# todo: don't allow this command in chats if msg.chat.type != 'private':
comm_ids_and_names = [(community.chat_id, community.name) for community in user.communities] 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.reply_with_template(msg, 'request_meeting', comm_list=comm_ids_and_names)
@bot.handle_commands(['/join']) @bot.handle_commands(['/join'])
def join_community(msg, user, args): 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 # send community link
# todo: check if it really is a community
community = Community.by_id(msg.chat.id, bot) community = Community.by_id(msg.chat.id, bot)
bot.reply_with_template(msg, 'welcome', community=community, join=True) bot.reply_with_template(msg, 'welcome', community=community, join=True)

Loading…
Cancel
Save