#!/bin/bash

# SPDX-FileCopyrightText: © 2021 Stefano Zacchiroli <zack@upsilon.cc>
# SPDX-License-Identifier: GPL-3.0-or-later

# Usage:
#
# $ jitsiroom
# https://meet.jit.si/TreasureNikeIrsGarage

JITSI_URL="https://meet.jit.si/"
ROOM_NAME_LEN=4
WORD_LIST_URL="https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english-no-swears.txt"
WORD_LIST="${HOME}/.cache/$(basename ${WORD_LIST_URL})"

if ! [ -f "$WORD_LIST" ] ; then
    echo "I: word list not found, downloading and caching it"
    mkdir -p $(dirname "$WORD_LIST")
    if ! wget -O "$WORD_LIST" "$WORD_LIST_URL" ; then
        echo "E: failed to retrieve word list from ${WORD_LIST_URL}, stopping."
        exit 2
    fi
fi

echo -n "$JITSI_URL"
for word in $(shuf -n "$ROOM_NAME_LEN" "$WORD_LIST") ; do
    echo -n ${word^}
done
echo