From 1830b1be752415214ed21236f79c97359e1b9770 Mon Sep 17 00:00:00 2001 From: khuxkm fbexl Date: Fri, 11 Sep 2020 02:23:29 +0000 Subject: [PATCH 1/3] Fix octal literals --- toot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/toot.py b/toot.py index 0f326fb..2c6aa9c 100644 --- a/toot.py +++ b/toot.py @@ -4,20 +4,20 @@ from os import chmod, stat from stat import ST_MODE def getmod(fn): - return stat(fn)[ST_MODE] & 0777 + return stat(fn)[ST_MODE] & 0o777 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) + chmod("clientcred.secret",0o600) + elif getmod("clientcred.secret")!=0o600: + chmod("clientcred.secret",0o600) 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) + chmod("usercred.secret",0o600) +elif getmod("usercred.secret")!=0o600: + chmod("usercred.secret",0o600) m = Mastodon(access_token='usercred.secret',api_base_url="https://tilde.zone") From d23ef4ae6670be465f1c157f1dcc1626ef0b85f0 Mon Sep 17 00:00:00 2001 From: khuxkm fbexl Date: Fri, 11 Sep 2020 02:24:47 +0000 Subject: [PATCH 2/3] How did I miss those parentheses? --- toot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toot.py b/toot.py index 2c6aa9c..1fce9cf 100644 --- a/toot.py +++ b/toot.py @@ -14,7 +14,7 @@ if not exists("usercred.secret"): chmod("clientcred.secret",0o600) 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") + tmp.log_in(f.readline().strip(),f.readline().strip(),to_file="usercred.secret") chmod("usercred.secret",0o600) elif getmod("usercred.secret")!=0o600: chmod("usercred.secret",0o600) From bf59265e94e3b7dfcaba33902bc8654c25f28c6a Mon Sep 17 00:00:00 2001 From: khuxkm fbexl Date: Wed, 16 Sep 2020 17:01:53 +0000 Subject: [PATCH 3/3] Wrap CosmicBot.check_rss in a try-except block This prevents cosmicbot's RSS checking thread from crashing if the RSS feed ends up malformed for any reason. --- bot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index bb84713..5537bb8 100644 --- a/bot.py +++ b/bot.py @@ -49,13 +49,19 @@ class CosmicBot(teambot.Handler): self.load_modules() self.tasks.run() def check_rss(self,state,base_state): - newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) - if newtrans: - 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) + try: + newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) + if newtrans: + 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) + except: + print("Error occurred while loading feed, will try again...") + print("Traceback is below:") + traceback.print_exc() + pass return state def on_pubmsg(self,channel,nick,text): self.is_admin = self.event.source.userhost == bot_op