mirror of https://github.com/Bunsly/JobSpy
code arrangement
parent
f0f6cf044f
commit
afa18099bb
|
@ -1,17 +1,25 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from telegram import MaybeInaccessibleMessage
|
||||||
|
from telegram.constants import ReactionEmoji
|
||||||
|
|
||||||
|
from jobspy import create_logger
|
||||||
from telegram_bot import TelegramBot
|
from telegram_bot import TelegramBot
|
||||||
|
from telegram_handler.button_callback.button_fire_strategy import FireStrategy
|
||||||
|
from telegram_handler.button_callback.button_poo_strategy import PooStrategy
|
||||||
from telegram_handler.button_callback.button_strategy import ButtonStrategy
|
from telegram_handler.button_callback.button_strategy import ButtonStrategy
|
||||||
|
|
||||||
|
|
||||||
class ButtonCallBackContext():
|
class ButtonCallBackContext:
|
||||||
"""
|
"""
|
||||||
The Context defines the interface
|
The Context defines the interface
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, strategy: ButtonStrategy = None) -> None:
|
def __init__(self, data: str, message: MaybeInaccessibleMessage) -> None:
|
||||||
self.telegram_bot = TelegramBot()
|
self._logger = create_logger("Button CallBack Context")
|
||||||
self._strategy = strategy
|
self._message = message
|
||||||
|
self._data = data
|
||||||
|
self._telegram_bot = TelegramBot()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def strategy(self) -> ButtonStrategy:
|
def strategy(self) -> ButtonStrategy:
|
||||||
|
@ -32,14 +40,14 @@ class ButtonCallBackContext():
|
||||||
self._strategy = strategy
|
self._strategy = strategy
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
# extract job id from message
|
self._logger.info("Starting")
|
||||||
# find the position in DB
|
if ReactionEmoji.FIRE.name == self._data:
|
||||||
# set applied to True
|
self.strategy = FireStrategy(self._message)
|
||||||
# save
|
elif ReactionEmoji.PILE_OF_POO.name == self._data:
|
||||||
# set reaction to message
|
self.strategy = PooStrategy(self._message)
|
||||||
|
else:
|
||||||
|
self._logger.error("Invalid enum value")
|
||||||
|
return
|
||||||
|
|
||||||
print("Context: Starting")
|
|
||||||
await self._strategy.execute()
|
await self._strategy.execute()
|
||||||
print("Context: Finished")
|
self._logger.info("Finished")
|
||||||
|
|
||||||
# ...
|
|
||||||
|
|
|
@ -20,14 +20,6 @@ class TelegramCallHandler:
|
||||||
"""Parses the CallbackQuery and updates the message."""
|
"""Parses the CallbackQuery and updates the message."""
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
await query.answer()
|
await query.answer()
|
||||||
button_context = ButtonCallBackContext()
|
button_context = ButtonCallBackContext(query.data,query.message)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
await button_context.run()
|
await button_context.run()
|
||||||
|
|
Loading…
Reference in New Issue