From 5fdccada37f42c68f050a685d86d662f75291b87 Mon Sep 17 00:00:00 2001 From: jowj Date: Mon, 20 Jan 2020 15:45:58 -0600 Subject: [PATCH 01/17] Add dedicated post to slack function. --- mojo-web/mojo-web.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/mojo-web/mojo-web.py b/mojo-web/mojo-web.py index e756d94..1c8fee2 100644 --- a/mojo-web/mojo-web.py +++ b/mojo-web/mojo-web.py @@ -2,18 +2,27 @@ import os from pathlib import Path import slack -def react_to_monitoring(): +slack_token = os.environ.get("SLACK_BOT_TOKEN") +client = slack.WebClient(token=os.environ['SLACK_BOT_TOKEN']) + + +def post_to_slack(message_list): + if message_list: + client.chat_postMessage( + channel = "#bots-like-gaston", + text = message_list + ) + + +def react_to_monitoring(): results_file = Path("/shared/alerts.log") - does_file_exist = results_file.is_file() if results_file.is_file(): - open_file = open("/shared/alerts.log","r") + open_file = open("/shared/alerts.log", "r") for line in open_file: - webclient.chat_postMessage( - channel = channel_id, - text = line - ) + post_to_slack(line) os.remove("/shared/alerts.log") + if __name__ == '__main__': while True: react_to_monitoring() From d315140e2ef06b2cf4b57d0f8909b054a804d5f8 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 15:53:50 -0600 Subject: [PATCH 02/17] Remove white space, add response for 'arke' command. --- mojo-rtm/mojo-rtm.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index b3e3666..384d5dd 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -1,5 +1,6 @@ import os import re +import json import slack EXAMPLE_COMMAND = "do" @@ -10,7 +11,8 @@ BOT_CHANNEL = "bots-like-gaston" def parse_direct_mention(message_text): """ Finds a direct mention (a mention that is at the beginning) in message text - and returns the user ID which was mentioned. If there is no direct mention, returns None + and returns the user ID which was mentioned. If there is no direct mention, + returns None """ matches = re.search(MENTION_REGEX, message_text) # the first group contains the username, the second group contains the remaining message @@ -35,7 +37,6 @@ def reactable_string(text): return reactable_array - @slack.RTMClient.run_on(event='message') def handle_messages(**payload): """ @@ -47,7 +48,6 @@ def handle_messages(**payload): channel_id = data['channel'] thread_ts = data['ts'] - if reactable_string(data['text']): reactions_needed = reactable_string(data['text']) @@ -58,7 +58,6 @@ def handle_messages(**payload): timestamp=thread_ts ) - if 'ai' in reactions_needed: react_to_message("robot_face") if 'furry' in reactions_needed: @@ -78,7 +77,10 @@ def handle_messages(**payload): if is_command[1].startswith("download"): response = "you wouldn't download a car" if "arke" in is_command[1]: - pass + response = [] + with open("/shared/state.log", "r") as json_File: + for line in json_File: + response.append(json.loads(line)) if "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: @@ -91,6 +93,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']) From 7eb33cc2207aeeee26f852154364cb451c5716e0 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 16:08:15 -0600 Subject: [PATCH 03/17] Update to use the proper python file! --- mojo-rtm/dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/dockerfile b/mojo-rtm/dockerfile index 900b42e..97e2246 100644 --- a/mojo-rtm/dockerfile +++ b/mojo-rtm/dockerfile @@ -18,4 +18,4 @@ COPY ./ ./mojo/ RUN pip3 install requests slackclient -CMD python3 /mojo/mojo-web.py +CMD python3 /mojo/mojo-rtm.py From 7911582f852cc011ffcee2ad280464d4c7b91938 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 16:12:43 -0600 Subject: [PATCH 04/17] Fix misnamed environment variable. --- mojo-rtm/mojo-rtm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 384d5dd..3646516 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -95,7 +95,7 @@ def handle_messages(**payload): if __name__ == '__main__': - SLACK_TOKEN = os.environ["SLACK_API_TOKEN"] - CLIENT = slack.WebClient(token=os.environ['SLACK_API_TOKEN']) + SLACK_TOKEN = os.environ["SLACK_BOT_TOKEN"] + CLIENT = slack.WebClient(token=os.environ['SLACK_BOT_TOKEN']) RTM_CLIENT = slack.RTMClient(token=SLACK_TOKEN) RTM_CLIENT.start() From 75e51c1277989aab6c24a417e4815900113e871b Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 16:18:03 -0600 Subject: [PATCH 05/17] The laziest debugging commit i've ever done. --- mojo-rtm/mojo-rtm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 3646516..e04d4f7 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -84,7 +84,7 @@ def handle_messages(**payload): if "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: - response = "that's not my job, bithc" + response = f"{is_command}" webclient = payload['web_client'] webclient.chat_postMessage( From afc1554914ea49f39296e58c5d85e943eff7afd3 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 16:23:27 -0600 Subject: [PATCH 06/17] Change back to previous catch all response. --- mojo-rtm/mojo-rtm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index e04d4f7..3646516 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -84,7 +84,7 @@ def handle_messages(**payload): if "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: - response = f"{is_command}" + response = "that's not my job, bithc" webclient = payload['web_client'] webclient.chat_postMessage( From 6550bb152ee7d74210ede9084fafe754d8cfb4bd Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 21 Jan 2020 16:24:42 -0600 Subject: [PATCH 07/17] Change sequntial ifs to elifs. --- mojo-rtm/mojo-rtm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 3646516..2b3da53 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -72,16 +72,16 @@ def handle_messages(**payload): if is_command != (None, None): if is_command[1].startswith("say"): response = f"{is_command[1]}" - if is_command[1].startswith("furry"): + elif is_command[1].startswith("furry"): response = f"{is_command[1]}" - if is_command[1].startswith("download"): + elif is_command[1].startswith("download"): response = "you wouldn't download a car" - if "arke" in is_command[1]: + elif "arke" in is_command[1]: response = [] with open("/shared/state.log", "r") as json_File: for line in json_File: response.append(json.loads(line)) - if "pence" in is_command[1]: + elif "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: response = "that's not my job, bithc" From 9739a1691c459e49c0c583d9f739a518f7ee5787 Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 03:31:55 +0000 Subject: [PATCH 08/17] Add initial zalgo function. --- mojo-rtm/mojo-rtm.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 2b3da53..f04469b 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -19,6 +19,19 @@ def parse_direct_mention(message_text): return (matches.group(1), matches.group(2).strip()) if matches else (None, None) +async def zalgo_ify(text): + ''' Takes some normal text and zalgo-ifies it ''' + # "Combining Diacritical Marks" Unicode block. + combining_chars = [chr(n) for n in range(768, 878)] + + zalgo_text = '' + + for char in text: + combining_char = random.choice(combining_chars) + zalgo_text += f'{char}{combining_char}' + + return zalgo_text + def reactable_string(text): """ Return regex objects matching interesting strings @@ -81,6 +94,8 @@ def handle_messages(**payload): with open("/shared/state.log", "r") as json_File: for line in json_File: response.append(json.loads(line)) + elif "zalgo" in is_command[1]: + zalgo_ify(is_command[1]) elif "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: From 6ec3083b3aaca27fb4fde9efb79cddae61c9bf8b Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 03:42:53 +0000 Subject: [PATCH 09/17] Stop using async --- mojo-rtm/mojo-rtm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index f04469b..7f0dd7a 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -19,7 +19,7 @@ def parse_direct_mention(message_text): return (matches.group(1), matches.group(2).strip()) if matches else (None, None) -async def zalgo_ify(text): +def zalgo_ify(text): ''' Takes some normal text and zalgo-ifies it ''' # "Combining Diacritical Marks" Unicode block. combining_chars = [chr(n) for n in range(768, 878)] From 4438d66ed1b32079331c38b0dd95c9b2ed6847bc Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 03:54:31 +0000 Subject: [PATCH 10/17] Add var definition - goddamnit i'm a fucking moron. --- mojo-rtm/mojo-rtm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 7f0dd7a..368963f 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -95,7 +95,8 @@ def handle_messages(**payload): for line in json_File: response.append(json.loads(line)) elif "zalgo" in is_command[1]: - zalgo_ify(is_command[1]) + response = zalgo_ify(is_command[1]) + elif "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: From fea8bcc7bdddacba29f6dc69e1f7caec6b2ced82 Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 03:59:27 +0000 Subject: [PATCH 11/17] Add random import. --- mojo-rtm/mojo-rtm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 368963f..c0ee6dd 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -2,6 +2,7 @@ import os import re import json import slack +import random EXAMPLE_COMMAND = "do" MENTION_REGEX = "^<@(|[WU].+)>(.*)" From a0ee9f1702a11b8272b0149d9e4126e949c474a8 Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 04:46:27 +0000 Subject: [PATCH 12/17] Update zalgo logic to remove 'zalgo' from response - now it should be prettier! --- mojo-rtm/mojo-rtm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index c0ee6dd..d911612 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -96,8 +96,9 @@ def handle_messages(**payload): for line in json_File: response.append(json.loads(line)) elif "zalgo" in is_command[1]: - response = zalgo_ify(is_command[1]) - + # remove zalgo + name_removal = re.sub("^zalgo .*?", "", "is_command[1]") + response = zalgo_ify(name_removal) elif "pence" in is_command[1]: response = "mother wouldn't want me to say that" else: From 3920131cb6a18af73141876b1a4332f3bf65655b Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 25 Jan 2020 04:52:40 +0000 Subject: [PATCH 13/17] Remove the quotes that have betrayed me --- mojo-rtm/mojo-rtm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index d911612..a373dd8 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -97,7 +97,7 @@ def handle_messages(**payload): response.append(json.loads(line)) elif "zalgo" in is_command[1]: # remove zalgo - name_removal = re.sub("^zalgo .*?", "", "is_command[1]") + name_removal = re.sub("^zalgo .*?", "", is_command[1]) response = zalgo_ify(name_removal) elif "pence" in is_command[1]: response = "mother wouldn't want me to say that" From 4f72485e9fff215eab64b5c22e160866181bae88 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 28 Jan 2020 16:10:27 -0600 Subject: [PATCH 14/17] Update state.log to state.json to match changes in arke. --- mojo-rtm/mojo-rtm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index 2b3da53..4d0bdc8 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -78,7 +78,7 @@ def handle_messages(**payload): response = "you wouldn't download a car" elif "arke" in is_command[1]: response = [] - with open("/shared/state.log", "r") as json_File: + with open("/shared/state.json", "r") as json_File: for line in json_File: response.append(json.loads(line)) elif "pence" in is_command[1]: From 17fffde8c5443fff87c84737e80b73d892799280 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 28 Jan 2020 16:15:01 -0600 Subject: [PATCH 15/17] Remove the file once I've read it out. --- mojo-rtm/mojo-rtm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index f1c5e3c..e87a9b4 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -95,6 +95,7 @@ def handle_messages(**payload): with open("/shared/state.json", "r") as json_File: for line in json_File: response.append(json.loads(line)) + os.remove("/shared/state.json") elif "zalgo" in is_command[1]: # remove zalgo name_removal = re.sub("^zalgo .*?", "", is_command[1]) From 63aa44eff0dbc4e5df9d08ca4ccb23d1282a5db8 Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 28 Jan 2020 16:27:19 -0600 Subject: [PATCH 16/17] Fix file pointer to look at alerts.log (oops) --- mojo-rtm/mojo-rtm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index e87a9b4..ead259c 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -92,10 +92,10 @@ def handle_messages(**payload): response = "you wouldn't download a car" elif "arke" in is_command[1]: response = [] - with open("/shared/state.json", "r") as json_File: + with open("/shared/alerts.log", "r") as json_File: for line in json_File: response.append(json.loads(line)) - os.remove("/shared/state.json") + os.remove("/shared/alerts.log") elif "zalgo" in is_command[1]: # remove zalgo name_removal = re.sub("^zalgo .*?", "", is_command[1]) From eef1cb68f5cc4f6b799fa5919ad1420590e74b96 Mon Sep 17 00:00:00 2001 From: jowj Date: Thu, 30 Jan 2020 15:15:03 -0600 Subject: [PATCH 17/17] Move to human readable format from posting. --- mojo-rtm/mojo-rtm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mojo-rtm/mojo-rtm.py b/mojo-rtm/mojo-rtm.py index ead259c..0392a3f 100644 --- a/mojo-rtm/mojo-rtm.py +++ b/mojo-rtm/mojo-rtm.py @@ -92,10 +92,10 @@ def handle_messages(**payload): response = "you wouldn't download a car" elif "arke" in is_command[1]: response = [] - with open("/shared/alerts.log", "r") as json_File: - for line in json_File: - response.append(json.loads(line)) - os.remove("/shared/alerts.log") + with open("/shared/state.json", "r") as json_File: + state = json.load(json_File) + for key, value in state.items(): + response.append(f"{key}: {value}") elif "zalgo" in is_command[1]: # remove zalgo name_removal = re.sub("^zalgo .*?", "", is_command[1])