Exemplo n.º 1
0
def term(cmd):
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    if p.stderr:
        log.error(p.stderr.readlines())
    return p.stdout.readlines()
Exemplo n.º 2
0
def exit_gracefully(signum, frame):
    log.warning("Bye!")

    try:
        redis.save()
    except Exception:
        log.error("Exiting immediately!")
    os.kill(os.getpid(), signal.SIGUSR1)
Exemplo n.º 3
0
 async def wrapped_1(*args, **kwargs):
     global SENT
     # We can't use redis here
     # So we save data - 'message sent to' in a list variable
     update = args[0]
     message = (update.message if update.message is not None else
                update.callback_query.message
                if update.callback_query is not None else update)
     chat_id = message.chat.id if 'chat' in message else None
     try:
         return await func(*args, **kwargs)
     except RedisError:
         if chat_id not in SENT:
             text = 'Sorry for inconvience! I encountered error in my redis DB, which is necessary for running '\
                    'bot \n\nPlease report this to my support group immediately when you see this error!'
             if await bot.send_message(chat_id, text):
                 SENT.append(chat_id)
         # Alert bot owner
         if OWNER_ID not in SENT:
             text = 'Sophie panic: Got redis error'
             if await bot.send_message(OWNER_ID, text):
                 SENT.append(OWNER_ID)
         log.error(RedisError, exc_info=True)
         return False
Exemplo n.º 4
0
    )


# TODO: Logs channel

log.debug("Checking on database structure update...")

if not (data := mongodb.db_structure.find_one({'db_ver': {"$exists": True}})):
    log.info("Your database is empty! Creating database structure key...")
    mongodb.db_structure.insert_one({'db_ver': DB_STRUCTURE_VER})
    log.info("Database structure version is: " + str(DB_STRUCTURE_VER))
else:
    curr_ver = data['db_ver']
    log.info("Your database structure version is: " + str(curr_ver))
    if DB_STRUCTURE_VER > curr_ver:
        log.error("Your database is old! Waiting 20 seconds till update...")
        log.info("Press CTRL + C to cancel!")
        time.sleep(20)
        log.debug("Trying to update database structure...")
        log.info("--------------------------------")
        log.info("Your current database structure version: " + str(curr_ver))
        log.info("New database structure version: " + str(DB_STRUCTURE_VER))
        log.info("--------------------------------")
        old_ver = curr_ver
        while curr_ver < DB_STRUCTURE_VER:
            new_ver = curr_ver + 1
            log.info(f"Trying update to {str(new_ver)}...")

            log.debug("Importing: sophie_bot.db." + str(new_ver))
            import_module("sophie_bot.db." + str(new_ver))