#7 Moving from package to module.
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Alexey Skobkin 2022-05-30 00:33:36 +03:00
parent dc314b4599
commit 305f1afa3c
4 changed files with 34 additions and 35 deletions

2
bot.py
View file

@ -2,7 +2,7 @@ import logging
import os import os
from dotenv import load_dotenv from dotenv import load_dotenv
from telegram.command_processor import CommandProcessor from telegram import CommandProcessor
load_dotenv() load_dotenv()

View file

@ -32,3 +32,36 @@ class CommandProcessor:
def __delete_feed(self, message: Message): def __delete_feed(self, message: Message):
self.bot.reply_to(message, 'Feed deleted: (stub)') self.bot.reply_to(message, 'Feed deleted: (stub)')
class Notifier:
"""Sends notifications to users about new RSS feed items."""
bot: telebot.TeleBot
def __init__(self, token: str):
self.bot = telebot.TeleBot(token)
def send_updates(self, chat_id: int, updates: list):
"""Send notification about new items to the user"""
for update in updates:
self.__send_update(chat_id, update)
def __send_update(self, chat_id: int, update):
self.bot.send_message(
chat_id=chat_id,
text=self.__format_message(),
parse_mode='MarkdownV2'
)
def __format_message(self) -> str:
update = {
'title': 'Item Title',
'text': 'Short item text here...',
'url': 'https://fediland.github.io/',
}
return (
f"**[{update['title']}]({update['url']})**\n\n"
f"{update['text']}"
)

View file

View file

@ -1,34 +0,0 @@
import telebot
class Notifier:
"""Sends notifications to users about new RSS feed items."""
bot: telebot.TeleBot
def __init__(self, token: str):
self.bot = telebot.TeleBot(token)
def send_updates(self, chat_id: int, updates: list):
"""Send notification about new items to the user"""
for update in updates:
self.__send_update(chat_id, update)
def __send_update(self, chat_id: int, update):
self.bot.send_message(
chat_id=chat_id,
text=self.__format_message(),
parse_mode='MarkdownV2'
)
def __format_message(self) -> str:
update = {
'title': 'Item Title',
'text': 'Short item text here...',
'url': 'https://fediland.github.io/',
}
return (
f"**[{update['title']}]({update['url']})**\n\n"
f"{update['text']}"
)