Merge branch 'master' of git.awful.club:hosted/mojojojo-bot

master
jowj 4 years ago
commit 5e00dc9aac

@ -18,4 +18,4 @@ COPY ./ ./mojo/
RUN pip3 install requests slackclient
CMD python3 /mojo/mojo-web.py
CMD python3 /mojo/mojo-rtm.py

@ -1,6 +1,8 @@
import os
import re
import json
import slack
import random
EXAMPLE_COMMAND = "do"
MENTION_REGEX = "^<@(|[WU].+)>(.*)"
@ -10,13 +12,27 @@ 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
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):
"""
Return regex objects matching interesting strings
@ -35,6 +51,7 @@ def reactable_string(text):
return reactable_array
<<<<<<< HEAD
def react_to_message(reaction, payload, channel_id, thread_ts):
payload['web_client'].reactions_add(
channel=channel_id,
@ -45,6 +62,8 @@ def react_to_message(reaction, payload, channel_id, thread_ts):
return None
=======
>>>>>>> eef1cb68f5cc4f6b799fa5919ad1420590e74b96
@slack.RTMClient.run_on(event='message')
def handle_messages(**payload):
"""
@ -59,6 +78,16 @@ def handle_messages(**payload):
if 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:
react_to_message("robot_face", payload, channel_id, thread_ts)
if 'furry' in reactions_needed:
@ -73,13 +102,21 @@ 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]:
pass
if "pence" in is_command[1]:
elif "arke" in is_command[1]:
response = []
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"
else:
response = "that's not my job, bithc"
@ -93,7 +130,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()

@ -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()

Loading…
Cancel
Save