#!/bin/bash # Function to prompt for input with a default value prompt() { local prompt_text="$1" local default_val="$2" local var_name="$3" if [ -n "$default_val" ]; then read -p "$prompt_text [$default_val]: " input eval $var_name="\${input:-$default_val}" else read -p "$prompt_text: " input eval $var_name="\$input" fi } # --- 1. Gather Event Details --- echo "--- New Event Wizard ---" prompt "Event Name" "" EVENT_NAME prompt "Date (YYYY-MM-DD)" "$(date +%Y-%m-%d)" EVENT_DATE prompt "Time (e.g. 6-9 PM)" "6-9 PM" EVENT_TIME prompt "Location" "Engineering IV, Maxwell Room (57-124)" EVENT_LOCATION prompt "Ping Preference (1: @everyone, 2: @UCLA, 3: None)" "3" PING_CHOICE case $PING_CHOICE in 1) PING_TEXT="@everyone" ;; 2) PING_TEXT="<@&1000205372327481444>" ;; # Assuming @UCLA role ID, replace if known or use generic *) PING_TEXT="" ;; esac echo "Enter Description (Markdown supported). Press Ctrl+D on a new line to finish:" EVENT_DESCRIPTION=$(cat) echo "" # Add newline after input # Slugify event name for filename SLUG=$(echo "$EVENT_NAME" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z) FILENAME="content/events/${SLUG}.md" # --- 2. Generate Hugo Content --- echo "Generating $FILENAME..." cat < "$FILENAME" --- title: "$EVENT_NAME" date: $(date +%Y-%m-%d) tags: [events] author: LUG Board --- $EVENT_DESCRIPTION * **Date**: $EVENT_DATE * **Time**: $EVENT_TIME * **Location**: $EVENT_LOCATION EOF echo "Hugo page created." # --- 3. Discord Notification (Webhook) --- # Check for env var or prompt if [ -z "$DISCORD_WEBHOOK_URL" ]; then prompt "Enter Discord Webhook URL (leave empty to skip)" "" DISCORD_WEBHOOK_URL fi if [ -n "$DISCORD_WEBHOOK_URL" ]; then echo "Sending Discord announcement..." # Construct JSON payload # Note: Using jq would be safer, but manual construction avoids dependencies if simple # Escaping quotes in description for JSON SAFE_DESC=$(echo "$EVENT_DESCRIPTION" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g') JSON_PAYLOAD=$(cat < "18:00" # This is a simplification. For robust parsing, might need python or date utils. # Extract start hour and minute START_HOUR=$(echo "$EVENT_TIME" | grep -oE '^[0-9]+' | head -1) START_MINUTE=$(echo "$EVENT_TIME" | grep -oE ':[0-9]+' | sed 's/://' | head -1) START_MINUTE=${START_MINUTE:-00} if [[ "$EVENT_TIME" == *"PM"* ]] && [ "$START_HOUR" -lt 12 ]; then START_HOUR=$((START_HOUR + 12)) fi # Construct ISO string with timezone using date command START_DATE_STR="$EVENT_DATE $START_HOUR:$START_MINUTE" START_ISO=$(date -d "$START_DATE_STR" --iso-8601=seconds) # End time: Start + 2 hours # Use START_ISO as base to ensure correct calculation END_ISO=$(date -d "$START_ISO + 2 hours" --iso-8601=seconds) # Location Type 3 is "External" CAL_PAYLOAD=$(cat <