aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-04-05 19:15:47 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2020-04-05 20:04:10 +0200
commit54d3c081a26fbe14426ae353f0949c69341d3109 (patch)
tree3f329e358cb0cad24afee6e045321af55a9416bf
parent1fb2018b17efa27261810fde572fcb932ec749c6 (diff)
downloadwee-slack-54d3c081a26fbe14426ae353f0949c69341d3109.tar.gz
Stop calling thread.mark if not supported
The subscriptions.thread.mark method is only supported for the tokens the web client use, not by oauth or legacy tokens, so if we get an error that it's not supported for the current token type, remove it from slack_api_translator so we don't keep calling it. slack_api_translator is moved to a team attribute because different teams may use different token types.
-rw-r--r--wee_slack.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 544445d..d67d478 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -11,6 +11,7 @@ from functools import partial, wraps
from io import StringIO
from itertools import chain, count, islice
+import copy
import errno
import textwrap
import time
@@ -1249,6 +1250,7 @@ class SlackTeam(object):
"""
def __init__(self, eventrouter, token, team_hash, websocket_url, team_info, subteams, nick, myidentifier, my_manual_presence, users, bots, channels, **kwargs):
+ self.slack_api_translator = copy.deepcopy(SLACK_API_TRANSLATOR)
self.identifier = team_info["id"]
self.active = True
self.team_hash = team_hash
@@ -1609,10 +1611,11 @@ class SlackChannelCommon(object):
if update_remote:
args = {"channel": self.identifier, "ts": ts}
args.update(post_data)
- s = SlackRequest(self.team, SLACK_API_TRANSLATOR[self.type]["mark"],
- args, channel=self)
- self.eventrouter.receive(s)
- self.new_messages = False
+ mark_method = self.team.slack_api_translator[self.type].get("mark")
+ if mark_method:
+ s = SlackRequest(self.team, mark_method, args, channel=self)
+ self.eventrouter.receive(s)
+ self.new_messages = False
class SlackChannel(SlackChannelCommon):
@@ -2893,7 +2896,10 @@ def handle_reactionsremove(json, eventrouter, team, channel, metadata):
def handle_subscriptionsthreadmark(json, eventrouter, team, channel, metadata):
if not json["ok"]:
- print_error("Couldn't set thread read status: {}".format(json['error']))
+ if json['error'] == 'not_allowed_token_type':
+ team.slack_api_translator['thread']['mark'] = None
+ else:
+ print_error("Couldn't set thread read status: {}".format(json['error']))
def handle_subscriptionsthreadadd(json, eventrouter, team, channel, metadata):