Browse Source

Fix bug with repeating messages

master
Lev 2 years ago
parent
commit
5246c38cc8
  1. 8
      bot.py
  2. 6
      user.py

8
bot.py

@ -193,10 +193,13 @@ class Bot(telebot.TeleBot):
yield Community.from_dict(community_data)
def poll_user_for_community(self, user: User, community: Community):
try:
def_answer = False # community.default_answers.get(user.user_id, True)
community.polled[user.user_id] = datetime.date.today()
self.send_template(user.user_id, 'poll_user', community=community, answer=def_answer)
community.pool += [user.user_id] * def_answer
community.polled[user.user_id] = datetime.date.today()
except telebot.apihelper.ApiTelegramException:
pass
def poll_users_in_community(self, community: Community):
for user_id in community.users_to_poll():
@ -223,9 +226,12 @@ class Bot(telebot.TeleBot):
def send_meeting_info_in_community(self, community: Community):
for meeting in community.scheduled_meetings:
try:
person_1, person_2 = self.get_chat(meeting[0]), self.get_chat(meeting[1])
self.send_template(meeting[0], 'meeting_info', community=community, meeting=meeting, person=person_2)
self.send_template(meeting[1], 'meeting_info', community=community, meeting=meeting, person=person_1)
except telebot.apihelper.ApiTelegramException:
pass
community.archived_meetings += community.scheduled_meetings
community.scheduled_meetings = []
self.save_community(community)

6
user.py

@ -2,6 +2,9 @@ from __future__ import annotations
from dataclasses import dataclass, field, asdict
import typing
import time
import telebot
from community import Community
from telebot.types import ChatMember
@ -28,7 +31,10 @@ class User:
if chat_id in self.checked_chats:
return False
self.checked_chats.append(chat_id)
try:
chat_member_info: ChatMember = bot.get_chat_member(chat_id, self.user_id)
except telebot.apihelper.ApiTelegramException: # user not found
return False
return chat_member_info.is_member or chat_member_info.status in ['creator', 'administrator', 'admin', 'member']
def dict(self) -> dict:

Loading…
Cancel
Save