diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index b3e3666..4f892b0 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -35,6 +35,15 @@ def reactable_string(text): return reactable_array +def react_to_message(reaction, payload, channel_id, thread_ts): + payload['web_client'].reactions_add( + channel=channel_id, + name=reaction, + timestamp=thread_ts + ) + + return None + @slack.RTMClient.run_on(event='message') def handle_messages(**payload): @@ -47,26 +56,17 @@ def handle_messages(**payload): channel_id = data['channel'] thread_ts = data['ts'] - if reactable_string(data['text']): reactions_needed = reactable_string(data['text']) - def react_to_message(reaction): - payload['web_client'].reactions_add( - channel=channel_id, - name=reaction, - timestamp=thread_ts - ) - - if 'ai' in reactions_needed: - react_to_message("robot_face") + react_to_message("robot_face", payload, channel_id, thread_ts) if 'furry' in reactions_needed: - react_to_message("eggplant") - react_to_message("sweat_drops") + react_to_message("eggplant", payload, channel_id, thread_ts) + react_to_message("sweat_drops", payload, channel_id, thread_ts) if 'flavortown' in reactions_needed: - react_to_message("dark_sunglasses") - react_to_message("guyfieri") + react_to_message("dark_sunglasses", payload, channel_id, thread_ts) + react_to_message("guyfieri", payload, channel_id, thread_ts) is_command = parse_direct_mention(data['text']) @@ -91,6 +91,7 @@ def handle_messages(**payload): timestamp=thread_ts ) + if __name__ == '__main__': SLACK_TOKEN = os.environ["SLACK_API_TOKEN"] CLIENT = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])