|
|
@ -1,6 +1,8 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
import json
|
|
|
|
import slack
|
|
|
|
import slack
|
|
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLE_COMMAND = "do"
|
|
|
|
EXAMPLE_COMMAND = "do"
|
|
|
|
MENTION_REGEX = "^<@(|[WU].+)>(.*)"
|
|
|
|
MENTION_REGEX = "^<@(|[WU].+)>(.*)"
|
|
|
@ -10,13 +12,27 @@ BOT_CHANNEL = "bots-like-gaston"
|
|
|
|
def parse_direct_mention(message_text):
|
|
|
|
def parse_direct_mention(message_text):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Finds a direct mention (a mention that is at the beginning) in 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)
|
|
|
|
matches = re.search(MENTION_REGEX, message_text)
|
|
|
|
# the first group contains the username, the second group contains the remaining message
|
|
|
|
# the first group contains the username, the second group contains the remaining message
|
|
|
|
return (matches.group(1), matches.group(2).strip()) if matches else (None, None)
|
|
|
|
return (matches.group(1), matches.group(2).strip()) if matches else (None, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
def reactable_string(text):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Return regex objects matching interesting strings
|
|
|
|
Return regex objects matching interesting strings
|
|
|
@ -35,6 +51,7 @@ def reactable_string(text):
|
|
|
|
return reactable_array
|
|
|
|
return reactable_array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
def react_to_message(reaction, payload, channel_id, thread_ts):
|
|
|
|
def react_to_message(reaction, payload, channel_id, thread_ts):
|
|
|
|
payload['web_client'].reactions_add(
|
|
|
|
payload['web_client'].reactions_add(
|
|
|
|
channel=channel_id,
|
|
|
|
channel=channel_id,
|
|
|
@ -45,6 +62,8 @@ def react_to_message(reaction, payload, channel_id, thread_ts):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
>>>>>>> eef1cb68f5cc4f6b799fa5919ad1420590e74b96
|
|
|
|
@slack.RTMClient.run_on(event='message')
|
|
|
|
@slack.RTMClient.run_on(event='message')
|
|
|
|
def handle_messages(**payload):
|
|
|
|
def handle_messages(**payload):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -59,6 +78,16 @@ def handle_messages(**payload):
|
|
|
|
if reactable_string(data['text']):
|
|
|
|
if reactable_string(data['text']):
|
|
|
|
reactions_needed = reactable_string(data['text'])
|
|
|
|
reactions_needed = reactable_string(data['text'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
def react_to_message(reaction):
|
|
|
|
|
|
|
|
payload['web_client'].reactions_add(
|
|
|
|
|
|
|
|
channel=channel_id,
|
|
|
|
|
|
|
|
name=reaction,
|
|
|
|
|
|
|
|
timestamp=thread_ts
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>>>>>> eef1cb68f5cc4f6b799fa5919ad1420590e74b96
|
|
|
|
if 'ai' in reactions_needed:
|
|
|
|
if 'ai' in reactions_needed:
|
|
|
|
react_to_message("robot_face", payload, channel_id, thread_ts)
|
|
|
|
react_to_message("robot_face", payload, channel_id, thread_ts)
|
|
|
|
if 'furry' in reactions_needed:
|
|
|
|
if 'furry' in reactions_needed:
|
|
|
@ -73,13 +102,21 @@ def handle_messages(**payload):
|
|
|
|
if is_command != (None, None):
|
|
|
|
if is_command != (None, None):
|
|
|
|
if is_command[1].startswith("say"):
|
|
|
|
if is_command[1].startswith("say"):
|
|
|
|
response = f"{is_command[1]}"
|
|
|
|
response = f"{is_command[1]}"
|
|
|
|
if is_command[1].startswith("furry"):
|
|
|
|
elif is_command[1].startswith("furry"):
|
|
|
|
response = f"{is_command[1]}"
|
|
|
|
response = f"{is_command[1]}"
|
|
|
|
if is_command[1].startswith("download"):
|
|
|
|
elif is_command[1].startswith("download"):
|
|
|
|
response = "you wouldn't download a car"
|
|
|
|
response = "you wouldn't download a car"
|
|
|
|
if "arke" in is_command[1]:
|
|
|
|
elif "arke" in is_command[1]:
|
|
|
|
pass
|
|
|
|
response = []
|
|
|
|
if "pence" in is_command[1]:
|
|
|
|
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])
|
|
|
|
|
|
|
|
response = zalgo_ify(name_removal)
|
|
|
|
|
|
|
|
elif "pence" in is_command[1]:
|
|
|
|
response = "mother wouldn't want me to say that"
|
|
|
|
response = "mother wouldn't want me to say that"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
response = "that's not my job, bithc"
|
|
|
|
response = "that's not my job, bithc"
|
|
|
@ -93,7 +130,7 @@ def handle_messages(**payload):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
SLACK_TOKEN = os.environ["SLACK_API_TOKEN"]
|
|
|
|
SLACK_TOKEN = os.environ["SLACK_BOT_TOKEN"]
|
|
|
|
CLIENT = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
|
|
|
|
CLIENT = slack.WebClient(token=os.environ['SLACK_BOT_TOKEN'])
|
|
|
|
RTM_CLIENT = slack.RTMClient(token=SLACK_TOKEN)
|
|
|
|
RTM_CLIENT = slack.RTMClient(token=SLACK_TOKEN)
|
|
|
|
RTM_CLIENT.start()
|
|
|
|
RTM_CLIENT.start()
|
|
|
|