feat: now check last check
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -1,14 +1,38 @@
|
||||
from app import config_parser
|
||||
import telegram
|
||||
import random
|
||||
from importlib.metadata import version
|
||||
import asyncio
|
||||
|
||||
config = config_parser.ConfigParser().loadConfig()
|
||||
|
||||
|
||||
class telegramBot:
|
||||
bot = None
|
||||
|
||||
async def sendMessage(self, message):
|
||||
self.bot = telegram.Bot(config['telegram']['token'])
|
||||
async with self.bot:
|
||||
await self.bot.sendMessage(chat_id=config['telegram']['chat_id'], text=str(message))
|
||||
ver = version("python-telegram-bot")
|
||||
major = int(ver.split(".")[0])
|
||||
|
||||
|
||||
token = config["telegram"]["token"]
|
||||
chat_id = config["telegram"]["chat_id"]
|
||||
|
||||
# --------------------
|
||||
# PTB v20+ (async)
|
||||
# --------------------
|
||||
if major >= 20:
|
||||
self.bot = telegram.Bot(token)
|
||||
await self.bot.send_message(chat_id=chat_id, text=str(message))
|
||||
return
|
||||
|
||||
# --------------------
|
||||
# PTB v12/v13 (sync)
|
||||
# --------------------
|
||||
else:
|
||||
self.bot = telegram.Bot(token)
|
||||
|
||||
# ejecuta el método sync en un hilo para no romper asyncio.run()
|
||||
loop = asyncio.get_running_loop()
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
lambda: self.bot.send_message(chat_id=chat_id, text=str(message))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user