Dummy messaging, channel utility useful vars, nagging
This commit is contained in:
parent
fcabaf420a
commit
bc25ffcb1e
|
|
@ -1,13 +1,15 @@
|
||||||
|
|
||||||
import shelve
|
|
||||||
import slack_util
|
import slack_util
|
||||||
|
|
||||||
DB_NAME = "channel_priveleges"
|
DB_NAME = "channel_priveleges"
|
||||||
|
|
||||||
|
# Useful channels
|
||||||
|
GENERAL = "C0CFHPNEM"
|
||||||
|
COMMAND_CENTER_ID = "GCR631LQ1"
|
||||||
|
SLAVES_TO_THE_MACHINE_ID = "C9WUQBYNP"
|
||||||
|
BOTZONE = "C3BF2MFKM"
|
||||||
|
|
||||||
# Define our patterns
|
# Define our patterns
|
||||||
channel_check_pattern = r"channel id\s*(.*)"
|
channel_check_pattern = r"channel id\s*(.*)"
|
||||||
# channel_check_pattern = r"channel id <#(.*)>"
|
|
||||||
# identify_other_pattern = r"<@(.*)>\s+has scroll\s+(.*)"
|
|
||||||
|
|
||||||
|
|
||||||
def channel_check_callback(slack, msg, match):
|
def channel_check_callback(slack, msg, match):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import time
|
||||||
|
import channel_util
|
||||||
|
|
||||||
|
msg = {
|
||||||
|
"type": "message",
|
||||||
|
"channel": channel_util.COMMAND_CENTER_ID,
|
||||||
|
"user": "U0Q1PKL92",
|
||||||
|
"text": "nagjobs tuesday",
|
||||||
|
"ts": "1355517523.000005"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class FakeClient(object):
|
||||||
|
def rtm_send_message(self, channel=None, message="", thread=None, to_channel=None):
|
||||||
|
print("Sent \"{}\" to channel {}".format(message, channel))
|
||||||
|
|
||||||
|
def rtm_connect(self, with_team_state=None, auto_reconnect=None):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def rtm_read(self):
|
||||||
|
time.sleep(4)
|
||||||
|
return [msg]
|
||||||
|
|
@ -1,27 +1,55 @@
|
||||||
import identifier
|
import identifier
|
||||||
import scroll_util
|
import scroll_util
|
||||||
import slack_util
|
import slack_util
|
||||||
|
import google_api
|
||||||
|
import channel_util
|
||||||
|
|
||||||
nag_pattern = r"nag (.*)"
|
nag_pattern = r"nagjobs (tuesday|thursday)"
|
||||||
|
|
||||||
|
|
||||||
|
SHEET_ID = "1lPj9GjB00BuIq9GelOWh5GmiGsheLlowPnHLnWBvMOM"
|
||||||
|
eight_jobs = "House Jobs!A2:C25" # Format: Job Day Bro
|
||||||
|
fiftythree_jobs = "House Jobs!E2:G6"
|
||||||
|
|
||||||
|
# For matching purposes
|
||||||
|
tuesday = "tuesday"
|
||||||
|
thursday = "thursday"
|
||||||
|
|
||||||
|
|
||||||
|
class Job(object):
|
||||||
|
def __init__(self, row):
|
||||||
|
self.job_name, self.day, self.brother_name = row
|
||||||
|
self.day = self.day.lower().strip()
|
||||||
|
|
||||||
|
def lookup_brother_slack_id(self):
|
||||||
|
brother_dict = scroll_util.find_by_name(self.brother_name)
|
||||||
|
return identifier.lookup_brother_userids(brother_dict)
|
||||||
|
|
||||||
|
|
||||||
def nag_callback(slack, msg, match):
|
def nag_callback(slack, msg, match):
|
||||||
# Get who we want to nag
|
# Only allow in
|
||||||
name = match.group(1)
|
|
||||||
|
|
||||||
# Find them using scroll shit
|
# Get the day
|
||||||
brother = scroll_util.find_by_name(name)
|
day = match.group(1).lower()
|
||||||
|
|
||||||
# Get the associated user ids
|
# Get the spreadsheet section
|
||||||
ids = identifier.lookup_brother_userids(brother)
|
jobs = google_api.get_sheet_range(SHEET_ID, eight_jobs)
|
||||||
|
jobs = jobs + google_api.get_sheet_range(SHEET_ID, fiftythree_jobs)
|
||||||
|
jobs = [Job(r) for r in jobs]
|
||||||
|
|
||||||
# Nag them each
|
# Filter to day
|
||||||
if ids:
|
jobs = [j for j in jobs if j.day == day]
|
||||||
result = "Hey"
|
|
||||||
for user_id in ids:
|
|
||||||
result += " <@{}>".format(user_id)
|
|
||||||
result += "!"
|
|
||||||
else:
|
|
||||||
result = "Nobody has identified themselves as {} ({})... Sad!".format(brother["name"], brother["scroll"])
|
|
||||||
|
|
||||||
slack_util.reply(slack, msg, result, in_thread=False)
|
# Nag each
|
||||||
|
response = "Do your jobs! They are as follows:\n"
|
||||||
|
for job in jobs:
|
||||||
|
response += "{} -- ".format(job.job_name)
|
||||||
|
ids = job.lookup_brother_slack_id()
|
||||||
|
if ids:
|
||||||
|
for id in ids:
|
||||||
|
response += "<@{}> ".format(id)
|
||||||
|
else:
|
||||||
|
response += "{} (scroll not found. Please register for @ notifications!)".format(job.brother_name)
|
||||||
|
response += "\n"
|
||||||
|
|
||||||
|
slack_util.reply(slack, msg, response, in_thread=False, to_channel=channel_util.BOTZONE)
|
||||||
|
|
|
||||||
15
main.py
15
main.py
|
|
@ -9,6 +9,7 @@ import identifier
|
||||||
import re
|
import re
|
||||||
import channel_util
|
import channel_util
|
||||||
import job_nagger
|
import job_nagger
|
||||||
|
from dummy import FakeClient
|
||||||
|
|
||||||
# Read api token from file
|
# Read api token from file
|
||||||
api_file = open("apitoken.txt", 'r')
|
api_file = open("apitoken.txt", 'r')
|
||||||
|
|
@ -39,7 +40,7 @@ def main():
|
||||||
# Added channel utility
|
# Added channel utility
|
||||||
wrapper.add_hook(channel_util.channel_check_pattern, channel_util.channel_check_callback)
|
wrapper.add_hook(channel_util.channel_check_pattern, channel_util.channel_check_callback)
|
||||||
|
|
||||||
# Add test nagging functionality
|
# Add nagging functionality
|
||||||
wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback)
|
wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback)
|
||||||
|
|
||||||
# Add kill switch
|
# Add kill switch
|
||||||
|
|
@ -53,10 +54,16 @@ def die(*args):
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG_MODE = False
|
||||||
|
|
||||||
|
|
||||||
class ClientWrapper(object):
|
class ClientWrapper(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Init slack
|
# Init slack
|
||||||
self._slack = SlackClient(SLACK_API)
|
if DEBUG_MODE:
|
||||||
|
self._slack = FakeClient()
|
||||||
|
else:
|
||||||
|
self._slack = SlackClient(SLACK_API)
|
||||||
|
|
||||||
# Hooks go regex -> callback on (slack, msg, match)
|
# Hooks go regex -> callback on (slack, msg, match)
|
||||||
self._hooks = OrderedDict()
|
self._hooks = OrderedDict()
|
||||||
|
|
@ -73,6 +80,10 @@ class ClientWrapper(object):
|
||||||
if msg.get("subtype") is not None:
|
if msg.get("subtype") is not None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Never deal with general
|
||||||
|
if msg.get("channel") == channel_util.GENERAL:
|
||||||
|
continue
|
||||||
|
|
||||||
# Handle Message
|
# Handle Message
|
||||||
text = msg['text'].strip()
|
text = msg['text'].strip()
|
||||||
success = False
|
success = False
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,19 @@ Slack helpers. Separated for compartmentalization
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def reply(slack, msg, text, in_thread=True):
|
def reply(slack, msg, text, in_thread=True, to_channel=None):
|
||||||
"""
|
"""
|
||||||
Sends message with "text" as its content to the channel that message came from
|
Sends message with "text" as its content to the channel that message came from
|
||||||
"""
|
"""
|
||||||
channel = msg['channel']
|
# If no channel specified, just do same as msg
|
||||||
thread_id = msg['ts']
|
if to_channel is None:
|
||||||
|
to_channel = msg['channel']
|
||||||
|
|
||||||
|
# Send in a thread by default
|
||||||
if in_thread:
|
if in_thread:
|
||||||
slack.rtm_send_message(channel=channel, message=text, thread=thread_id)
|
slack.rtm_send_message(channel=to_channel, message=text, thread=msg['ts'])
|
||||||
else:
|
else:
|
||||||
slack.rtm_send_message(channel=channel, message=text)
|
slack.rtm_send_message(channel=to_channel, message=text)
|
||||||
|
|
||||||
|
|
||||||
def message_stream(slack):
|
def message_stream(slack):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue