Un bot qui récupère une image random en local et la publie
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Dryusdan 67849b7f9f Remove quote for unsplash_client_id il y a 1 an
limiter add limiter #7 il y a 2 ans
secrets Mettre à jour 'secrets/secrets.txt' il y a 2 ans
utils finish streaming il y a 2 ans
.gitignore add distant image #3 il y a 2 ans
LICENSE Initial commit il y a 2 ans
README.md Improve README il y a 1 an
activity.log refactor code il y a 2 ans
blacklist.sample.json make blacklist #8 il y a 2 ans
bot.py Improve unsplash mode il y a 1 an
collection.sample.json add distant image #3 il y a 2 ans
config.sample.txt Remove quote for unsplash_client_id il y a 1 an
rename_all_file.sh add renamer il y a 2 ans
requirements.txt add distant image #3 il y a 2 ans

README.md

masto-image-bot

A bot that fetches a random local image and publish it on Mastodon.

Copy the file config.sample.txt to config.txt and add the path to your images directory. File the file secrets/secrets.txt with the codes you will find in the developper tab of your Mastodon account. You can also register your bot on a Mastodon instance and get the needed codes with the help of the script register-app.

Install the dependencies

pip3 install -r requirements.txt

Configure the bot

Copy config.sample.txt to config.txt and replace data by your data.

If you don’t want any “spoiler text”, just leave the line empty.

Field name Description Value
img_path Path where image are located /home/bot/img
name Name of your bot (name after @). Is usefull to hide it’s name in reply mybot
secrets_filepath Path where located secret secrets/secrets.txt
log_filepath Path where located log file activity.log
blacklist_filepath Path where located blacklist file blacklist.json
collection_filepath Path where located distant image collection collection.json
sensitive Hide picture behind “sensitive content” mask or not yes
default_text Text for --img option string
spoiler_text Text for every spoiler (or CW) (for --img or --stream option) string
limit Limit send per minute per person int
limit_hour Limit send par hour per person int
collection_url URL of website you deserve image. <collection> is a variable who depend on collection.json (you can remove this variable) string
unsplash_client_id Access key of your Unsplash App (you can create it on api.unsplash.com ) string

Copy blacklist.sample.json to blacklist.json and replace or add accounts that should not receive any image

Copy collection.sample.json to collection.json and add collection for your bot

Use it

usage: bot.py [-h] [-i] [-s SOURCE] [--stream]

Choose between image or streaming

optional arguments:
  -h, --help            show this help message and exit
  -i, --img             post image
  -s SOURCE, --source SOURCE
                        Source of image [ local | distant | unsplash-random ]
  --stream              stream user profile

--img option send image. --stream option send image on mention

Create a systemd service

On /etc/systemd/system/bot.service copy paste code behind

[Unit]
Description=Image bot Mastodon
Documentation=https://git.drycat.fr/Dryusdan/masto-random-local-image-bot/src/branch/master
Requires=network.target
After=network.target

[Service]
Type=simple
User=masto-bot
TimeoutSec=15
WorkingDirectory=/home/masto-bot/
ExecStart=/usr/bin/python3 bot.py --stream --source=local

[Install]
WantedBy=multi-user.target

Then do

systemctl daemon-reload
systemctl enable bot.service
systemctl start bot.service