1
0
Fork 0
mirror of https://gitlab.com/oloturia/fumcaso.git synced 2024-11-01 01:38:16 +01:00
fumcaso/mastrep.py

48 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-04-27 17:12:37 +02:00
#!/usr/bin/python3
2022-04-30 00:54:16 +02:00
from randstrip import createStrip
from mastodon import Mastodon, StreamListener
from mastodon_main import publishStrip
import json
2022-04-27 17:12:37 +02:00
import os
import sys
2022-11-29 15:57:07 +01:00
import time
2022-04-27 17:12:37 +02:00
fileDir = os.path.dirname(os.path.abspath(__file__))
fileDir = fileDir + "/"
API_URL = "https://botsin.space"
2022-04-30 00:54:16 +02:00
class stripListener(StreamListener):
def on_notification(self, notification):
try:
account = "@"+notification["account"]["acct"]
content = notification["status"]["content"]
if content.find("help") != -1:
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")
2022-05-02 02:02:22 +02:00
elif content.find("new strip") != -1:
2022-04-30 00:54:16 +02:00
if content.find("oloeng") != -1:
profile = "oloeng"
elif content.find("olofra") != -1:
profile = "olofra"
else:
profile = "oloturia"
publishStrip([profile],account)
except KeyError:
return
2022-04-27 17:12:37 +02:00
2022-04-30 00:54:16 +02:00
if __name__ == "__main__":
with open(fileDir+"/config.json") as f:
config = json.load(f)
2022-05-02 02:02:22 +02:00
with open(fileDir+config["mastodonListenerToken"]) as f:
2022-04-30 00:54:16 +02:00
createapp = f.readlines()
createapp = [x.strip() for x in createapp]
TOKEN = createapp[0]
mastodon = Mastodon(access_token = TOKEN,api_base_url = API_URL)
listener = stripListener()
2022-11-29 15:57:07 +01:00
while True:
try:
mastodon.stream_user(listener)
except:
time.sleep(10)