1
0
Fork 0
mirror of https://gitlab.com/oloturia/fumcaso.git synced 2025-01-05 04:57:18 +01:00

added the replier

This commit is contained in:
oloturia 2022-04-30 00:54:16 +02:00
parent 157c6387c1
commit c78bc6ba7e
5 changed files with 61 additions and 15 deletions

2
.gitignore vendored
View file

@ -11,3 +11,5 @@ history/*
bin/*
temp/*
*.pyc
secret
mastodon_listener_token

View file

@ -1,8 +1,6 @@
{
"defaultProfile": "oloturia",
"defaultMastodonToken": "./mastodon_token",
"defaultTelegramToken": "./telegram_token",
"defaultTwitterToken": "./twitter_token",
"mastodonListenerToken": "./mastodon_listener_token",
"oloturia": {
"saveLocation": "/var/tmp",

View file

@ -8,13 +8,8 @@ fileDir = os.path.dirname(os.path.abspath(__file__))
fileDir = fileDir +"/"
API_URL = "https://botsin.space"
if __name__ == "__main__":
if len(sys.argv) == 2:
altProfile = [sys.argv[1]]
else:
altProfile = False
def publishStrip(altProfile=False,user=False):
config = readConfig(platform="mastodon",profile=altProfile)
with open(config["token"]) as f:
createapp = f.readlines()
createapp = [x.strip() for x in createapp]
@ -26,7 +21,10 @@ if __name__ == "__main__":
for i in range(1,100):
try:
new_strip = mastodon.media_post(config["saveLocation"]+config["filename"],"image/png")
mastodon.status_post(config["text"],media_ids=new_strip)
if not(user):
mastodon.status_post(config["text"],media_ids=new_strip)
else:
mastodon.status_post(user+" "+config["text"],media_ids=new_strip,visibility="direct")
published = True
except:
continue
@ -36,3 +34,9 @@ if __name__ == "__main__":
else:
print("error creating image\n")
print(status)
if __name__ == "__main__":
if len(sys.argv) == 2:
publishStrip([sys.argv[1]])
else:
publishStrip()

37
mastodon_replier.py Normal file → Executable file
View file

@ -1,7 +1,9 @@
#!/usr/bin/python3
from randstrip import createStrip,readConfig
from mastodon import Mastodon
from randstrip import createStrip
from mastodon import Mastodon, StreamListener
from mastodon_main import publishStrip
import json
import os
import sys
@ -9,7 +11,32 @@ fileDir = os.path.dirname(os.path.abspath(__file__))
fileDir = fileDir + "/"
API_URL = "https://botsin.space"
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")
elif content.find("strip") != -1:
if content.find("oloeng") != -1:
profile = "oloeng"
elif content.find("olofra") != -1:
profile = "olofra"
else:
profile = "oloturia"
publishStrip([profile],account)
except KeyError:
return
if __name__ == "__main__":
config = readConfig
with open(fileDir+"/config.json") as f:
config = json.load(f)
with open(config["mastodonListenerToken"]) as f:
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()
mastodon.stream_user(listener)

15
register_app.py Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env python3
from mastodon import Mastodon
'''
you need to register the app only once
'''
Mastodon.create_app(
"oloturia_listener",
api_base_url = "https://botsin.space",
to_file = "secret"
)
print("App registered!")