1
0
Fork 0

Separate notification for support module unload

This commit is contained in:
Ethanell 2019-12-28 02:41:51 +01:00
parent 949df1e102
commit e57d0d8617
4 changed files with 55 additions and 30 deletions

View file

@ -19,36 +19,13 @@ def have_await_cmd(msg: types.Message):
async def notif():
with Session as session:
for u in session.query(User).all():
nt = None
kf = None
tm = None
try:
nt = u.get_notif()
kf = u.get_kfet()
tm = u.get_tomuss()
except Exception as e:
logger.error(e)
else:
if nt:
await bot.send_message(u.id, lang(u, "notif_event")+str(nt), parse_mode=ParseMode.MARKDOWN)
if kf:
if kf == 1:
kf = lang(u, "kfet")
elif kf == 2:
kf = lang(u, "kfet_prb")
else:
kf = lang(u, "kfet_err")
await bot.send_message(u.id, kf, parse_mode=ParseMode.MARKDOWN)
if tm:
for i in tm:
msg = markdown.text(
markdown.bold(i.title),
markdown.code(i.summary.replace("<br>", "\n").replace("<b>", "").replace("</b>", "")),
sep="\n"
)
await bot.send_message(u.id, msg, parse_mode=ParseMode.MARKDOWN)
u.tomuss_last = str(i)
session.commit()
async def notif_cmd(message: types.Message):

View file

@ -5,7 +5,7 @@ from aiogram import types
from aiogram.types import ParseMode
from aiogram.utils import markdown
from TelegramEDT import dp, key, logger, Session, check_id, modules
from TelegramEDT import dp, key, logger, Session, check_id, modules, bot
from TelegramEDT.base import User, KFET_URL
from TelegramEDT.lang import lang
@ -78,6 +78,24 @@ async def await_cmd(message: types.message):
await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=key)
async def notif():
with Session as session:
for u in session.query(User).all():
try:
kf = u.get_kfet()
except Exception as e:
logger.error(e)
else:
if kf is not None:
if kf == 1:
kf = lang(u, "kfet")
elif kf == 2:
kf = lang(u, "kfet_prb")
else:
kf = lang(u, "kfet_err")
await bot.send_message(u.id, kf, parse_mode=ParseMode.MARKDOWN)
def load():
logger.info(f"Load {module_name} module")
dp.register_message_handler(kfet, lambda msg: msg.text.lower() == "kfet")

View file

@ -1,9 +1,17 @@
from asyncio import sleep
from TelegramEDT.edt_notif import notif
from TelegramEDT import modules
from TelegramEDT.edt_notif import notif as edt_notif
from TelegramEDT.kfet import notif as kfet_notif
from TelegramEDT.tomuss import notif as tomuss_notif
async def main():
while True:
await notif()
if "edt_notif" in modules:
await edt_notif()
if "kfet" in modules:
await kfet_notif()
if "tomuss" in modules:
await tomuss_notif()
await sleep(30)

View file

@ -1,8 +1,9 @@
from aiogram import types
from aiogram.types import ParseMode
from aiogram.utils import markdown
from feedparser import parse
from TelegramEDT import dp, key, logger, Session, check_id, modules
from TelegramEDT import dp, key, logger, Session, check_id, modules, bot
from TelegramEDT.base import User
from TelegramEDT.lang import lang
@ -39,6 +40,7 @@ async def await_cmd(message: types.message):
msg = lang(user, "settomuss_error")
else:
user.tomuss_rss = message.text
user.tomuss_last = str()
msg = lang(user, "settomuss")
user.await_cmd = str()
session.commit()
@ -46,6 +48,26 @@ async def await_cmd(message: types.message):
await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=key)
async def notif():
with Session as session:
for u in session.query(User).all():
try:
tm = u.get_tomuss()
except Exception as e:
logger.error(e)
else:
if tm:
for i in tm:
msg = markdown.text(
markdown.bold(i.title),
markdown.code(i.summary.replace("<br>", "\n").replace("<b>", "").replace("</b>", "")),
sep="\n"
)
await bot.send_message(u.id, msg, parse_mode=ParseMode.MARKDOWN)
u.tomuss_last = str(i)
session.commit()
def load():
logger.info(f"Load {module_name} module")
dp.register_message_handler(settomuss, lambda msg: msg.text.lower() == "settomuss")