aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-02-09 14:44:38 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2020-02-23 18:47:05 +0100
commit1177240dd248daf3592d808cbb14ab2c906089c9 (patch)
tree8ed7444b6c8e9c936f133890e147d1de04f15234 /wee_slack.py
parent0763ae4d3279757bd600c7b37834ee79a6253452 (diff)
downloadwee-slack-1177240dd248daf3592d808cbb14ab2c906089c9.tar.gz
Cleanup/simplify callback functions
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py45
1 files changed, 10 insertions, 35 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 751eab6..01b3fad 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -479,7 +479,8 @@ class EventRouter(object):
team.connect()
dbg("reconnecting {}".format(team))
- def receive_ws_callback(self, team_hash):
+ @utf8_decode
+ def receive_ws_callback(self, team_hash, fd):
"""
This is called by the global method of the same name.
It is triggered when we have incoming data on a websocket,
@@ -513,7 +514,9 @@ class EventRouter(object):
if self.recording:
self.record_event(message_json, 'type', 'websocket')
self.receive(message_json)
+ return w.WEECHAT_RC_OK
+ @utf8_decode
def receive_httprequest_callback(self, data, command, return_code, out, err):
"""
complete
@@ -524,11 +527,7 @@ class EventRouter(object):
where the request originated and route properly.
"""
request_metadata = self.retrieve_context(data)
- try:
- dbg("RECEIVED CALLBACK with request of {} id of {} and code {} of length {}".format(request_metadata.request, request_metadata.response_id, return_code, len(out)))
- except:
- dbg(request_metadata)
- return
+ dbg("RECEIVED CALLBACK with request of {} id of {} and code {} of length {}".format(request_metadata.request, request_metadata.response_id, return_code, len(out)))
if return_code == 0:
if len(out) > 0:
if request_metadata.response_id not in self.reply_buffer:
@@ -571,6 +570,7 @@ class EventRouter(object):
dbg('rtm.start failed with return_code {}. stack:\n{}'
.format(return_code, ''.join(traceback.format_stack())), level=5)
self.receive(request_metadata)
+ return w.WEECHAT_RC_OK
def receive(self, dataobj):
"""
@@ -672,12 +672,7 @@ class EventRouter(object):
dbg("Callback not implemented for event: {}".format(function_name))
-def handle_next(*args):
- """
- complete
- This is just a place to call the event router globally.
- This is a dirty hack. There must be a better way.
- """
+def handle_next(data, remaining_calls):
try:
EVENTROUTER.handle_next()
except:
@@ -766,29 +761,6 @@ def local_process_async_slack_api_request(request, event_router):
@utf8_decode
-def receive_httprequest_callback(data, command, return_code, out, err):
- """
- complete
- This is a dirty hack. There must be a better way.
- """
- # def url_processor_cb(data, command, return_code, out, err):
- EVENTROUTER.receive_httprequest_callback(data, command, return_code, out, err)
- return w.WEECHAT_RC_OK
-
-
-@utf8_decode
-def receive_ws_callback(*args):
- """
- complete
- The first arg is all we want here. It contains the team
- hash which is set when we _hook the descriptor.
- This is a dirty hack. There must be a better way.
- """
- EVENTROUTER.receive_ws_callback(args[0])
- return w.WEECHAT_RC_OK
-
-
-@utf8_decode
def ws_ping_cb(data, remaining_calls):
for team in EVENTROUTER.teams.values():
if team.ws and team.connected:
@@ -5101,6 +5073,9 @@ if __name__ == "__main__":
EVENTROUTER = EventRouter()
# setup_trace()
+ receive_httprequest_callback = EVENTROUTER.receive_httprequest_callback
+ receive_ws_callback = EVENTROUTER.receive_ws_callback
+
# WEECHAT_HOME = w.info_get("weechat_dir", "")
# Global var section