From d627560a20dfbf75d0fc9aa1931fe24c9f9a3c54 Mon Sep 17 00:00:00 2001 From: rom4nik <46846000+rom4nik@users.noreply.github.com> Date: Thu, 30 Sep 2021 20:01:01 +0200 Subject: [PATCH] Add Matrix support --- Dockerfile | 6 ++++-- README.md | 23 ++++++++++++++--------- config-sample.txt | 7 ++++++- src/main.sh | 5 +++++ src/msg_matrix.sh | 9 +++++++++ 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 src/msg_matrix.sh diff --git a/Dockerfile b/Dockerfile index 77b8d00..3ae9686 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM alpine:3.14 -RUN apk add --no-cache bash tzdata curl imagemagick nodejs npm && \ +RUN apk add --no-cache bash tzdata curl imagemagick \ + nodejs npm \ + jq file coreutils && \ ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && echo Europe/Warsaw > /etc/timezone COPY src /app WORKDIR /app/msg_facebook/ -RUN npm install +RUN npm install && apk del npm USER 1000:1000 VOLUME ["/data"] diff --git a/README.md b/README.md index a37d010..3cc805b 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,20 @@ # pb-rozklad -## Run: -Dockerfile defaults to running the script in a cron-like manner, see docker-compose.yml for an example deployment. +## Setup +Dockerfile defaults to running the script in a cron-like manner, see `docker-compose.yml` for an example deployment. Make sure to set `xx_ENABLED=false` in config.txt if you don't intend to use a particular messaging platform. -## appstate.json for FB Messenger: +## appstate.json for FB Messenger https://github.com/shellmage/AAAAAAAAAAAAA/blob/main/getAppstate.js -Run it in without headless mode, then click the login button manually. +This script is partially broken. Outside container run `npm install puppeteer`, run script above without headless mode, click the login button manually, then move generated appstate.json to `/data` inside container. -## Testy: -- 404 (brak rozkładu) -- pierwszy rozkład -- powtórka rozkładu -- zmieniony rozkład \ No newline at end of file +## Matrix support +Put https://github.com/fabianonline/matrix.sh/ in `/data`. Run it once inside container using `HOME=/data/matrix.sh /data/matrix.sh/matrix.sh --login` to obtain access token. + +E2EE rooms aren't supported for the time being. + +## Tests +- no schedule (HTTP 404) +- first schedule +- schedule without changes +- schedule with changes \ No newline at end of file diff --git a/config-sample.txt b/config-sample.txt index bba9f4e..edc4df8 100644 --- a/config-sample.txt +++ b/config-sample.txt @@ -11,4 +11,9 @@ DC_MESSAGE="nowy rozkład:" FB_ENABLED=true FB_THREAD_ID="123456789" -FB_MESSAGE="nowy rozkład:" \ No newline at end of file +FB_MESSAGE="nowy rozkład:" + + +MX_ENABLED=true +MX_ROOM_ID="!xxxxxx:example.com" +MX_MESSAGE="nowy rozkład:" \ No newline at end of file diff --git a/src/main.sh b/src/main.sh index b84ac1d..3ba772b 100755 --- a/src/main.sh +++ b/src/main.sh @@ -58,6 +58,11 @@ if [ $FB_ENABLED = true ]; then node /app/msg_facebook/msg_facebook.js fi +if [ $MX_ENABLED = true ]; then + export MX_ROOM_ID MX_MESSAGE pdf_nice diff_exitcode + bash /app/msg_matrix.sh +fi + # TODO: check if that still works if [ $ARCHIVE_WAYBACK = true ]; then curl -o /dev/null "https://web.archive.org/save/$PDF_URL" -w %{url_effective} -Ls diff --git a/src/msg_matrix.sh b/src/msg_matrix.sh new file mode 100644 index 0000000..51c1b43 --- /dev/null +++ b/src/msg_matrix.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# workaround for matrix.sh storing config file in ~/.matrix.sh +HOME=/data/matrix.sh + +/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --send "$MX_MESSAGE" +/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/current.png --image +if [ $diff_exitcode -eq 1 ]; then /data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/comparison.png --image; fi +/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/$pdf_nice