aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2018-08-21 22:28:16 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2018-08-21 22:36:53 +0200
commit9064677abfb3fe7dc63b3d13ecf0e4c477632437 (patch)
treeecf5470513f930ee4980b0656f779c5bf0d75bb0 /wee_slack.py
parent601ce1e69e6f1ace2a8d8601e4e4e002af500096 (diff)
downloadwee-slack-9064677abfb3fe7dc63b3d13ecf0e4c477632437.tar.gz
Cleanup process_reply
There is no point in creating a SlackMessage when we're just going to use message_json. I think this is just left over from when more of the message was actually used. It's not necessary to reset ws_counter. Python supports arbitrarily large ints, and Slacks docs doesn't specify a limit (it does says that the int should be unique for that connection, so this is more in line with the docs). I tested the API with 2^65 and that worked fine. It returns a string instead of an int if it's larger than 2^31 - 1 though, so we convert it to an int to be sure.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py33
1 files changed, 8 insertions, 25 deletions
diff --git a/wee_slack.py b/wee_slack.py
index efa5307..c4df9ba 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1194,8 +1194,6 @@ class SlackTeam(object):
self.ws_url = url
def next_ws_transaction_id(self):
- if self.ws_counter > 999:
- self.ws_counter = 0
self.ws_counter += 1
return self.ws_counter
@@ -2589,31 +2587,16 @@ def subprocess_channel_topic(message_json, eventrouter, channel, team):
def process_reply(message_json, eventrouter, **kwargs):
- dbg('processing reply')
team = kwargs["team"]
- identifier = message_json["reply_to"]
- try:
- original_message_json = team.ws_replies[identifier]
- del team.ws_replies[identifier]
- if "ts" in message_json:
- original_message_json["ts"] = message_json["ts"]
- else:
- dbg("no reply ts {}".format(message_json))
-
- c = original_message_json.get('channel', None)
- channel = team.channels[c]
- m = SlackMessage(original_message_json, team, channel)
-
- # if "type" in message_json:
- # if message_json["type"] == "message" and "channel" in message_json.keys():
- # message_json["ts"] = message_json["ts"]
- # channels.find(message_json["channel"]).store_message(m, from_me=True)
-
- # channels.find(message_json["channel"]).buffer_prnt(server.nick, m.render(), m.ts)
-
- process_message(m.message_json, eventrouter, channel=channel, team=team)
+ reply_to = int(message_json["reply_to"])
+ original_message_json = team.ws_replies.pop(reply_to, None)
+ if original_message_json:
+ original_message_json.update(message_json)
+ channel = team.channels[original_message_json.get('channel')]
+ process_message(original_message_json, eventrouter,
+ channel=channel, team=team)
dbg("REPLY {}".format(message_json))
- except KeyError:
+ else:
dbg("Unexpected reply {}".format(message_json))