====== Write your own simple Fediverse bot ======
===== 1. Acquire the ingredients =====
* [[https://github.com/ihabunek/toot|toot]]
* systemd
* fortune-mod
===== 2. Write the shell script =====
Create an account to the desired instance, then login to that account with toot. Make sure you do this with the user account the cron job is going to run as.
#!/bin/sh
toot post -l fr -u "dansunegalaxie@pouet.quebec" "$(fortune -sn5000 dansunegalaxie)"
You will want to make sure the output of the command you give out to ''toot post'' isn't longer than the character limit allowed by your instance, or else it won't post. In this instance, you can set the ''-n'' parameter of ''fortune'' to that character limit so it can try to not come up with fortunes longer than this.
===== 3. Run cron job =====
[Unit]
Description=Post a random DUG quote to Mastodon
[Service]
Type=oneshot
ExecStart=/home/yuki/bin/dugbot
User=yuki
Make sure to point ''ExecStart'' to the path of your script, and ''User'' to the user account you used to login to your bot account with ''toot''.
[Unit]
Description=Run dugbot every 30 minutes
[Timer]
OnCalendar=*:00,30
[Install]
WantedBy=timers.target
The .timer file should have the same file name as the corresponding .service.
Enable the timer:
sudo systemctl enable dugbot.timer
sudo systemctl start dugbot.timer
Or run it once:
sudo systemctl start dugbot.service
===== Current list of bots =====
* [[https://pouet.quebec/dansunegalaxie|@dansunegalaxie@pouet.quebec]] (Dans une galaxie près de chez vous quotes)
* [[https://pouet.quebec/jocelyne|@jocelyne@pouet.quebec]] (Radio Enfer quotes)