Add function for handling monitoring errors.

master
jowj 6 years ago
parent db3adea966
commit b157a74fd5

@ -2,6 +2,9 @@ import os
import time import time
import re import re
import logging import logging
import json
from pathlib import Path
from slackclient import SlackClient from slackclient import SlackClient
from json import JSONDecoder from json import JSONDecoder
from random import randint from random import randint
@ -125,6 +128,19 @@ def react_to_message(reaction):
) )
def react_to_monitoring(filename):
results_file = os.Path("results.json")
if results_file.is_file():
results_file = open(filename,"r")
for line in results_file:
slack_client.api_call(
"chat.postMessage",
get_channel_ID("bots-like-gaston"),
text=line
)
os.remove(filename)
def get_channel_ID(channelName): def get_channel_ID(channelName):
for channel in slack_client.api_call('channels.list')["channels"]: for channel in slack_client.api_call('channels.list')["channels"]:
if channel["name"] == channelName: if channel["name"] == channelName:
@ -135,6 +151,7 @@ def get_channel_ID(channelName):
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(filename='mojojojo.log', level=logging.INFO) logging.basicConfig(filename='mojojojo.log', level=logging.INFO)
logging.info('Started') logging.info('Started')
results_file = Path("results.json")
if slack_client.rtm_connect(with_team_state=False): if slack_client.rtm_connect(with_team_state=False):
print("mojo jojo online, connected, and running!") print("mojo jojo online, connected, and running!")
# Read bot's user ID by calling Web API method `auth.test` # Read bot's user ID by calling Web API method `auth.test`
@ -144,6 +161,8 @@ if __name__ == "__main__":
command, channel = parse_bot_commands(event) command, channel = parse_bot_commands(event)
if command: if command:
handle_command(command, channel) handle_command(command, channel)
if results_file.is_file():
react_to_monitoring(results_file)
if reactable_message(event): if reactable_message(event):
channel = event['channel'] channel = event['channel']
text = event['text'] text = event['text']

Loading…
Cancel
Save