Captain Arepa
d03d10c3b5
|
1 year ago | |
---|---|---|
.gitignore | 1 year ago | |
LICENSE.md | 1 year ago | |
README.md | 1 year ago | |
deploy.sh | 1 year ago | |
gelbooru_poster.py | 1 year ago | |
misskeybot.service | 1 year ago | |
misskeybot.timer | 2 years ago | |
run.sh | 1 year ago |
README.md
Misskey Booru Bot - Yet another Booru bot, but for Misskey
Summary
This "bot" is just a Python script that fetches pictures from Gelbooru, and then uploads and posts them to your Misskey account. That's it. No frills, no complex stuff.
I found the original script on GitHub while looking for an alternative *booru bot that would work on Misskey. I originally used a modified version of Yandere's DanbooruBot for my Pleroma/Akkoma instances, but since I started using Misskey I looked for a bot that could do the same, and here it is. Just with comments and instructions on how to set up and use it.
Disclaimer
The instructions found here are made for Linux users that want to set this bot either in their local environment or in a remote host (e.g. a VPS where your instance is locate). I'm not responsible for any potential damage incurred to any system (hardware or software) that this script might cause. Run at your own risk.
Requirements
The basic requirements to configure and run this bot are:
- Python 3
- Knowledge on Linux terminal, crontab and systemd.
- A token generated from your Misskey account.
- Having your ssh host set up in a config (in case you're deploying to a remote server).
- Patience (?).
Configuration
In order to configure the bot so it can post to a Misskey account, first run python3 gelboory_poster.py --gen-config
to generate the base configuration files config.json
and a defaults.json
. They both will look like this:
{
"gelbooru_tags": "rating:safe",
"gelbooru_tags_exclude": "",
"bot_message": "Random image from Gelbooru",
"misskey_url": "https://misskey.example.com/",
"misskey_token": "",
"max_page_number": 1000
}
The values for each field are pretty much self-explanatory:
gelbooru_tags
: tags used for search, concatenated with a+
. For example,mona_(genshin_implact)+rating:explicit
.gelbooru_tags_exclude
: tags used in the search for filtering the results, concatenated by+
and with a-
preceding each value. For example+-guro+-scat+-furry+-comic
.bot_message
: well, d'uh!misskey_url
: URL of the instance the bot account will post from.misskey_token
: the token for your bot (or application). You need to generate it with full permissions in the API sections of your Misskey account settings.max_page_number
: number of pages queries by the script.
Once the base config files are generated, you need to create two folders, config
and live
at script level, copy the config.json
to the config
folder with another name, for example monabot.json
and modify the values with the coresponding data. You can have as many bot configurations as you want, but each one will be deployed to and run on their own folder.
Deploying
To a remote server
In order to deploy your bot, you have set the deploy.sh
to executable with sudo chmod +x deploy.sh
, and then run it with the following parameters ./deploy.sh [bot name] [ssh user] [ssh host] [target folder]
, where you'll have to replace each parameter with their corresponding values.
NOTE: the deploy.sh
script was made with a ssh host configuration in mind. If you're encountering errors, you could either modify it by adding -e "ssh -i $HOME/.ssh/[your server key]"
just before ${USER}
and setting your respective ssh key.
Locally
While this guide is intended for running on a remote server, the process for deploying locally is a bit simpler (with some caveats). Just rename the bot's configuration file back to config.json
, and copy it alongside the defaults.json
, the gelbooru_poster.py
and the run.sh
to whatever dedicated folder in you machine.
Running
To run the bot, you have 2 options: set up a systemd
service with a corresponding timer, or set up a crontab entry.
Crontab
Just add an entry to your system's crontab by executing crontab -e
and entering a new line. For example 00 */6 * * * /home/monamegistus/bots/monabot/run.sh >> "/home/monamegistus/bots/monabot/log.txt" 2>&1
will run the bot located at /home/monamegistus/bots/monabot
every sixth hour daily.
Service
In this case, you'll have to copy the contents of misskeybot.service
and misskeybot.timer
to files corresponding to your bot on /etc/systemd/system/
as root
user, and then enable them via terminal. Remember to modify the ExecPath
of your bot's .service
file to match the location of the script.
TODO - Future Stuff
Currently the script is made to post from a single configuration file, but I'm thinking of rewriting it so it can ultimately read from multiple configuration files. Maybe I'll add an argument on the script call, just like the DanbooruBot. Who know.
Credits
Kudos to Himanshu Goel for writing the original script.