Fix whitespace issues.

master
jowj 6 years ago
parent 5d63c4bc6e
commit db3adea966

@ -15,10 +15,11 @@ starterbot_id = None
bot_channel = "inmyimo" bot_channel = "inmyimo"
# constants # constants
RTM_READ_DELAY = 1 # 1 second delay between reading from RTM RTM_READ_DELAY = 1 # 1 second delay between reading from RTM
EXAMPLE_COMMAND = "do" EXAMPLE_COMMAND = "do"
MENTION_REGEX = "^<@(|[WU].+)>(.*)" MENTION_REGEX = "^<@(|[WU].+)>(.*)"
def parse_bot_commands(slack_events): def parse_bot_commands(slack_events):
""" """
Parses a list of events coming from the Slack RTM API to find bot commands. Parses a list of events coming from the Slack RTM API to find bot commands.
@ -31,6 +32,7 @@ def parse_bot_commands(slack_events):
return message, event["channel"] return message, event["channel"]
return None, None return None, None
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
@ -40,6 +42,7 @@ def parse_direct_mention(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 select_noun(): def select_noun():
with open('/mjj1/corpora.json', 'r') as infh: with open('/mjj1/corpora.json', 'r') as infh:
for data in json_parse(infh): for data in json_parse(infh):
@ -50,6 +53,7 @@ def select_noun():
else: else:
return("car") return("car")
def json_parse(fileobj, decoder=JSONDecoder(), buffersize=2048): def json_parse(fileobj, decoder=JSONDecoder(), buffersize=2048):
buffer = '' buffer = ''
for chunk in iter(partial(fileobj.read, buffersize), ''): for chunk in iter(partial(fileobj.read, buffersize), ''):
@ -63,6 +67,7 @@ def json_parse(fileobj, decoder=JSONDecoder(), buffersize=2048):
# Not enough data to decode, read more # Not enough data to decode, read more
break break
def handle_command(command, channel): def handle_command(command, channel):
""" """
Executes bot command if the command is known Executes bot command if the command is known
@ -87,6 +92,7 @@ def handle_command(command, channel):
text=response or default_response text=response or default_response
) )
def reactable_message(event): def reactable_message(event):
"""Test whether a (Slack) event is a reaction-able message """Test whether a (Slack) event is a reaction-able message
@ -94,6 +100,7 @@ def reactable_message(event):
""" """
return 'channel' in event and 'text' in event and event.get('type') == 'message' return 'channel' in event and 'text' in event and event.get('type') == 'message'
def reactable_string(text): def reactable_string(text):
"""Return regex objects matching interesting strings """Return regex objects matching interesting strings
""" """
@ -108,6 +115,7 @@ def reactable_string(text):
reactable_array.append('flavortown') reactable_array.append('flavortown')
return reactable_array return reactable_array
def react_to_message(reaction): def react_to_message(reaction):
slack_client.api_call( slack_client.api_call(
'reactions.add', 'reactions.add',
@ -116,12 +124,14 @@ def react_to_message(reaction):
timestamp = event.get('ts') timestamp = event.get('ts')
) )
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:
return channel["id"] return channel["id"]
raise Exception("couldn't find channel requested.") raise Exception("couldn't find channel requested.")
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')

Loading…
Cancel
Save