A small bot that publishes images from a folder any time you run it
 
 
Go to file
arne 5266681574 Mention Pixelfed in README 2023-02-18 20:37:46 +01:00
posts Initial commit 2023-01-03 21:01:48 +01:00
.envrc Initial commit 2023-01-03 21:01:48 +01:00
.gitignore Initial commit 2023-01-03 21:01:48 +01:00
README.md Mention Pixelfed in README 2023-02-18 20:37:46 +01:00
flake.lock Initial commit 2023-01-03 21:01:48 +01:00
flake.nix Initial commit 2023-01-03 21:01:48 +01:00
main.ts Allow specifying a custom folder 2023-02-03 09:34:30 +01:00

README.md

Fediverse Image Bot

This is a small program that posts image from a given folder to a Mastodon or Pixelfed server every time you call it. It aims to be easy to use and easy to set up. It has been tested and works with Mastodon 4.x and Pixelfed 0.11.x. Usage:

deno run -A main.ts [folder]

Setup

  • Install deno
  • Create an account on a bot-friendly mastodon instance and obtain an access token (see below)
  • Create a folder somewhere on your computer
  • Fill the folder with images you'd like to post

Obtaining an access token

An access token is required for this bot to log into an account and act on behalf of it, to upload images and create new posts. To set it up, go to the "New application" page on your mastodon instance (for example https://botsin.space/settings/applications/new).

  • Give your bot a name
  • Scroll down to "Scopes"; you can uncheck everything and check only write:media and write:posts.
  • Click submit. You will be redirected to https://botsin.space/settings/applications
  • Click on the application you just created
  • Copy the value in the row "your access token". It will be a sequence of letters and numbers that looks like K3g57Yv4-wsg8I78VzegJIowGr-AS1HWmXO2tD9MmPu (for Pixelfed servers this will be longer)

Anybody with this access token can use the account to upload media and write posts, so take care to not publish it anywhere where a lot of people have access to it.

Usage

You can call it like so:

# for example MASTODON_INSTANCE_URL=https://botsin.space
export MASTODON_INSTANCE_URL=...
# for example MASTODON_ACCESS_TOKEN=K3g57Yv4-wsg8I78VzegJIowGr-AS1HWmXO2tD9MmPu
export MASTODON_ACCESS_TOKEN=...
deno run --allow-env --allow-net --allow-write --allow-read main.ts [folder]

It is best if you specify folder as an /absolute/path/like/so. You can also a folder when calling the script, it will try to look for a posts directory inside the folder where the script is located.