diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9e09acf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM debian:stable + +RUN apt-get update && apt-get -y install jq curl wget coreutils locales + +RUN mkdir -p /dirkjan-bot/data /usr/bin +RUN chmod +rwx /dirkjan-bot/data + +RUN locale-gen nl_NL.UTF-8 + +ADD ./dirkjan-bot /dirkjan-bot/dirkjan-bot + +RUN ln -s /dirkjan-bot/dirkjan-bot /usr/bin/ + +CMD /dirkjan-bot/dirkjan-bot diff --git a/dirkjan-bot b/dirkjan-bot index cb2637d..7dc277c 100755 --- a/dirkjan-bot +++ b/dirkjan-bot @@ -11,7 +11,7 @@ instance_url='https://botsin.space' here="$(here="$(readlink -f "${BASH_SOURCE[0]}")" && dirname "$here")" || exit $? get-dirkjan-img-url() { - url="$1" + local url="$1" curl "$url/" | grep img | grep -Po '(?<=src=")[^"]+"' | head -n 2 | tail -n 1 } @@ -27,7 +27,7 @@ download-dirkjan-img() ( date="$(date +'%H-%M-%S %d-%m-%Y')" data_dir="$here/data" - mkdir -p "$data_dir" + [[ -d "$data_dir" ]] || mkdir -p "$data_dir" outfile="$data_dir/dirkjan $date.png" @@ -37,7 +37,7 @@ download-dirkjan-img() ( ) api-curl() { - token="$1" + local token="$1" shift || return $? @@ -46,7 +46,11 @@ api-curl() { img_file="$(download-dirkjan-img "$dirkjan_url" "$here")" -bot_token="$(cat "$here/bot-token")" || exit $? +if [[ -z "$DIRKJAN_BOT_TOKEN" ]]; then + bot_token="$(cat "$here/bot-token")" || exit $? +else + bot_token="$DIRKJAN_BOT_TOKEN" +fi upload_result="$(api-curl "$bot_token" -F file=@"$img_file" "$instance_url/api/v1/media")" || exit $? @@ -59,7 +63,7 @@ echo ha format_string='{ "status": "#dirkjan %s\\n\\n#dagelijks #nederlandstalig #strip #daily #dutch #comic", "media_ids": [ "%s" ], -"visibility": "unlisted" +"visibility": "public" }' printf -v json "$format_string" "$post_text" "$media_id" diff --git a/dirkjan.png b/dirkjan.png new file mode 100644 index 0000000..e93753d Binary files /dev/null and b/dirkjan.png differ