Exemple #1
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: Update = args[0]

            if update.message is not None:
                message = update.message
            elif update.callback_query is not None:
                message = update.callback_query.message
            elif update.edited_message is not None:
                message = update.edited_message
            else:
                return True

            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 inconvenience! 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 = 'Daisy panic: Got redis error'
                    if await bot.send_message(OWNER_ID, text):
                        SENT.append(OWNER_ID)
                log.error(RedisError, exc_info=True)
                return True
Exemple #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)
Exemple #3
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()
Exemple #4
0
async def all_errors_handler(update: Update, error):
    if update.message is not None:
        message = update.message
    elif update.callback_query is not None:
        message = update.callback_query.message
    elif update.edited_message is not None:
        message = update.edited_message
    else:
        return True  # we don't want other guys in playground

    chat_id = message.chat.id
    err_tlt = sys.exc_info()[0].__name__
    err_msg = str(sys.exc_info()[1])

    log.warn(
        "Error caused update is: \n"
        + html.escape(str(parse_update(message)), quote=False)
    )

    if redis.get(chat_id) == str(error):
        # by err_tlt we assume that it is same error
        return True

    if err_tlt == "BadRequest" and err_msg == "Have no rights to send a message":
        return True

    ignored_errors = (
        "FloodWaitError",
        "RetryAfter",
        "SlowModeWaitError",
        "InvalidQueryID",
    )
    if err_tlt in ignored_errors:
        return True

    if err_tlt in ("NetworkError", "TelegramAPIError", "RestartingTelegram"):
        log.error("Conn/API error detected", exc_info=error)
        return True

    text = "<b>Sorry, I encountered a error!</b>\n"
    text += f"<code>{html.escape(err_tlt, quote=False)}: {html.escape(err_msg, quote=False)}</code>"
    redis.set(chat_id, str(error), ex=600)
    await bot.send_message(chat_id, text)
Exemple #5
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: DaisyX.db." + str(new_ver))
            import_module("DaisyX.db." + str(new_ver))