A Mastodon bot for pinging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 年之前
123456789101112131415161718192021222324
  1. from ananas import PineappleBot, html_strip_tags, reply
  2. class PingBot(PineappleBot):
  3. def start(self):
  4. self.notifiees = self.config.notify.split(',')
  5. self.notifiees_str = ", ".join(self.notifiees)
  6. print(f"Now monitoring {self.config.monitor}; pinging {self.notifiees_str}.")
  7. @reply
  8. def post_response(self, mention, user):
  9. petitioner = user["acct"]
  10. if petitioner != self.config.monitor: # Prevent self-replies
  11. msg = mention["uri"]
  12. if self.config.full_message:
  13. msg += f"\n\n{html_strip_tags(mention['content'])}"
  14. visibility = 'direct'
  15. # This is for logging purposes. You may wish to redirect this into a text log.
  16. print(f"Received a reply from {petitioner}. Pinging {self.notifiees_str}.")
  17. notify_list = " ".join(self.notifiees)
  18. status = f"{notify_list} {self.monitor} has received a new message from {petitioner}:\n\n{msg}"
  19. if len(status) > 450: # don't let the post get too long!
  20. status = status[:450] + " ...(message continues)"
  21. self.mastodon.status_post(status, visibility=visibility)