#!/bin/bash
# ig give a default optionfuck
if [ -z "$1" ]; then
    msg="SHIT'S GOIN ON RN"
else
    msg="$1"
fi

# faggot function
broadcast_important_princess_message() {
    # fuckin hell if yo dont have an arg fuku
    if [ -z "$1" ]; then
        echo "Usage: broadcast_important_princess_message \"Princess' Important Message\"" >&2
        return 1
    fi

    # am i rootie?
    if [ "$EUID" -ne 0 ]; then
        echo "Error: fuckyou dis shit needs root FAIL" >&2
        return 1
    fi

    local message="$1"
    local timestamp
    timestamp=$(date +"%H:%M:%S")

    echo "Broadcasting message to all ponies~"

    # loop throu /dev/pts/
    for pty in /dev/pts/[0-9]*; do
        # Eig check it fuukc
        if [ -c "$pty" ]; then
            # end my IMPORTANT MESSAGE IN RED WITH A BANMNER
            {
                echo -e "\033[31m"
                echo -e "=== PRINCESS BROADCAST SYSTEM ($timestamp) ==="
                echo -e "$message"
                echo  -e "====================================="
                echo -e "\e[0m"
            } > "$pty" 2>/dev/null
        fi
    done
}

# needz root to write to other peoplez ptys
broadcast_important_princess_message "$msg"