Ejemplo n.º 1
0
def handle_request_list(request_list, published=True):
    """
    :param request_list: list of request dictionaries
    :param published: directly publish to Facebook
    """
    logger.info(f"Starting request handler (published: {published})")
    exception_count = 0
    for request_dict in request_list:
        try:
            return handle_request_item(request_dict, published)
        except exceptions.RestingMovie:
            # ignore recently requested movies
            continue
        except (FileNotFoundError, OSError,
                timeout_decorator.TimeoutError) as error:
            # to check missing or corrupted files
            exception_count += 1
            logger.error(error, exc_info=True)
            continue
        except (exceptions.BlockedUser, exceptions.NSFWContent):
            update_request_to_used(request_dict["id"])
        except Exception as error:
            logger.error(error, exc_info=True)
            exception_count += 1
            update_request_to_used(request_dict["id"])
            message = type(error).__name__
            if "offens" in message.lower():
                block_user(request_dict["user"])
            notify(request_dict["id"], message, published)
        if exception_count > 20:
            logger.warning("Exception limit exceeded")
            break
Ejemplo n.º 2
0
def handle_request_item(request_dict, published):
    """
    :param request_list: request dictionaries
    :param published: directly publish to Facebook
    """
    block_user(request_dict["user"], check=True)
    request_command = request_dict["type"]
    request_dict["is_episode"] = is_episode(request_dict["comment"])
    request_dict["parallel"] = is_parallel(request_dict["comment"])

    if len(request_dict["content"]) > 8:
        raise exceptions.TooLongRequest

    logger.info(
        f"Request command: {request_command} {request_dict['comment']} "
        f"(Episode: {request_dict['is_episode']})")

    is_multiple = len(request_dict["content"]) > 1
    final_imgs, frames, alt_title = get_images(request_dict, is_multiple,
                                               published)
    request_dict["parallel"] = alt_title

    try:
        post_id = post_request(
            final_imgs,
            frames[0].movie,
            request_dict,
            published,
            request_dict["is_episode"],
        )
    except facepy.exceptions.OAuthError as error:
        message = f"Something is wrong with the Facebook token: {error}"
        webhook = DiscordWebhook(url=DISCORD_WEBHOOK_TEST, content=message)
        webhook.execute()
        sys.exit(message)

    try:
        comment_post(post_id, published, request_dict["is_episode"])
        notify(request_dict["id"], None, published, request_dict["is_episode"])
    except (facepy.exceptions.FacepyError, RequestException) as error:
        logger.error(error, exc_info=True)
    finally:
        if request_dict["is_episode"]:
            insert_episode_request_info_to_db(frames[0].movie,
                                              request_dict["user"])
        else:
            insert_request_info_to_db(frames[0].movie, request_dict["user"])

        update_request_to_used(request_dict["id"])

        logger.info("Request finished successfully")
        return True
Ejemplo n.º 3
0
def handle_request_list(request_list, published=True):
    """
    :param request_list: list of request dictionaries
    :param published: directly publish to Facebook
    """
    logger.info(f"Starting request handler (published: {published})")
    exception_count = 0
    for request_dict in request_list:
        try:
            return finish_request(request_dict, published)
        except exceptions.RestingMovie:
            # ignore recently requested movies
            continue
        except (
            exceptions.SubtitlesNotFound,
            FileNotFoundError,
            OSError,
            timeout_decorator.TimeoutError,
        ) as error:
            # to check missing or corrupted files
            exception_count += 1
            logger.error(error, exc_info=True)
            continue
        except (exceptions.BlockedUser, exceptions.NSFWContent):
            update_request_to_used(request_dict["id"])
        except Exception as error:
            try:
                send_traceback_webhook(traceback.format_exc(), request_dict, published)
                logger.error(error, exc_info=True)
                exception_count += 1
                update_request_to_used(request_dict["id"])
                message = f"{type(error).__name__} raised: {error}"
                if "offens" in message.lower():
                    block_user(request_dict["user"])
                notify(request_dict["id"], message, published)
            # We don't want the bot to stop working after notifying an
            # exception
            except Exception as error:
                logger.error(error, exc_info=True)

        if exception_count > 20:
            logger.warning("Exception limit exceeded")
            break
Ejemplo n.º 4
0
async def block(ctx, *args):
    user = "******".join(args)
    db.block_user(user.strip())
    await ctx.send("Ok.")