A Mastodon bot for pinging
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425
  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 = [f"@{notif}" for notif in self.notifiees]
  6. self.notifiees_str = ", ".join(self.notifiees)
  7. print(f"Now monitoring {self.config.monitor}; pinging {self.notifiees_str}.")
  8. @reply
  9. def post_response(self, mention, user):
  10. petitioner = user["acct"]
  11. if petitioner != self.config.monitor: # Prevent self-replies
  12. msg = mention["uri"]
  13. if self.config.full_message and str(self.config.full_message).lower() == "true":
  14. msg += f"\n\n{html_strip_tags(mention['content'])}"
  15. visibility = 'direct'
  16. # This is for logging purposes. You may wish to redirect this into a text log.
  17. print(f"Received a reply from {petitioner}. Pinging {self.notifiees_str}.")
  18. notify_list = " ".join(self.notifiees)
  19. status = f"{notify_list} {self.config.monitor} has received a new message from {petitioner}:\n\n{msg}"
  20. if len(status) > 450: # don't let the post get too long!
  21. status = status[:450] + " ...(message continues)"
  22. self.mastodon.status_post(status, visibility=visibility)