From 50e6b11ce0376d0752b5d18367f975064ceb0a81 Mon Sep 17 00:00:00 2001 From: Jacob Henry Date: Wed, 12 Sep 2018 23:30:50 -0400 Subject: [PATCH] Added a way to identify channels. --- channel_util.py | 17 +++++++++++++++++ main.py | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 channel_util.py diff --git a/channel_util.py b/channel_util.py new file mode 100644 index 0000000..0fd38f6 --- /dev/null +++ b/channel_util.py @@ -0,0 +1,17 @@ + +import shelve + +DB_NAME = "channel_priveleges" + +# Define our patterns +channel_check_pattern = r"channel id" +# channel_check_pattern = r"channel id <#(.*)>" +# identify_other_pattern = r"<@(.*)>\s+has scroll\s+(.*)" + + +def channel_check_callback(slack, msg, match): + # Sets the users scroll + # with shelve.open(DB_NAME) as db: + + # Respond + slack_util.reply(slack, msg, msg["channel"]) \ No newline at end of file diff --git a/main.py b/main.py index ea3f13c..8a49e37 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from slack_util import * import scroll_util import identifier import re +import channel_util import job_nagger # Read api token from file @@ -35,6 +36,9 @@ def main(): wrapper.add_hook(identifier.identify_other_pattern, identifier.identify_other_callback) wrapper.add_hook(identifier.name_pattern, identifier.name_callback) + # Added channel utility + wrapper.add_hook(channel_util.channel_check_pattern, channel_util.channel_check_callback) + # Add test nagging functionality wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback) @@ -53,7 +57,6 @@ class ClientWrapper(object): def __init__(self): # Init slack self._slack = SlackClient(SLACK_API) - self._slack.rtm_send_message(channel="@jacob henry", message="I'm back baby!") # Hooks go regex -> callback on (slack, msg, match) self._hooks = OrderedDict() @@ -67,7 +70,7 @@ class ClientWrapper(object): print(msg) # We only care about standard messages, not subtypes, as those usually just channel activity - if msg.get("subtype"): + if msg.get("subtype") not in [None, "message_replied"]: continue # Handle Message