cleaned some code

pull/231/head
Yariv Menachem 2024-12-29 19:03:23 +02:00
parent d417a3d32d
commit bdb70ff4de
2 changed files with 22 additions and 30 deletions

View File

@ -18,32 +18,6 @@ class TelegramBot:
self.chatId = os.getenv("TELEGRAM_CHAT_ID")
self.bot = Bot(token=self._api_token)
async def send_job(self, job: JobPost):
"""
Send JobPost details to Telegram chat.
"""
message = f"Job ID: {job.id}\n" \
f"Job Title: {job.title}\n" \
f"Company: {job.company_name}\n" \
f"Location: {job.location.display_location()}\n" \
f"Link: {job.job_url}\n"
keyboard = [
[
InlineKeyboardButton(ReactionEmoji.FIRE, callback_data=ReactionEmoji.FIRE.name),
InlineKeyboardButton(ReactionEmoji.PILE_OF_POO, callback_data=ReactionEmoji.PILE_OF_POO.name)
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
try:
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
logger.info(f"Sent job to Telegram: {job.id}")
except Exception as e:
logger.error(f"Failed to send job to Telegram: {job.id}")
logger.error(f"Error: {e}")
def get_reply_markup(self):
keyboard = [
[
@ -54,6 +28,24 @@ class TelegramBot:
return InlineKeyboardMarkup(keyboard)
async def send_job(self, job: JobPost):
"""
Send JobPost details to Telegram chat.
"""
message = f"Job ID: {job.id}\n" \
f"Job Title: {job.title}\n" \
f"Company: {job.company_name}\n" \
f"Location: {job.location.display_location()}\n" \
f"Link: {job.job_url}\n"
reply_markup = self.get_reply_markup()
try:
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
logger.info(f"Sent job to Telegram: {job.id}")
except Exception as e:
logger.error(f"Failed to send job to Telegram: {job.id}")
logger.error(f"Error: {e}")
async def send_test_message(self):
"""
Send Test Message to Telegram chat.

View File

@ -6,17 +6,17 @@ from src.telegram_handler.button_callback.button_strategy import ButtonStrategy
class FireStrategy(ButtonStrategy):
def __init__(self, data: MaybeInaccessibleMessage) -> None:
def __init__(self, message: MaybeInaccessibleMessage) -> None:
"""
Usually, the Context accepts a strategy through the constructor, but
also provides a setter to change it at runtime.
"""
self.data = data
self.message = message
self._emoji = ReactionEmoji.FIRE
self.telegram_bot = TelegramBot()
async def execute(self):
telegram_bot = TelegramBot()
await telegram_bot.set_message_reaction(self.data.message_id, self._emoji)
await self.telegram_bot.set_message_reaction(self.message.message_id, self._emoji)
# find the position in DB
# set applied to True
# save