Skip to content

Instantly share code, notes, and snippets.

@PVince81
Last active November 4, 2020 09:59
Show Gist options
  • Save PVince81/c67e2e288c06adf56e49573cdc4c2e7b to your computer and use it in GitHub Desktop.
Save PVince81/c67e2e288c06adf56e49573cdc4c2e7b to your computer and use it in GitHub Desktop.
Nextcloud chatter generator
#!/bin/bash
# replace accordingly
NC_URL="https://localhost"
USERS=(alice bob charles dave)
PASSWORD=test
EXPRESSIONS=("hello" "hello!" "goodbye" "bye" "how are you" "good, thank you")
while true;
do
USER=${USERS[$RANDOM % ${#USERS[@]} ]}
# get all non-readonly rooms
ROOMS=($(curl "${NC_URL}/ocs/v2.php/apps/spreed/api/v3/room?format=json" \
-X GET \
-u "$USER:$PASSWORD" \
-H 'OCS-APIRequest: true' \
-s | jq -r ".ocs.data[] | select(.readOnly==0).token"
))
ROOM=${ROOMS[$RANDOM % ${#ROOMS[@]}]}
MESSAGE=${EXPRESSIONS[$RANDOM % ${#EXPRESSIONS[@]} ]}
echo User \"$USER\" posting \"$MESSAGE\" to room "$ROOM"
curl "${NC_URL}/ocs/v2.php/apps/spreed/api/v1/chat/$ROOM" \
-X POST \
-u "$USER:$PASSWORD" \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'OCS-APIRequest: true' \
--data-binary '{"message":"'$MESSAGE'"}' \
-s \
> /dev/null
sleep $(($RANDOM % 3))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment