diff --git a/bot.py b/bot.py index 01ed102..dd2d7d7 100644 --- a/bot.py +++ b/bot.py @@ -54,6 +54,7 @@ class CosmicBot(teambot.Handler): state["known"].extend(newpost(x) for x in newtrans) for trans in newtrans: self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans)) + toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans)) time.sleep(1) return state def on_pubmsg(self,channel,nick,text): diff --git a/requirements.txt b/requirements.txt index 3425b84..8a0a612 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,45 @@ -certifi==2020.4.5.1 -chardet==3.0.4 -feedparser==5.2.1 -idna==2.9 -inflect==2.1.0 -irc==17.0 -jaraco.classes==1.5 -jaraco.collections==1.6.0 -jaraco.functools==1.20 -jaraco.itertools==3.0.0 -jaraco.logging==1.5.2 -jaraco.stream==1.2 -jaraco.text==1.10.1 -more-itertools==4.3.0 -pytz==2018.7 -requests==2.23.0 -six==1.11.0 -teambot==0.2.0 -tempora==1.14 -titlecase==0.12.0 -tracery==0.1.1 -urllib3==1.25.9 +appdirs>=1.4.3 +blurhash>=1.1.4 +CacheControl>=0.12.6 +certifi>=2020.6.20 +chardet>=3.0.4 +colorama>=0.4.3 +contextlib2>=0.6.0 +decorator>=4.4.2 +distlib>=0.3.0 +distro>=1.4.0 +feedparser>=5.2.1 +html5lib>=1.0.1 +idna>=2.10 +inflect>=4.1.0 +ipaddr>=2.2.0 +irc>=19.0.1 +jaraco.classes>=3.1.0 +jaraco.collections>=3.0.0 +jaraco.functools>=3.0.1 +jaraco.itertools>=5.0.0 +jaraco.logging>=3.0.0 +jaraco.stream>=3.0.0 +jaraco.text>=3.2.0 +lockfile>=0.12.2 +Mastodon.py>=1.5.1 +more-itertools>=8.5.0 +msgpack>=0.6.2 +packaging>=20.3 +pep517>=0.8.2 +progress>=1.5 +pyparsing>=2.4.6 +python-dateutil>=2.8.1 +python-magic>=0.4.18 +pytoml>=0.1.21 +pytz>=2020.1 +regex>=2020.7.14 +requests>=2.24.0 +retrying>=1.3.3 +six>=1.14.0 +teambot>=0.2.0 +tempora>=4.0.0 +titlecase>=1.1.1 +tracery>=0.1.1 +urllib3>=1.25.10 +webencodings>=0.5.1 diff --git a/toot.py b/toot.py new file mode 100644 index 0000000..0f326fb --- /dev/null +++ b/toot.py @@ -0,0 +1,25 @@ +from mastodon import Mastodon +from os.path import exists +from os import chmod, stat +from stat import ST_MODE + +def getmod(fn): + return stat(fn)[ST_MODE] & 0777 + +if not exists("usercred.secret"): + if not exists("clientcred.secret"): + Mastodon.create_app("cosmicbot toots",api_base_url="https://tilde.zone",to_file="clientcred.secret") + chmod("clientcred.secret",0600) + elif getmod("clientcred.secret")!=0600: + chmod("clientcred.secret",0600) + tmp = Mastodon(client_id="clientcred.secret",api_base_url="https://tilde.zone") + with open("details.secret") as f: + tmp.log_in(f.readline().strip(),f.readline.strip(),to_file="usercred.secret") + chmod("usercred.secret",0600) +elif getmod("usercred.secret")!=0600: + chmod("usercred.secret",0600) + +m = Mastodon(access_token='usercred.secret',api_base_url="https://tilde.zone") + +def toot(msg): + m.toot(msg)