Beispiel #1
0
def update_login_time(snowflake: int) -> None:
    """Update the user's last logged in time

    Args:
        snowflake (int): User's ID
    """
    current_date = datetime.now()
    db = get_db()
    db.execute(
        "UPDATE user SET last_login_date = ? WHERE snowflake = ?",
        (current_date.strftime("%Y-%m-%d %H:%M:%S"), snowflake),
    )
    db.commit()
Beispiel #2
0
def update_db_fields(unique_id: str, **kwargs) -> None:
    """Update the stream's properties in the database.

    Args:
        unique_id (str): The stream's unique ID.
    """
    db = get_db()
    for key, value in kwargs.items():
        current_app.logger.info(
            f"Updating field '{key}' in stream {unique_id}")
        db.execute(f"UPDATE stream SET {key} = ? WHERE unique_id = ?",
                   (value, unique_id))

    db.commit()
Beispiel #3
0
def end_stream(stream_key: str) -> None:
    """Sets the stream's end date in the database.

    Args:
        stream_key (str): The stream key to update.
    """
    db = get_db()
    current_app.logger.info(f"Ending stream {stream_key}")
    res = query_one("SELECT * FROM stream WHERE stream_key = ?", [stream_key])
    db.execute(
        "UPDATE stream SET end_date = ? WHERE id = ?",
        (datetime.now().strftime("%Y-%m-%d %H:%M:%S"), res["id"]),
    )
    db.commit()
Beispiel #4
0
def archive_stream(stream_key: str):
    """Archives a stream.

    Args:
        stream_key (str): The stream's stream key.
    """
    stream_path = Path(environ.get("REC_PATH", "")) / f"{stream_key}.mp4"
    current_app.logger.info(f"Adding stream {stream_path} to archive")
    db = get_db()
    db.execute(
        "UPDATE stream SET archived_file = ? WHERE stream_key = ?",
        (str(stream_path), stream_key),
    )
    db.commit()
Beispiel #5
0
def check_if_user_exists(snowflake: int) -> bool:
    """Returns True if user exists in database

    Args:
        snowflake (int): User's ID

    Returns:
        bool: User exists in database
    """
    db = get_db()
    q = db.execute("SELECT * FROM user WHERE snowflake = ?", (snowflake, ))
    result = q.fetchone()

    if result:
        return True
    else:
        return False
Beispiel #6
0
def add_user(username: str, snowflake: int, avatar: Union[str, None]) -> None:
    """Adds user to database

    Args:
        username (str): User's username
        snowflake (int): User's account ID
        avatar (Union[str, None]): User's avatar URL
    """
    current_date = datetime.now()
    db = get_db()
    current_app.logger.info(f"Adding user {username} to User table")
    db.execute(
        "INSERT INTO user (username, snowflake, avatar, last_login_date) VALUES (?, ?, ?, ?)",
        (username, snowflake, avatar,
         current_date.strftime("%Y-%m-%d %H:%M:%S")),
    )
    db.commit()
Beispiel #7
0
def add_stream_to_db(
    snowflake: int,
    title: str,
    description: str,
    category: str,
    archivable: bool,
    unique_id: str,
    stream_key: str,
    unlisted: bool,
) -> None:
    """Adds the stream to the database.

    Args:
        snowflake (int): User ID of the user initiating the stream.
        title (str): Title of the stream.
        description (str): The stream's description.
        category (str): The stream's category.
        archivable (bool): Is the stream going to be publically archived?
        unique_id (str): The stream's unique ID.
        stream_key (str): The stream's stream key.
        unlisted (bool): Is the stream unlisted?
    """
    db = get_db()
    current_app.logger.info(
        f"Adding stream {title} by {snowflake} with stream key {stream_key} to database"
    )
    db.execute(
        "INSERT INTO stream (user_snowflake, title, description, category, archivable, unique_id, stream_key, unlisted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
        (
            snowflake,
            title,
            description,
            category,
            archivable,
            unique_id,
            stream_key,
            unlisted,
        ),
    )
    db.commit()