This repository has been archived on 2021-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
masto-image-bot/README.md

88 lines
4.4 KiB
Markdown
Raw Permalink Normal View History

2018-06-21 14:09:12 +02:00
# masto-image-bot
2018-03-23 07:25:35 +01:00
A bot that fetches a random local image and publish it on Mastodon.
2018-05-16 10:04:05 +02:00
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](https://framagit.org/fiat-tux/hat-softwares/mastodon/register-app).
2018-06-19 22:14:04 +02:00
## Install the dependencies
```
pip3 install -r requirements.txt
```
## Configure the bot
2018-06-21 10:10:33 +02:00
2018-06-21 22:08:34 +02:00
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.
2018-06-22 22:08:06 +02:00
| **Field name** | Description | Value |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| img_path | Path where image are located | /home/bot/img | ../bot |
| 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 | no |
| 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 |
2019-01-07 13:52:34 +01:00
| unsplash_client_id | Access key of your Unsplash App (you can create it on api.unsplash.com ) | string |
2018-06-21 22:40:43 +02:00
2018-06-22 18:18:51 +02:00
Copy `blacklist.sample.json` to `blacklist.json` and replace or add accounts that should not receive any image
2018-06-22 22:10:42 +02:00
Copy `collection.sample.json` to `collection.json` and add collection for your bot
2018-06-19 22:36:37 +02:00
## Use it
2018-06-19 22:14:04 +02:00
```
2018-06-22 22:33:33 +02:00
usage: bot.py [-h] [-i] [-s SOURCE] [--stream]
2018-06-19 22:14:04 +02:00
Choose between image or streaming
optional arguments:
2018-06-22 22:33:33 +02:00
-h, --help show this help message and exit
-i, --img post image
-s SOURCE, --source SOURCE
Source of image [ local | distant | unsplash-random ]
2018-06-22 22:33:33 +02:00
--stream stream user profile
2018-06-19 22:14:04 +02:00
```
`--img` option send image.
`--stream` option send image on mention
2018-06-19 22:36:37 +02:00
## Create a systemd service
On `/etc/systemd/system/bot.service` copy paste code behind
2018-06-21 22:08:34 +02:00
2018-06-19 22:36:37 +02:00
```
[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/
2018-06-23 01:02:02 +02:00
ExecStart=/usr/bin/python3 bot.py --stream --source=local
2019-01-05 23:30:59 +01:00
[Install]
WantedBy=multi-user.target
```
Then do
```
systemctl daemon-reload
systemctl enable bot.service
systemctl start bot.service
2018-06-19 22:36:37 +02:00
```