mirror of https://github.com/Bunsly/JobSpy
cleaned some code
parent
8195c2c884
commit
d417a3d32d
|
@ -44,12 +44,7 @@ class TelegramBot:
|
||||||
logger.error(f"Failed to send job to Telegram: {job.id}")
|
logger.error(f"Failed to send job to Telegram: {job.id}")
|
||||||
logger.error(f"Error: {e}")
|
logger.error(f"Error: {e}")
|
||||||
|
|
||||||
async def send_test_message(self):
|
def get_reply_markup(self):
|
||||||
"""
|
|
||||||
Send Test Message to Telegram chat.
|
|
||||||
"""
|
|
||||||
message = "Test Test Testing"
|
|
||||||
try:
|
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(ReactionEmoji.FIRE, callback_data=ReactionEmoji.FIRE.name),
|
InlineKeyboardButton(ReactionEmoji.FIRE, callback_data=ReactionEmoji.FIRE.name),
|
||||||
|
@ -57,7 +52,15 @@ class TelegramBot:
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
return InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
|
async def send_test_message(self):
|
||||||
|
"""
|
||||||
|
Send Test Message to Telegram chat.
|
||||||
|
"""
|
||||||
|
message = "Test Test Testing"
|
||||||
|
try:
|
||||||
|
reply_markup = self.get_reply_markup()
|
||||||
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
|
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
|
||||||
logger.info("Sent test message to Telegram")
|
logger.info("Sent test message to Telegram")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -4,6 +4,7 @@ from telegram.ext import (
|
||||||
ContextTypes,
|
ContextTypes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from src.jobspy import create_logger
|
||||||
from src.telegram_bot import TelegramBot
|
from src.telegram_bot import TelegramBot
|
||||||
from src.telegram_handler.button_callback.button_callback_context import ButtonCallBackContext
|
from src.telegram_handler.button_callback.button_callback_context import ButtonCallBackContext
|
||||||
from src.telegram_handler.button_callback.button_fire_strategy import FireStrategy
|
from src.telegram_handler.button_callback.button_fire_strategy import FireStrategy
|
||||||
|
@ -13,25 +14,20 @@ from src.telegram_handler.button_callback.button_poo_strategy import PooStrategy
|
||||||
class TelegramCallHandler:
|
class TelegramCallHandler:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.telegram_bot = TelegramBot()
|
self.telegram_bot = TelegramBot()
|
||||||
|
self.logger = create_logger("TelegramCallHandler")
|
||||||
|
|
||||||
async def button_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def button_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
"""Parses the CallbackQuery and updates the message text."""
|
"""Parses the CallbackQuery and updates the message."""
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
|
|
||||||
# CallbackQueries need to be answered, even if no notification to the user is needed
|
|
||||||
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
|
|
||||||
await query.answer()
|
await query.answer()
|
||||||
button_context = ButtonCallBackContext()
|
button_context = ButtonCallBackContext()
|
||||||
if ReactionEmoji.FIRE.name == query.data:
|
|
||||||
strategy = FireStrategy(query.message)
|
|
||||||
# elif ReactionEmoji.PILE_OF_POO.name == query.data:
|
|
||||||
# strategy = PooStrategy(query.message)
|
|
||||||
else:
|
|
||||||
raise ValueError("Invalid enum value")
|
|
||||||
|
|
||||||
if not strategy:
|
if ReactionEmoji.FIRE.name == query.data:
|
||||||
|
button_context.strategy = FireStrategy(query.message)
|
||||||
|
elif ReactionEmoji.PILE_OF_POO.name == query.data:
|
||||||
|
button_context.strategy = PooStrategy(query.message)
|
||||||
|
else:
|
||||||
|
self.logger.error("Invalid enum value")
|
||||||
return
|
return
|
||||||
|
|
||||||
button_context.strategy = strategy
|
|
||||||
await button_context.run()
|
await button_context.run()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue