Ejemplo n.º 1
0
def exit_gracefully(signum, frame):
    log.warning("Bye!")

    try:
        redis.save()
    except Exception:
        log.error("Exiting immediately!")
    os.kill(os.getpid(), signal.SIGUSR1)
Ejemplo n.º 2
0
def _convert_time(__t: dict) -> str:
    from datetime import timedelta

    sec = timedelta(**__t).total_seconds()
    # this works on basis that days, hours, minutes are whole numbers!
    # check days first
    if sec % 86400 == 0:
        return f"{round(sec / 86400)}d"
    elif sec % 3600 == 0:
        # check hours
        return f"{round(sec / 3600)}h"
    elif sec % 60 == 0:
        # check minutes
        return f"{round(sec / 60)}m"
    else:
        log.warning(f"Found unexpected value {sec}...!")
Ejemplo n.º 3
0
    for module_name in modules:
        # Load pm_menu at last
        if module_name == 'pm_menu':
            continue
        log.debug(f"Importing <d><n>{module_name}</></>")
        imported_module = import_module("hitsuki.modules." + module_name)
        if hasattr(imported_module, '__help__'):
            if hasattr(imported_module, '__mod_name__'):
                MOD_HELP[
                    imported_module.__mod_name__] = imported_module.__help__
            else:
                MOD_HELP[imported_module.__name__] = imported_module.__help__
        LOADED_MODULES.append(imported_module)
    log.info("Modules loaded!")
else:
    log.warning("Not importing modules!")

loop = asyncio.get_event_loop()

import_module('hitsuki.modules.pm_menu')
# Import misc stuff
import_module("hitsuki.utils.exit_gracefully")
if not get_bool_key('DEBUG_MODE'):
    import_module("hitsuki.utils.sentry")


async def before_srv_task(loop):
    for module in [
            m for m in LOADED_MODULES if hasattr(m, '__before_serving__')
    ]:
        log.debug('Before serving: ' + module.__name__)