Telegram module #10

Merged
skobkin merged 19 commits from feature_telegram into master 2022-05-30 20:54:27 +00:00
Showing only changes of commit f9ffdac38a - Show all commits

View file

@ -1,3 +1,5 @@
import time
from telebot import TeleBot
from telebot.handler_backends import BaseMiddleware
from telebot.types import Message
@ -88,13 +90,22 @@ class CommandProcessor:
class Notifier:
"""Sends notifications to users about new RSS feed items."""
BATCH_LIMIT: int = 30
sent_counter: int = 0
def __init__(self, token: str):
self.bot: TeleBot = TeleBot(token)
def send_updates(self, chat_id: int, updates: list[FeedItem]):
def send_updates(self, chat_ids: list[int], updates: list[FeedItem]):
"""Send notification about new items to the user"""
for update in updates:
self.__send_update(chat_id, update)
for chat_id in chat_ids:
for update in updates:
self.__send_update(chat_id, update)
self.sent_counter += 1
if self.sent_counter >= self.BATCH_LIMIT:
# TODO: probably implement better later
time.sleep(1)
def __send_update(self, telegram_id: int, update: FeedItem):
self.bot.send_message(