mastodon_replier.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/python3
  2. from randstrip import createStrip
  3. from mastodon import Mastodon, StreamListener
  4. from mastodon_main import publishStrip
  5. import json
  6. import os
  7. import sys
  8. fileDir = os.path.dirname(os.path.abspath(__file__))
  9. fileDir = fileDir + "/"
  10. API_URL = "https://botsin.space"
  11. class stripListener(StreamListener):
  12. def on_notification(self, notification):
  13. try:
  14. account = "@"+notification["account"]["acct"]
  15. content = notification["status"]["content"]
  16. if content.find("help") != -1:
  17. mastodon.status_post("Hello "+account+" just send me a message with 'new strip' and the desired profile. Try with 'oloturia' (Italian), 'oloeng' (broken English) or 'olofra' (French). If not specified, Italian will be selected as default.",visibility="direct")
  18. elif content.find("strip") != -1:
  19. if content.find("oloeng") != -1:
  20. profile = "oloeng"
  21. elif content.find("olofra") != -1:
  22. profile = "olofra"
  23. else:
  24. profile = "oloturia"
  25. publishStrip([profile],account)
  26. except KeyError:
  27. return
  28. if __name__ == "__main__":
  29. with open(fileDir+"/config.json") as f:
  30. config = json.load(f)
  31. with open(config["mastodonListenerToken"]) as f:
  32. createapp = f.readlines()
  33. createapp = [x.strip() for x in createapp]
  34. TOKEN = createapp[0]
  35. mastodon = Mastodon(access_token = TOKEN,api_base_url = API_URL)
  36. listener = stripListener()
  37. mastodon.stream_user(listener)