1
0
Fork 0

Upgrade modules

This commit is contained in:
Ethanell 2019-12-28 02:23:30 +01:00
parent fca0204059
commit 949df1e102
10 changed files with 94 additions and 69 deletions

View file

@ -48,6 +48,7 @@ def check_id(user: types.User):
logger.info("Start loading modules")
from TelegramEDT.modules import load_module
for m in ["modules", "basic", "edt", "kfet", "tomuss", "notif", "tools"]:
modules = list()
for m in ["modules", "basic", "edt", "kfet", "tomuss", "edt_notif", "tools"]:
load_module(m)
logger.info("Modules loading finish")

View file

@ -1,11 +1,12 @@
from aiogram import types
from aiogram.types import ParseMode
from TelegramEDT import dp, key, logger, Session, check_id
from TelegramEDT import dp, key, logger, Session, check_id, modules
from TelegramEDT.base import User
from TelegramEDT.lang import lang
logger = logger.getChild("basic")
module_name = "basic"
logger = logger.getChild(module_name)
async def start(message: types.Message):
@ -31,12 +32,14 @@ async def help_cmd(message: types.Message):
def load():
logger.info("Load basic module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(start, commands="start")
dp.register_message_handler(help_cmd, commands="help")
modules.append(module_name)
def unload():
logger.info("Unload basic module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(start)
dp.message_handlers.unregister(help_cmd)
modules.remove(module_name)

View file

@ -11,12 +11,13 @@ from ics.parse import ParseError, string_to_container
from pyzbar.pyzbar import decode
from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema
from TelegramEDT import API_TOKEN, TIMES, bot, dp, key, logger, Session, check_id, posts_cb
from TelegramEDT import API_TOKEN, TIMES, bot, dp, key, logger, Session, check_id, posts_cb, modules
from TelegramEDT.EDTcalendar import Calendar
from TelegramEDT.base import User
from TelegramEDT.lang import lang
logger = logger.getChild("edt")
module_name = "edt"
logger = logger.getChild(module_name)
re_url = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
@ -136,7 +137,7 @@ async def edt_geturl(message: types.Message):
def load():
logger.info("Load edt module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(edt_cmd, lambda msg: msg.text.lower() == "edt")
dp.register_inline_handler(inline_edt)
dp.register_callback_query_handler(edt_query, posts_cb.filter(action=["day", "next", "week", "next week"]))
@ -144,13 +145,15 @@ def load():
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg), content_types=[ContentType.TEXT,
ContentType.PHOTO])
dp.register_message_handler(edt_geturl, commands="getedt")
modules.append(module_name)
def unload():
logger.info("Unload edt module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(edt_cmd)
dp.inline_query_handlers.unregister(inline_edt)
dp.callback_query_handlers.unregister(edt_query)
dp.message_handlers.unregister(edt_await)
dp.message_handlers.unregister(await_cmd)
dp.message_handlers.unregister(edt_geturl)
modules.remove(module_name)

View file

@ -1,14 +1,13 @@
from asyncio import sleep
from aiogram import types
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
from aiogram.utils import markdown
from TelegramEDT import bot, dp, logger, posts_cb, Session, check_id, key
from TelegramEDT import bot, dp, logger, posts_cb, Session, check_id, key, modules
from TelegramEDT.base import User
from TelegramEDT.lang import lang
logger = logger.getChild("notif")
module_name = "edt_notif"
logger = logger.getChild(module_name)
def have_await_cmd(msg: types.Message):
@ -18,7 +17,6 @@ def have_await_cmd(msg: types.Message):
async def notif():
while True:
with Session as session:
for u in session.query(User).all():
nt = None
@ -52,8 +50,6 @@ async def notif():
u.tomuss_last = str(i)
session.commit()
await sleep(60)
async def notif_cmd(message: types.Message):
check_id(message.from_user)
@ -114,14 +110,16 @@ async def await_cmd(message: types.message):
def load():
logger.info("Load notif module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(notif_cmd, lambda msg: msg.text.lower() == "notif")
dp.register_callback_query_handler(notif_query, posts_cb.filter(action=["toggle", "time", "cooldown"]))
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
modules.append(module_name)
def unload():
logger.info("Unload notif module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(notif_cmd)
dp.callback_query_handlers.unregister(notif_query)
dp.message_handlers.unregister(await_cmd)
modules.remove(module_name)

View file

@ -5,11 +5,12 @@ from aiogram import types
from aiogram.types import ParseMode
from aiogram.utils import markdown
from TelegramEDT import dp, key, logger, Session, check_id
from TelegramEDT import dp, key, logger, Session, check_id, modules
from TelegramEDT.base import User, KFET_URL
from TelegramEDT.lang import lang
logger = logger.getChild("kfet")
module_name = "kfet"
logger = logger.getChild(module_name)
def get_now():
@ -78,14 +79,16 @@ async def await_cmd(message: types.message):
def load():
logger.info("Load kfet module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(kfet, lambda msg: msg.text.lower() == "kfet")
dp.register_message_handler(kfet_set, lambda msg: msg.text.lower() == "setkfet")
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
modules.append(module_name)
def unload():
logger.info("Unload kfet module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(kfet)
dp.message_handlers.unregister(kfet_set)
dp.message_handlers.unregister(await_cmd)
modules.remove(module_name)

9
TelegramEDT/loop.py Normal file
View file

@ -0,0 +1,9 @@
from asyncio import sleep
from TelegramEDT.edt_notif import notif
async def main():
while True:
await notif()
await sleep(30)

View file

@ -2,9 +2,10 @@ from importlib import import_module
from aiogram.types import Message
from TelegramEDT import ADMIN_ID, dp, logger
from TelegramEDT import ADMIN_ID, dp, logger, modules
logger = logger.getChild("modules")
module_name = "modules"
logger = logger.getChild(module_name)
def load_module(module: str) -> bool:
@ -62,12 +63,14 @@ async def unload_cmd(message: Message):
def load():
logger.info("Load modules module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(load_cmd, commands="load")
dp.register_message_handler(unload_cmd, commands="unload")
modules.append(module_name)
def unload():
logger.info("Unload tools module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(load_cmd)
dp.message_handlers.unregister(unload_cmd)
modules.remove(module_name)

View file

@ -2,11 +2,12 @@ from aiogram import types
from aiogram.types import ParseMode
from feedparser import parse
from TelegramEDT import dp, key, logger, Session, check_id
from TelegramEDT import dp, key, logger, Session, check_id, modules
from TelegramEDT.base import User
from TelegramEDT.lang import lang
logger = logger.getChild("tomuss")
module_name = "tomuss"
logger = logger.getChild(module_name)
def have_await_cmd(msg: types.Message):
@ -46,12 +47,14 @@ async def await_cmd(message: types.message):
def load():
logger.info("Load tomuss module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(settomuss, lambda msg: msg.text.lower() == "settomuss")
dp.register_message_handler(await_cmd, lambda msg: have_await_cmd(msg))
modules.append(module_name)
def unload():
logger.info("Unload tomuss module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(settomuss)
dp.message_handlers.unregister(await_cmd)
modules.remove(module_name)

View file

@ -1,14 +1,13 @@
import datetime
from aiogram import types
from aiogram.types import ParseMode
from aiogram.utils import markdown
from aiogram.utils.exceptions import MessageIsTooLong
from TelegramEDT import ADMIN_ID, bot, dp, key, logger, Session, check_id
from TelegramEDT import ADMIN_ID, bot, dp, key, logger, Session, check_id, modules
from TelegramEDT.base import User
logger = logger.getChild("tools")
module_name = "tools"
logger = logger.getChild(module_name)
async def get_id(message: types.Message):
@ -87,18 +86,20 @@ async def errors(*args, **partial_data):
def load():
logger.info("Load tools module")
logger.info(f"Load {module_name} module")
dp.register_message_handler(get_id, commands="getid")
dp.register_message_handler(get_logs, commands="getlogs")
dp.register_message_handler(get_db, commands="getdb")
dp.register_message_handler(eval_cmd, commands="eval")
dp.register_errors_handler(errors)
modules.append(module_name)
def unload():
logger.info("Unload tools module")
logger.info(f"Unload {module_name} module")
dp.message_handlers.unregister(get_id)
dp.message_handlers.unregister(get_logs)
dp.message_handlers.unregister(get_db)
dp.message_handlers.unregister(eval_cmd)
dp.errors_handlers.unregister(errors)
modules.remove(module_name)

View file

@ -2,9 +2,10 @@ import asyncio
from aiogram.utils import executor
from TelegramEDT.notif import notif, dp
from TelegramEDT import dp
from TelegramEDT.loop import main
loop = asyncio.get_event_loop()
loop.create_task(notif())
loop.create_task(main())
loop.create_task(executor.start_polling(dp, skip_updates=True))
loop.run_forever()