neige d'aoust

knowledge, art, and other stuff

User Tools

Site Tools


fedibot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
fedibot [2025/02/02 18:17] – créée Yukifedibot [2025/02/13 16:37] (current) Yuki
Line 1: Line 1:
-Write your own simple Fediverse bot+====== Write your own simple Fediverse bot ======
  
-## 1. Acquire the ingredients+===== 1. Acquire the ingredients =====
  
-[toot](https://github.com/ihabunek/toot) +  * [[https://github.com/ihabunek/toot|toot]] 
-systemd+  systemd 
 +  * fortune-mod
  
-## 2. Write the shell script+===== 2. Write the shell script =====
  
-Create an account to the desired instance, then login to that account with toot.+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/dugbot+<code bash ~/bin/dugbot>
-```sh+
 #!/bin/sh #!/bin/sh
-toot post -l fr -u "dansunegalaxie@botsin.space" "$(fortune -sn500 dansunegalaxie)" +toot post -l fr -u "dansunegalaxie@pouet.quebec" "$(fortune -sn5000 dansunegalaxie)" 
-```+</code>
  
-You will want to make sure the output of the command you give out to `toot postisn't longer than the character limit allowed by your instance, or else it won't post.+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+===== 3. Run cron job =====
  
-/etc/systemd/system/dugbot.service+<code ini /etc/systemd/system/dugbot.service>
-```ini+
 [Unit] [Unit]
 Description=Post a random DUG quote to Mastodon Description=Post a random DUG quote to Mastodon
Line 27: Line 26:
 [Service] [Service]
 Type=oneshot Type=oneshot
-ExecStart=/home/juju/bin/dugbot +ExecStart=/home/yuki/bin/dugbot 
-User=juju +User=yuki 
-```+</code>
  
-/etc/systemd/system/dugbot.timer+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''
-```ini+ 
 +<code ini /etc/systemd/system/dugbot.timer>
 [Unit] [Unit]
 Description=Run dugbot every 30 minutes Description=Run dugbot every 30 minutes
Line 41: Line 41:
 [Install] [Install]
 WantedBy=timers.target WantedBy=timers.target
-```+</code>
  
-Run it:+The .timer file should have the same file name as the corresponding .service.
  
-```sh+Enable the timer: 
 + 
 +<code bash>
 sudo systemctl enable dugbot.timer sudo systemctl enable dugbot.timer
-```+sudo systemctl start dugbot.timer 
 +</code> 
 + 
 +Or run it once: 
 + 
 +<code bash> 
 +sudo systemctl start dugbot.service 
 +</code> 
 + 
 +===== Current list of bots ===== 
 + 
 +  * [[https://pouet.quebec/dansunegalaxie|@[email protected]]] (Dans une galaxie près de chez vous quotes) 
 +  * [[https://pouet.quebec/jocelyne|@[email protected]]] (Radio Enfer quotes)
fedibot.1738538263.txt.gz · Last modified: 2025/02/02 18:17 by Yuki